My 10 favourite Vim tips, features and plugins

Contents

Tip 1: Save time with macros

qq

q

@q

10@q

Tip 2: Block mode editing

Ctrl-V Enter visual block mode Ctrl-Q Enter visual block mode (Windows) I Insert before selected block A Append to selected block c Change text in selected block r Replace text in selected block with character

Tip 3: Powerful search and replace

:%s/search/replace/g

:%s/\(\w\)\(\d\)\(\d\)/\1(\2, \3)/g



\w Word character \d Digit \1, \2, ... Replaced with the pattern between \( and \)

Tip 4: Repeat actions with the .dot key

.

Tip 5: Snippets

Tip 6: Switch between different open files (Lusty Juggler)

Tip 7: Command-T plugin

Tip 8: Taglist plugin

Tip 9: Auto format source code

= Format selected area == Format current line gg=G Format entire file

Tip 10: Split windows

Ctrl-W s Split window Ctrl-W v Split window vertical Ctrl-W c Close split window

A lot of text-editing tasks have a similar pattern. For example, doing the same kind of changes on multiple lines. While macros are not unique to Vim, the way you record and apply them is so fast, that you are really using them in practice. To record a macro simply press: (recording to register q)To stop recording:And then execute the macro (from register q):Or execute it 10 times:In the following example a macro gets recorded for the first line and is then applied to the next five lines:Many text files are structured column-wise and Vim has a powerful mode to edit them.Example: Turn e11, e12, ... to e(1, 1), e(1, 2), ...Simple actions can be repeated with the dot key:The following example shows four function declarations that are turned into a body for the actual implementation. Only the first function body is typed, the rest is repeated by simply pressing the dot key.Quickly insert often-typed text patterns with the snipMate plugin for Vim.For example to create the body of a for loop, type in for (in insert mode) and then tab. The snipMate will then insert the for loop body. It's a bit like IntelliSense. Pressing tab will cycle through the important parts of the for loop. You can customize your own snippets in a simple text file.The LustyJuggler is a high speed buffer juggler plugin and highly recommended.Lusty Juggler allows you to change the current file with the home row keys. This is especially great for touch typists.Fast file opening with only a few keystrokes. Just type in parts of the file name to locate and open the file. Link to Command-T Source code navigation for all kinds of files with the taglist plugin Auto format with the = command. A few examples:Edit files with multiple views.

If you have any questions or suggestions, send me a mail: