# Learning the vi Editor/Vim/Tips and Tricks

* Learning the vi Editor:
* Getting acquainted —
* Basic tasks —
* Making your work easier —
* Advanced tasks —
* Details —
* Vi clones
* (Vim –
* Basic navigation –
* Modes –
* Tips and Tricks –
* Useful things for programmers to know –
* Enhancing Vim –
* Vim on Windows –
* VimL Script language,
* Vile,
* BB vi) —
* vi Reference
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.

## About this Book
### 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 compatible settings.

### Conventions Used
#### <c>

    A single character, such as 'a' or '1'.

#### <ESC>, <Ctrl-[>

    Indicates that the Escape (Esc) key on your keyboard should be pressed, which is identical to Control and '['.

#### <CR>

    Indicates that the Carrier Return (Enter) key should be pressed.

#### <TAB>

    Indicates that the Tabulator key should be pressed

#### <Ctrl-x>, <C-x>

    Indicates that the Control key and the 'x' key should be pressed simultaneously. 'x' can be almost any other key on your keyboard.

#### <Shift-x>, <S-x>, <X>

    Indicates that the Shift key and the 'x' key should be pressed simultaneously

#### <Meta-x>, <M-x>

    Indicates that the Meta or Alt key and the 'x' key should be pressed simultaneously.

#### :quit, :q

    An Ex command. started with <:>, followed by the command and ends with <CR>. For many Ex commands there is a long form (:quit) and a short form (:q).

#### :set nocompatible

    represents a setting.

#### strlen

    represents a function.

#### /pattern/, ?pattern?

    A Search pattern. Search pattern in vi are regular expressions.

#### :ranges/search/replace/options, :global /pattern/ delete

    A Search pattern combined with an Ex command.
All commands in vi are case sensitive.
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:

## Vim Help

If you are new to vi, try the vimtutor 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 'nocompatible' is already set)
* Help tag completion: if you think 'foo' is part of something which has a hyperlink in the help system, use
    where <Tab> 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 <Left> and <Right> arrow keys; accept a selection by hitting <Enter>, abort by hitting <Esc>.
* The :helpgrep function: if you think that some regular expression describe text you want to search for in the text of all the help files, use
    where <pattern> 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 |more-prompt| (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

## Inserting Text From a File or Register

If your text is in a file on its own, you can use :r with a line number (the number of the line after which to insert, or 0 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 r. The file name comes as an argument at the end.
Example (after line 5):
If your text is in a register, you can use :put 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 :put.
Example (before cursor line):
You can also insert a string directly using :put and direct assignment:
See

## Full Screen Mode

To achieve a full screen editing window on any version of gvim you can do:
* 'guioptions': 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".
* 'lines', 'columns': setting them to a large value will maximize the window.
For more, see:
* Learning the vi Editor:
* Getting acquainted —
* Basic tasks —
* Making your work easier —
* Advanced tasks —
* Details —
* Vi clones
* (Vim –
* Basic navigation –
* Modes –
* Tips and Tricks –
* Useful things for programmers to know –
* Enhancing Vim –
* Vim on Windows –
* VimL Script language,
* Vile,
* BB vi) —
* vi Reference