Currently, the wildcard completions for filenames (after pressing :e or :new, etc.) in command line mode is sorted alphabetically, as if all the filenames are strings. This is understandable, but for one who keeps editing *.tex files, the following is desired:
Upon completion of initials of filename, first show me the *.tex file.
Let the *.log files be placed in the second place.
Note that, I do not want the wildcard to ignore *.log files completely, as it used by other statistical softwares for logs.
Any thought on how to elevate the priority of `.tex files?
All the best,
-Linfeng
For that, Vim has the 'suffixes' option. From :help 'suffixes':
Files with these suffixes get a lower priority when multiple files match a wildcard.
So, just set
:set suffixes+=.log
and log files will appear after any other file extension.
There's also 'wildignore' for completely ignoring certain files. Anything beyond that would require overriding the :edit etc. commands with custom ones that implement a custom filename completion, so that would be cumbersome and quite involved.
I undestand Vim can do spell-check, and it can modify a spell-file inside ~/.vim to keep words flagged as good.
I'd like to keep a "local" spell-file in the same directory as a file I'm editing, so that if I'm in different directories editing different files, different spell-files would be used.
How would I set up Vim to do this?
Vim's own help is usefull here:
:help spellfile
Name of the word list file where words are added for the
zg and zw commands. It must end in ".{encoding}.add".
You need to include the path, otherwise the file is placed
in the current directory.
More detailed information:
http://thejakeharding.com/tutorial/2012/06/13/using-spell-check-in-vim.html
Separate Vim spellfile for custom words
So:
:set spellfile=./en.utf-8.add
hth
I want to change where vim looks for file completion, but only in insert mode. For example:
I open gvim inside of the CG-Website directory.
This is my directory structure:
Then i go in to the css folder and open style.css
using :e src/static/css/style.css
Now i am inside of style.css and i want to complete a file name that is down one directory.
I want to be able to type ../ in INSERT mode and have all the files/folders that are inside of the static folder show up, instead of the www folder which is what it does right now.
However I don't want to change the actual directory, because I still want :e to work normally.
Insert mode filename completion is always done from the "current directory" or "working directory" which may or may not be the directory of the current file. Since you don't want to change directories, filename completion can't work like you want it to work.
Actually, the last sentence of :h compl-filename should give you a hint:
Search for the first file name that starts with the
same characters as before the cursor. The matching
file name is inserted in front of the cursor.
Alphabetic characters and characters in 'isfname'
are used to decide which characters are included in
the file name. Note: the 'path' option is not used
here (yet).
One solution to this problem is to set autochdir so that Vim always changes the working directory to the directory of the current file and use a plugin like CtrlP (there are others) for navigation. When configured properly, CtrlP lets you navigate your files from your project's home as defined by the presence of a .git or similar directory. This is really handy.
However, you can get around that limitation relatively easily with set autochdir (again, you need it for filename completion to work like you -- and I -- want it to work) and a bit of creativity:
nnoremap <F9> :e ~/path/to/project/
Consider this mapping as a quick shortcut to your project.
I think you are approaching this the wrong way. You want to filter results relative to your last opened dir without changing your current dir and that doesn't quite make sense.
My recommendation is to use a tool what will allow you to quickly filter through all of your files from the root folder of your project.
Take a look at Command-T: Fast file navigation for VIM
PS: you need vim with ruby support for that.
I frequently accidentally open a binary executable, i.e. "foo", when I mean to open the associated source code "foo.cpp". The root of the problem is that tab completion, i.e. :e fo<tab> typically lands on the binary instead of the source code.
Is there a way to get vim to only tab complete names of text files? Or alternatively, change the tab completion order?
Sometimes my hasty tab completion error happens outside of vim; for those cases, what is the best way to prevent vim from opening files that are not text?
Not exactly what you need, but I have something like this in my .vimrc
" ignore these files when completing names and in Ex
set wildignore=.svn,CVS,.git,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,*.pdf,*.bak,*.beam
" set of file name suffixes that will be given a lower priority when it comes to matching wildcards
set suffixes+=.old
For tab completion outside of vim, that will depend on your shell. Most shells have some form of autocompletion support. In particular, Zsh has the ability to autocomplete e.g. remote hosts for ssh. I'm not a wizard with these things, but it would probably be relatively simple to get your shell to drop files with certain suffixes from the autocompletion list when the command you are typing starts with "vim".
A quick google search turn up this page, which has this:
# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
'*?.old' '*?.pro'
It should not be too difficult to modify this logic to get what you want (if you use Zsh).
Maybe you can find this useful:
set wildmenu
set wildmode=longest,list
(taken and using from How do I make vim do normal (bash like) tab completion for file names?)
How do you manage big projects (hundreds of files) using only VIM?
I personally start having problems in any larger than small project.
is there any way to quickly 'go to file', preferably with name completition?
same for 'go to class definition', when it is in another file
I kinda know all the VIM basics, so I don't have problem using it for writing scripts or quick editing some source code. But it gets really messy for me when I have to navigate between files.
VIM has excellent support for tags. Once you have created a tags file for your project, you can jump to a definition or declaration of a method, class, etc., including jumping across files, all inside the same editing session.
Try
:help tags
To generate a tags file for C/C++, go to your shell prompt (I'm assuming your system is *nix/Cygwin) and type
info ctags
or
ctags --help
I like simple solutions, my favorite way to navigate at the moment is:
Add to ~/.vimrc.local
set path=$PWD/**
Then type this in the editor to find the file anywhere in the current working directory (pwd)
:find user_spec.rb
You can use tab-completion on the filenames to find multiple choices as well, making this TextMate convert very happy.
I use a combination of NERDTree (directory sidebar), FuzzyFinder Textmate (go-to-file like TextMate's CMD+T), and Sessions (:h sessions) to help me deal with large projects.
I would suggest using some sessions helper plugin. I would mention what I use, but I'm not satisfied with it yet. Just Google "vim sessions".
One thing to note with getting FuzzyFinder Textmate to work is that it depends on an old version the FuzzyFinder plugin, specifically v2.16. Anything higher and you'll get errors. But it's definitely worth the trouble. While it doesn't have name completion, its search is smart so if I search for fro/time/actionsphp it will pull up the file apps/(fro)ntend/modules/(time)_tracking/actions/(actions).class.(php) (parenthesis denote what it's matching). It makes it very easy to pick out files that are only unique by their folder name.
As well as the invaluable ctags and the various associated commands. I also couldn't live without the project plugin, which allows you to have the files of interest associated with a project in a separate pane. I can't remember how much of my setup is customised, but if I want to open a source file called Debug.c, I hit:
<F12> " Opens the project pane
/De " Searches for "De", which is likely to be enough to find Debug.c or possibly Debug.h
<ENTER> " Opens the selected file and closes the project pane
I often then do:
:vsp " Vertically split the window
<F12> " Reopen project pane
# " Search back to find previous entry with the same name (to find
Debug.h if I was on Debug.c: my headers are in Headers/ and
my source is in Source/, so the headers come earlier in the list
than the source). I use * to go the other way, obviously.
<ENTER> " Open the header file in the other window and close the project window.
With this relatively short sequence, I can open any file and it's header in a vertical split. Since the project plugin window is just a text file, completion is achieved by using Vim's searching capability.
Starting in Vim 7.3, the :find command has tab-completion of filenames.
So if you set your 'path' option to contain your entire project (probably using the ** wildcard to allow recursively searching subdirectories), then you can use the :find, :sfind, :tabfind, etc. commands with completion to get to any file in your project. This also allows jumping to files directly with gf and friends if the file name is in your text, for example in an include directive.
With this method, no external tools or plugins are needed for navigating to specific files. Although, it may admittedly not be as fast or easy to use, and doesn't address the need for jumping to definitions. For definitions, I use ctags as other answers suggest.
If you are using ctags as other posters have recommended, then make sure you look at the taglist plugin.
Make sure you take the time to read the docs and learn the key bindings. Here are a few to get you started (from the TList window):
o - open file in new window
t - open file in new tab
[[ or backspace - previous file in list
]] or tab - next file in list
Exuberant ctags.
Use Ctrl-] to jump to the tag under the cursor.
Opening vim from root of your source file and extending path option to include all sub-directories therein.
For example set path+=/usr/include/c++/** for C++ headers and set path+=** for your source directory.
This ,then, opens a plethora of following possibilities.
1) Opening file by name or parts of it
:find file_name
You can use auto-completion and wildcard expansion with :find reliably. You type the name, it will locate the name. This works language agnostic.I am sure you will like it.
2) Navigating to files under cusror:
if you want to go a file path like #include "project/path/classA.h.
gf or gF - go to file under cursor.
Ctrl-6 - to come back to last cursor position after gf or gF
3) API lookup and navigating to the API location
[i or [I can be used to look up your function signature for word under cursor without leaving your workspace. [<Tab> to actually go to declaration. Use Ctrl-6 to come back to last location.
Without extending path, you can start navigating files by :Ex command and navigate and open your file. I prefer NerdTree over this though.
I use FindFile. If you open vim at the root of your project and run :FC . the plugin will cache all the filenames beneath your cwd. You can then do :FF to open a completion menu and type the name of the file you want (or rather, the first few letters).
Although I'm kinda hoping someone will point out a better solution so I can learn something, NERDTree has been good to me for getting to specific files with name completion as long as I have the tree expanded. The command when I need to get to a file is something like:
,d/foo.pyo (where foo.py is a file name)
,d to open the tree, / to enter search mode, the name (or partial name, or regex, or whatever) of the file, and then o to open.
Of course you may have to hit 'n' a few times if you didn't type enough of the filename or there are duplicates.
I admit it feels like a bit of a hack using NERDTree like this although it has gotten so far into my muscle memory by now that I don't even think about it.
Of course I use ctags too but those are only useful when you have a function near the cursor and need to get to its definition in another file or something. A lot of times I say "OK, I need to work on feature x now" and need to navigate to another file without any references nearby that ctags would really help with.
I'm using two plugins of mine:
searchInRuntime that completes filenames on command line. It is somehow similar to fuzzyfinder and lookupfile,
lh-tags which is completely experimental and undocumented. It offers two features: automatic and quick update of the tagfile on file save(ing?), and a tag selector plugged to <c-w><m-down> by default. You may want to check the renowned taglist plugin instead.
Both require my viml library lh-vim-lib.
Try SourceCodeObedinece. This one I developed to handle C++ 1Gb source files project.
I use it in pair with 0scan.
These two plugins are wrappers around the most popular Vim browsing tools: ctags and cscope.