I spend almost all day programming in Vim and I am sure that a lot of you do too. What features do you use that make your day to day coding that much better? One that I use is gv, which will let you reselect the previously selected text. It is great for reindenting!

closed as not constructive by Gaff, Sathyajith Bhat Aug 31 '11 at 4:07

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

13 Answers 13



This command replaces all instances of x in the current file with y. This is basically just a find and replace, but I use it so often since I've learned it at work that it has become invaluable.

Also, /search string

then n to navigate through all instances of the search string within the file. Great for doing manual tweaks a lot more easily, especially if you can't apply a rule to the entire file.

  • I'm actually working on converting a largish section of our codebase at work and I'm doing it entirely with vim regular expressions (so far). It works really well! – Frew Schmidt Jul 15 '09 at 17:46
  • Add 'c' to the end of that to make the command interactive. e.g. :%s/x/y/gc – sml Sep 21 '10 at 6:21
  • 1
    Note that the % is where to do the substitution - % means "the current file." If you visually highlight some lines and type :s, you can do a substitution just in that selection. – Nathan Long Feb 1 '11 at 17:40

== does nice auto-indenting on the current line.

Normally, though, I use = with a motion, like =G to indent to the end of the file, or =i} to indent inside the current set of curly braces.

  • 2
    Also keep in mind >> and << which can manually do (un)indenting. – Frew Schmidt Jul 15 '09 at 17:46
  • @Frew - yep. Also, if you add vmap <Tab> >gv and vmap <S-Tab> <gv to your .vimrc, you can indent and unindent with Tab and Shift-Tab, respectively, AND it will go right back into visual selection mode so you can indent or unindent further. – Nathan Long Feb 1 '11 at 17:34

=% for auto-indenting everything within a block of code.

  • Oooh! That's new to me! – Frew Schmidt Jul 17 '09 at 22:09
  • That works if your cursor is on the beginning {. If you're inside the block, you can do =i{, for "indent inside the curly braces." – Nathan Long Feb 1 '11 at 17:38

Use * in command mode to search for the word under the cursor.

  • 1
    And don't forget it's sister command, #, which does the same thing but goes backwards instead of forwards! – Frew Schmidt Jul 15 '09 at 14:58

The :! command - invaluable for lsing, and the "sudo tee" trick.

I've been asked to explain the tee trick. Basically, it allows you to save a text file with admin priveleges, even if you didn't start VIM as root:

:w !sudo tee %
  • You might want to explain the "sudo tee" trick in here :-) Also I like to do :!sort after highlighting variable definitions and whatnot. – Frew Schmidt Jul 15 '09 at 14:57
  • You can really turn Vim into a great "scriptable" editor using :! and some shell/Python/Perl/other scripts. – Jonas Jul 15 '09 at 15:05
  • I actually have an alternative to !ls, which runs a vnew, outputs r!ls into the new buffer, and shrinks it horizontally. I can't be bothered to remember all of the files in a directory with over three in it ;) – new123456 Nov 16 '11 at 3:06

Hitting the . key repeats the previous command. Lovely for, say, editing an .ini, or so.

  • this is surprisingly powerful, but it takes a bit of vim-ing before you can really get good with it. – aaron Jun 13 '11 at 4:26

syntax color highlighting


I am always using gq to re-do line breaks on email, text files, etc. Really useful when replying to email (I use pine) and editing multiple previous replies.

  • Oooh, I'd totally forgotten about this! – Frew Schmidt Jul 16 '09 at 1:32
  • Why, oh why, can't the more popular email clients support similar functionality? – erichui Jul 16 '09 at 1:50
  • Recently I am using gw instead of gq because it keeps the cursor position – SergioAraujo Feb 1 '18 at 22:10

Where to start... Here's the things I can recall I've used in the last 5 minutes or so.

  • NERD Tree - File exploring. Makes VIM more like an IDE.
    • One huge thing for me is the ability to cd to a directory and then drop to a shell prompt through my shell mappings (below).
  • ci for emptying whatever you're stuck between.
  • :! for launching standard apps.
    • I have mappings for launching a shell prompt, mysql client, apache log files, etc.
    • Subversion integration is always nice. Quick diffs, stats, etc.
  • :abbr for making repetitive typing of large blocks go away.
  • Tabs. Need I say more?
  • Splitting out files, always good. :Sex is always nice.
  • :set paste! to keep from having auto-indent run amok.
  • I use all of these except for abbr. I tend to make a lot more macros than abbreviations. – Frew Schmidt Jul 17 '09 at 21:53

ZZ save and exit (instead of :wq!)

  • Huh? What about x? – DevSolar Sep 16 '11 at 7:17

I heavily use following commands while writing or traversing C/Tcl/Perl code:

copy-paste code

CTRL-f and CTRL-b for page forward and backward traversal
% for block-by-block traversal
^ goto start of line
$ goto last end of line

start selecting code using command v (visual mode) and any of the traversal key above
y for copy
p for paste

s to delete a character and goto insert mode to type new text.

Code level traversals (requires coding style discipline)

]] for start of next function
[[ for start of prev function

CTRL-] to jump to definition of a variable/function/macro if tags are available.


* => search word (or text selected using v) in forward direction
# => search word (or text selected using v) in backward direction
n => execute previous search command in forward direction
N => execute previous search command in backward direction

All the above commands can be prepend with a number to signify how many times to execute it. The realization of the power of this additional dimension comes slowly as one uses vim more and more and challenges oneself to improve.

  • Ah, ]] and [[ are new to me. That's cool! – Frew Schmidt Oct 21 '09 at 19:33

I just enter Text. Everything else is just ... Sugar.


I'm a former user of TextPad, and had memorized many of that program's accelerator keys. One of the first things I did in Vim was learning the map function to keep consistency (F5 search, F8 replace, etc.). I created my personal colorscheme, and borrowed alot from others' vimrc files. Viva Vim! Configurable to any degree.

Not the answer you're looking for? Browse other questions tagged or ask your own question.