Saturday, August 19, 2006

VIM (and some vi)

Everybody who knows me knows that I love vim. Vim is a powerful version of the vi editor. It usually comes with any *NIX instillation. It rules. Here are some links, and some of my favorite (non-obvious) tricks. If you are new to all of this, a good place to start is the VI lovers home page or, if you are in a hurry, the quick reference card.

VIM

Plain old VI

Tricks
  • Swap two characters xp
  • Swap two lines ddp
  • Reverse the order of all lines :g/^/m0/
  • Remove all lines with only whitespace :g/^\s*$/d
  • Move all lines onto one logical line :%j
  • Remove all blank lines :g/^$/d
  • Insert a newline at the end of every line :%s/$/^m/ (keystrokes to get this one are: Ctrl+V, Ctrl+M)
  • Text completion before, after cursor: Ctrl+N, Ctrl+P (thanks to neha for this link )
  • Get a command prompt :shell
  • Execute a shell command :!<command>
  • Append the contents of a file into your vi session :r!cat <file>
  • Omni-completion Ctrl+X Ctrl+O
  • Whole line completion Ctrl+X Ctrl+L
  • Search for a word forward under the cursor *
  • Search for a word backwards under the cursor #
  • Move to a percentage of the file: type the number, then hit %

1 comment:

Neha said...

Ultimate Vi tip

http://unixdesk.blogspot.com/2006/06/10-most-valuable-tips-vi-editor.html