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?
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.
"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
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
)
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: and
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.
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.
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.