Having just moved from textmate to vim I'm curious. To be able to navigate my project efficiently I've installed command-t and ack.vim. These both seem like relatively new projects in the history of vim. What do people traditionally do to move around a project when they work in vim, do they just use the file explorer or is there some old school trick I don't know about?
-
1The answers to this question may also be of interest: http://stackoverflow.com/questions/3554719/find-a-file-in-vim – David Winslow Sep 29 '10 at 04:13
-
1Now I've been using vim a little more I've noticed that I don't actually need to do half as much navigation. Why? I can open all the files that I want to work on at once in different viewports. I realise now that my real question was really, what's an efficient workflow for working with several files at once. Viewports are actually a much better solution than fast navigation around the file system. – opsb Oct 24 '10 at 12:10
8 Answers
I set path
properly then use find
for most things. Sometimes I just rely on the tags. The tags allow tab-completion, but find does not.
in my vimrc:
set path=src/**;c:/work,scripts/**;c:/work
then
:find foobar.cpp
Will turn up foobar.cpp if it exists under a src/ folder somewhere around my current directory (recursing up to find it until c:/work is hit) and then check the scripts hierarchy.
:tag FooBar
just jumps me right to the definition of that class, as I use ctags to tag my C source code and I also wrote a script to generate tags for an in-house DSL.

- 17,383
- 5
- 46
- 62
-
This is the best workflow I've heard so far. I see there is an rtags project for ruby so I'll give that a look. – opsb Sep 29 '10 at 11:30
What I'm using generally:
For opening new files:
:e
with tab-completion, or:Ex
(open explorer in the directory of current file).For jumping between files in the buffer list (
:ls
): the taglist plugin, or:b
and its tab-completion. Note that for:b
, tab-completion works for substrings. For example, if you have two files in buffer list: module.h and module.cpp, you can type:b cpp
and tab will complete module.cpp. Very handy!
For tab-completion I also recommend the must-have wildmenu (:set wildmenu
:set wildmode=full
)

- 7,988
- 2
- 21
- 17
Honestly? I rarely open a code file by name. For the most part I use ctags with ctrl-] to navigate around the files (following through to definitions between files), along with ctrl-t, ctrl-i, and ctrl-o. On the rare occasions I want to open a file by name, that's what a shell/explorer window is for.

- 16,497
- 3
- 46
- 59
-
-
@opsb: This question http://stackoverflow.com/questions/563616/vim-and-ctags-tips-and-tricks might be relevent if you're looking at ctags. – jkerian Sep 29 '10 at 15:28
Many people just use the normal file explorer in the bash command line or Windows Explorer or whatever and open files as necessary. For navigating existing source trees, cscope and ctags are both very useful. I find the project plugin really useful for IDE-like navigation of projects and files: it tends to be the main way I navigate my source tree. Combined with ctags, cscope, command-t and ack, navigation can generally be very fast.

- 70,428
- 10
- 106
- 108
"Traditionally?" I've used :Sex
for years. That and tab-completion for file-names doesn't make it that bad. Even in directory nestings 8 or 9 deep, using /mo
to jump to the directory "models", hit then o
to open it... etc etc.
I have installed Command-T on one machine, which is nice, but nothing beats the reliability of netrw

- 7,926
- 3
- 27
- 38
-
-
Not sure what you mean... but it is a standard file explorer... you see one directory at a time. – sleepynate Sep 30 '10 at 13:21
I also only use the basic file and buffer commands for managing my projects. However, I found the following plugins make things easier as well:
- Fuzzy Finder ( makes opening files more pleasant )
- NERDTree ( already mentioned, does a nice directory explorer view )
- Taglist ( useful for navigating in a file )
- alternate.vim ( useful for programming languages such as C++ with corresponding file types .h and .cpp )
- MiniBufExplorer ( makes keeping track of buffers easier )
Also, simply remapping :bn and :bp to something easier makes switching buffers more pleasant. For example:
nmap <C-n> :bn<cr>
nmap <C-p> :bp<cr>
Lastly, it wasn't mentioned but it is related to project management type stuff, make sure to check out the built in compile-edit stuff
- :help quickfix
I find that a lot people first coming to vim do not notice it right away.

- 1,930
- 1
- 15
- 23
-
The examples in the paragraph starting with "Also, simply remapping ..." are missing. Would you please fix that? – Yaser Sulaiman Sep 28 '10 at 19:51
I'm understand that it's may be too late, but I hope this would be useful for someone.
We have relatively large project on work of about thousand files of C/C++ code, php and shell scripts, configs and other stuff.
To navigate through files I use following options.
First, I use simple grep wrapper, stored in my .vimrc
to find specific string in files:
function MyGrep( pattern, path, case, whole )
execute "normal! GoSearch text " . a:pattern . " in " . a:path . " and subdirs, case: " .a:case. " whole: ".a:whole
"E - extended regexp, l - display filenames only, r - search recursively
let l:keys = "Elr"
if a:case == 0
"case-sensitive
let l:keys = l:keys . "i"
endif
if a:whole != 0
"whole words only
let l:keys = l:keys . "w"
endif
let l:cmd = "r!grep -" . keys . " -e \"" . a:pattern ."\" "
let l:cmd2 = a:path . " --exclude=*.ncb --exclude=*.o --exclude=*.d --exclude-dir=.svn --exclude-dir=.d --exclude-dir=rc.d --binary-files=without-match"
echo l:cmd . l:cmd2
execute l:cmd . l:cmd2
endfunction
com -nargs=1 GrepHere call MyGrep( <q-args>, "./", 0, 0)
com -nargs=1 GrepHereCaseWhole call MyGrep( <q-args>, "./", 1, 1)
com -nargs=1 GrepHereCase call MyGrep( <q-args>, "./", 1, 0)
com -nargs=1 GrepHereWhole call MyGrep( <q-args>, "./", 0, 1)
On windows I use vimgrep and changelist with this command (also in .vimrc
):
command -nargs=1 VGCodeHere :vimgrep /<args>/j ./**/*.{c,cpp,h,rc} | copen
Both 'greppers' are depend on current working directory, so don't forget to set it properly. I usually open a new unnamed tab in Vim and use this search commands there to dump there file names that I'm interested in, search results, logs locations and other info.
Second, a cscope utility and plug-in for Vim - it is Very convenient way to browse files, functions, symbols in project, but if you dealing with C/C++ sources.
Third, native Vim tricks, such as
:e ./**/filename.cpp
to open filename.cpp somewhere in file system subtree. Supports <Tab> filename completion.:tabe %<.h
to open corresponding header file (you can change .h extension to whatever you like):Ex
to navigate, using built-in file system browser- Ctrl-O, Ctrl-I to go backwards and forward in Vim jump list
And to resume next time from the same Vim state I use sessions.
Save session in Vim with
:mksession sessionname.vis
, and launch vim with session:
vim -S sessionname.vis

- 25
- 1
- 7