Thursday, September 22, 2011

Re: how do I turn off file type matching in open file dialog?

On Sep 22, 12:38 am, Jürgen Krämer <jottka...@googlemail.com> wrote:
> Hi,
>
> billy pilgrim wrote:
>
> > When I am editing a C++ file, and use the open file dialog, it always
> > defaults to looking for file types: C/C++.  If I am looking for
> > another file type (e.g., .h), I have to change it to All Files.  This
> > is not, of course, limited to C/C++ files, but that is a good
> > example.  I know there has to be a way to turn this off/on, right?
> > Anyone know?
>
> the open file dialog is called by executing
>
>   :browse {command}
>
> where {command} is one of e, w, wall, wq, etc. If you have a look at
>
>   :help :browse
>
> you will also find a section with help for a global variable called
> browsefilter. You can also jump there directly with
>
>   :help browsefilter
>
> Now that you know about it, you can check whether it is defined when you
> edit C++ files and maybe where it has been defined. (For C++ it actually
> has been set by the default C filetype plugin ($VIMRUNTIME/ftplugin/c.vim)).
> The help also tells you that your own local filetype plugin is a good
> place to set or override the global variable with a local variable
> b:browsefilter (note the leading "b:"). So, with
>
>   :let b:browsefilter = ''
>
> in your local $HOME/vimfiles/ftplugin/cpp.vim you can disable this
> behavior for C++ files. If you want to disable it for all file types,
> you can try it by putting
>
>   autocmd FileType * let b:browsefilter = ''
>
> in your .vimrc.
>

The default c filetype plugin already sets reasonable defaults. Here's
the code which does it:

" Win32 can filter files in the browse dialog
if has("gui_win32") && !exists("b:browsefilter")
if &ft == "cpp"
let b:browsefilter = "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++
\n" .
\ "C Header Files (*.h)\t*.h\n" .
\ "C Source Files (*.c)\t*.c\n" .
\ "All Files (*.*)\t*.*\n"
elseif &ft == "ch"
let b:browsefilter = "Ch Source Files (*.ch *.chf)\t*.ch;*.chf
\n" .
\ "C Header Files (*.h)\t*.h\n" .
\ "C Source Files (*.c)\t*.c\n" .
\ "All Files (*.*)\t*.*\n"
else
let b:browsefilter = "C Source Files (*.c)\t*.c\n" .
\ "C Header Files (*.h)\t*.h\n" .
\ "Ch Source Files (*.ch *.chf)\t*.ch;*.chf\n" .
\ "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++\n" .
\ "All Files (*.*)\t*.*\n"
endif
endif

Note that you can ALREADY select "C Header Files" by default. They
just won't be shown alongside the C/C++ Source Files.

You could rearrange the lines in the above string in your $HOME
directory as Jürgen suggests to get a different default filter. You
can also include the header files in the filter alongside the c files
by replacing *.c with *.c;*.h on the first line in the filter (for C++
add *.h to the list containing cpp and c++).

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment