Learning the vi Editor/Vim/Tips and Tricks

The Vim Tipbook is a collection of tips, hints and HowTos for using the Vim text editor. It is an outgrowth of the Vim tips database in a more flexible format, and also includes some helpful posts from the Vim mailing lists.

For information on the general use of Vim, please see the Learning the vi Editor/Vim.

Tips for Editing

 * Where possible, extensive personal configurations should be avoided. Keep suggestions within the scope of a single tip. You may wish to link to several other tips that might be used alongside, much in the same way a food cookbook would suggest dishes that go well together.
 * Always provide enough information so that a tip can be used from Vim's default  settings.

Conventions Used
Where a series of commands are required to be entered, these might be listed in a preformatted block:

Which will produce the following formatted text:

=70

Vim Help
If you are new to vi, try the  command. It's an excellent guide for the beginner.

Vim has an extensive help system. EVERYTHING is covered. This system is so extensive, however, that finding the needed information is sometimes akin to finding one's own little needle in a huge stack of hay. But even for that, there are Vim tools:


 * (assuming  is already set)


 * Help tag completion: if you think 'foo' is part of something which has a hyperlink in the help system, use

foo


 * where &lt;Tab&gt; means "hit the Tab key", and if there is only one possible completion Vim fills it in for you; if there is more than one the bottom status line is replaced by a menu which can be navigated by hitting the &lt;Left&gt; and &lt;Right&gt; arrow keys; accept a selection by hitting &lt;Enter&gt;, abort by hitting &lt;Esc&gt;.


 * The  function: if you think that some regular expression describe text you want to search for in the text of all the help files, use

&lt;pattern&gt;


 * where &lt;pattern&gt; is a Vim regular expression, like what you can use after / or ? . It may take some time for Vim to look up all its help files, and it may or may not display interim information which may require you to hit Enter to clear the  (q.v.) When the blinking cursor reappears in your editfile, it means Vim has compiled the list of all help locations where your regexp matches. See them by means of the following

or :cr or :cn or :cprev or :cN or :cla

Inserting Text From a File or Register
If your text is in a file on its own, you can use  with a line number (the number of the line after which to insert, or   for "before first line", or   for "after cursor line", or   for "after last line"; default is after cursor line) in the "range" position, i.e. just before the. The file name comes as an argument at the end.

Example (after line 5): 5r ~/template.txt If your text is in a register, you can use  with a line number (again) in the range position and the register name (including , which must be escaped as  , for the default register; or   for the system clipboard) after the.

Example (before cursor line): .-1put \" You can also insert a string directly using  and direct assignment:  :put ='This is text to insert.' See  :help :read  :help :put

Full Screen Mode
To achieve a full screen editing window on any version of gvim you can do:

:set lines=999 columns=999 m  when present, menu bar is present T  when present, toolbar is present on versions which support it (W32, GTK1, GTK2, Motif, Photon, kvim) l  when present, left scrollbar is always present L  when present, left scrollbar is present if there is a vertical split r  when present, right scrollbar is always present R  when present, right scrollbar is present if there is a vertical split b  when present, bottom scrollbar is present F  when present, gvim (Motif) will display a footer
 * : We remove the flags one-by-one to avoid problems if they appear in the option in a different order, or if some of them do not appear at all. By choosing which ones to remove (or not) you can customize your own flavour of "full-screen Vim".
 * , : setting them to a large value will maximize the window.

For more, see: :help 'guioptions' :help 'lines' :help 'columns'