# Using vim as a IDE

vim as IDE

Published on January 5, 2016

Vim is now my single editor for programming. However basic vim is missing some features necessary from an IDE:

• navigate through the files of your project,
• search files by name,
• search in files,
• open file which name is under cursor,
• compile your project and display the error message, in parallel with the faulty source file,
• open several files in parallel and copy/paste stuff between them.

So until recently I used vim only for very small projects. However with some setup you can manage to use it efficiently also for big programming projects!

To navigate through the files of your project, you can simply use this built-in feature: Explorer. You can start it with the command :E or :Explorer. The navigation is then entirely done with the keyboard. An alternative is to use the NERD tree extension.

### Search files by name

If you already know the name of the file that you want to edit and just want to jump to it, use the ctrlp extension. Ctrlp is a fuzzy file finder, that will open with the command ‘Ctrl-P’ on the keyboard. Ctrlp will then look for file names that are the closest possible with the name that you give. You can provide only partial or approximate file names. It present a list of files found, that you can then open. It is very practical!

### Search in files

To search a word in multiple files, I use the Ag extention. Binding it to the \ key allows for quick search. It also supports complex search expressions.

### Open file which name is under cursor

Source code often include file names in the text (such as ‘include’ or ‘import’ commands). It would be handy to be able to navigate to them… This feature is already supported natively by vim: place your cursor on top of an import file name, type gf (goto file) and it will open. It works also without filename extension and for files located in sub-directories.

### Compile / display error messages

To compile my program while keeping the source code open in parralel, I installed tmux. It allows you to have nice side-by-side terminal windows. I created a small script called “th” that launches tmux with the adequate two windows panes. For instance the command th README.md will open the readme file in vim in the top pane, with a shell in the bottom pane. You can use the mouse to switch panes, or Ctrl-a Arrows. One window will be dedicated to compilation, while the other is used for source code browsing. If the compilation shows errors, you can use Crl-P to find the file and then :<line number> to jump to the error.

### Edit files in parallel

To edit several files in parallel, first split the screen in two: :sp for horizontal split, and :vs for vertical split. Changing from one pane to another is done with Ctrl-w + an arrow. You can then select some piece of code with the visual mode: Ctrl-v and then copy them with y. Use Ctrl-Shift-v to select full lines. After changing pane, you can paste your selection with p. Quiting a pane is simply done with :q.

In sum, this setting is not specific to any programming language, so it will work will all of them! I am a long time vimmer, but I was never able to use it for programming in big projects. From what I gathered, vim is more geared to the work of the operator: loging to remote servers, launching commands, modifying some scripts… While Emacs is more geared towards developers work: editing a lot of files, compiling, checking for errors… Of course there is a big overlap between the two.

You can find all my configuration here, including tmux and vim configuration files.