21

I've been using Vim as my text editor for a little while now and I feel like I'm taking the long way to do anything. I use ctags to tag my code base for navigation and I use grep (although inefficiently) to find where certain methods are used. But I have a feeling there are some very useful tools out there that I don't know about that could make me more productive.

What is the best software stack I could use for general programming that would complement Vim? How do you navigate a code base, run make, push changes to your source control system, etc? Do you have a 2nd console open next to Vim?

4
  • 2
    Vim itself. Maybe you are not using the correct plugins/scripts for the job. It depends on what kind of programming you're doing, what language, what other tools you need and so forth.
    – Alex Bitek
    Aug 10, 2010 at 21:08
  • I'm not specifying any language so as not to influence the responses I'll get. I'm not really looking for Vim plugins, although they are useful. Aug 10, 2010 at 21:47
  • I found this presentation very useful: zmievski.org/2010/06/vim-for-programmers-on-slideshare
    – gabe.
    Aug 11, 2010 at 14:26
  • I made this a community wiki. I realized there is no single best answer to my question. Thanks to all for your answers! Aug 12, 2010 at 15:47

8 Answers 8

7

A great feature of vim is the ease of integration with existing shell commands. Some of the most useful external tools are the ones that are included in coreutils and other simple text maniplulation tools. For example, we can get the number of lines in a file with:

:! wc -l %

or the number of words:

:! wc -w %

Any command that works on the shell will work here. This can be powerfully combined with the :read (:r) command to put the output of the command into the file. For example:

:r !wc -l %

Will place the word line count into the file you are editing.

Another advantage of this is replacing the text you are currently editing with the output of one of these commands. For example, you could format the entire file with par by executing the command:

:% !par
0
5

I find NERDtree indispensible for navigating through my codebase. Alongside that, investing some time in becoming proficient in moving around your buffers/windows is really worthwhile.

1
4

Whatever your language you'll want to use a feature called ctags that lets to browse around source definitions. This requires an external tool to generate TAGS files that are used by VIM to discover the locations of various code definitions within a project.

Get the exuberant ctags tool, it works for many many languages and is v simple to use.

from VIM :help ctags

ctags will create an index of all identifiers in a source tree. You can then use the tag commands to navigate around your source tree. see :help tag-commands. The easiest is to place the cursor over a keyword and press CTRL-]. To get back to where you came from press CTRL-T

Beyond this you might want to look at some of the VIM tips and improvements discussed here, it's a very comprehensive discussion of some of the things than can be done to improve a vimmer's experience.

1
  • I did mention in my question I was using ctags, but thanks for the answer anyway! :) Aug 10, 2010 at 21:48
4

Vim is a very powerful tool, I am sure all of you already know that. You'll start getting a productivity boost by using vim within a couple of weeks. But you will never saturate your knowledge of Vim. So, I for one am always on the lookout for new and efficient ways of doing things in Vim. There is a guy named Derek Wyatt who's done some great screencasts on the usage of the Vim, and also on the plugins he uses.

A few of the plugins which I use

  1. command-t This makes browsing files a breeze, and it is very intelligent.

    The Command-T plug-in provides an extremely fast, intuitive mechanism for opening files with a minimal number of keystrokes. It's named "Command-T" because it is inspired by the "Go to File" window bound to Command-T in TextMate.

  2. fuzzyfinder I use this mostly to broswer buffers and change the current directory.

    FuzzyFinder provides convenient ways to quickly reach the buffer/file/command/bookmark/tag you want. FuzzyFinder searches with the fuzzy/partial pattern to which it converted an entered pattern

  3. NERDTree This is the best file browser plugin for vim.

    The NERD tree allows you to explore your filesystem and to open files and directories. It presents the filesystem to you in the form of a tree which you manipulate with the keyboard and/or mouse. It also allows you to perform simple filesystem operations.

  4. XPTemplate The best templating plugin in the world.

    Code snippets engine for Vim, with snippets library. XPTemplate let you write codes in a smooth, quick and comfortable way.

  5. rails.vim If you do rails dev stuff, this is indispensable.

    TextMate may be the latest craze for developing Ruby on Rails applications, but Vim is forever. This plugin offers the following features for Ruby on Rails application development.

  6. NerdCommenter Makes commenting in any kind of code easy.

And those are just a few of the plugins which I use, To download all the plugins with my vimrc, checkout my dotfiles

3

There's a great plugin for VIM that does syntax checking Syntastic. There are many other tools available as well for file management, building, etc. Go to IRC #vim on freenode.net, there are lots of helpful folks there.

3

my favorite is cscope. If you have compiled vim with cscope support, you can directly use cscope commands from VIM. e.g. searching for included files, functions called by xyz function, etc. I have tried it with a very large source code repository. It helps a lot.

http://cscope.sourceforge.net/cscope_vim_tutorial.html

1

If you are programming in any of the languages supported by GCC (C,C++,Java,Fortran) then Clewn is a great plugin that integrates the GDB debugger into VIM. I've actually found it to be one of the best interfaces to GDB that there is.

0

I usually set up a screen session for each project. Vim is in window 0, and I use window 1 for a shell session. If I'm coding in a language that has a decent REPL I usually run that in window 2. Of course, you don't need screen to do this; you could do it with different terminal windows or with tabs in a multitab terminal. I do find screen to be more stable than other alternatives: if your terminal app crashes, you can just start another terminal and reconnect to your still-running screen session. screen is also very quick to navigate in once you learn it (much like vim itself).

I mostly end up using the shell session for complicated version control activities like rebasing or merging: simpler things can be done from vim's command line (e.g. :!git commit % -m 'Added info aboutscreen.') or by using the fugitive addon. I find fugitive's :Gmove (rename the current buffer both in vim and in the git index) and :Gdiff (invoke vimdiff on the current buffer with a previous point in its history) particularly useful. You can also do things like building up a commit message in a scratch buffer, copying in text from various parts of your code, and then committing with :%!git commit -F /dev/stdin

I'll also use the shell session for functional/integration testing if that's applicable to whatever I'm working on, for example if I'm writing a command-line utility.

Vim's quickfix functionality is useful for debugging, though there seems to be a different addon required for each language you might want to work in. They also seem to use a variety of invocation techniques, mapping to function keys or to key sequences starting with \ or ,, or to custom commands, or by being automatically invoked when a buffer is saved. So far I haven't really bothered to suss this out, and just read unit test or lint results into a scratch buffer using e.g. :r !python -m doctest whatever.py. Modify code, switch back to the scratch buffer, u to undo, then hit :r and the up arrow (most of the time) to get that command back. But it may be worth your while to seek out an addon for this, depending on what language you work in.

For popular compiled languages like C, java, etc., :make will do a build, and support for the quickfix list is well established. So you can then do :copen to display the quickfix buffer. It will show a list of errors, one per line; hitting Enter on a line will jump your other window to that point in that file.

If you're working with multiple projects at a time, you can do :lmake to arrange for a list of errors to be stored in the location list: this is like the quickfix list but is associated with a single window rather than being a singleton within your vim instance. :lopen will open a location list for the current window.

Not the answer you're looking for? Browse other questions tagged .