Hacker News new | ask | show | jobs
by janus 4504 days ago
As always, what loses me on vim is that I'm not sure what's the easiest/best/common way to have a "project directory" open and quickly open one of the files inside that directory... no basic tutorial seems to tackle this, yet it's essential to migrate from any other editor you use as a programmer...
6 comments

You want CtrlP - it's a plugin that works basically the same way as Sublime Text's Cmd-T.

If you want a more familiar Sublime-esque experience, you can also rebind it from Ctrl-P to Cmd-T (which is how I personally use it).

So my workflow on a Mac is to type `mvim ~/project-dir-goes-here` and then press Cmd-T just like I would in Sublime to start typing in a filename and see a list of matching files to open.

https://github.com/kien/ctrlp.vim http://stackoverflow.com/questions/11979313/command-key-in-m...

Another tip, and this one doesn't need a plug-in:

If your cursor is on a file name, like "foo.js", you can type gf to "go to that file" for editing.

Going back isn't as easy to remember. It's Control-O. So I map that in my .vimrc to gb like this:

    " gf is built in and will "Goto File"
    " gb is the opposite, will "Go Back"
    nnoremap gb <C-o>
I never navigate by searching for a filename.

If it's C/C++ code I use ctags and cscope and just ":tag <function-name>" to go to the function definition (VIM will autocomplete the function name).

If it's a Rails project, there's a Vim Rails plugin and then ":Econtroller <controller-name>" opens the relevant file, etc.

It's also possible to keep a file listing all of your project files (Or just edit your Makefile if you use one). Then just switch to that buffer, search ("/<blabla>") for the file and "gf" (goto-file - opens the file whose name is under the cursor).

I'm not sure if this is what you want, but NERD Tree[1] works for a lot of people.

Here's a tutorial[2] for NERD Tree that I quickly found.

[1]: https://github.com/scrooloose/nerdtree

[2]: http://code.tutsplus.com/tutorials/vim-essential-plugin-nerd...

thanks, I'll give it a try. When I briefly tried NERDtree, my issue was how to switch back and forth between the tree and the opened files list
hold down control and hit w, twice, when in visual mode. That will move the cursor from frame to frame.

If you want to see a 'file browser', open VIM and type ":sp ."

Strictly speaking you don't need nerdTree (though I love it ).

:e . Will show a directory listing, you can navigate the directory tree and open files. Particularly useful if you have a shortcut to change the working directory to the current buffer's file path.
I use that one all the time! Also, :sp . which splits your window and opens the directory listing in a new buffer.
I have things set up to easily drop the output of a git grep into my quickfix buffer, so I can step through occurrences across many files in my project.