Learn to use help
From Vim Tips Wiki
created 2005 · complexity basic · author David S · version 6.0
Vim's help is remarkably helpful, but in order to use it effectively you need to spend a few minutes learning how it is organised.
Contents |
[edit] Getting started
Try these examples:
- Enter
:helpto browse help. Scroll down the help page to see the quickref and tutor links, and the table of contents. - Enter :help pattern for help on the topic pattern (for example).
:h patternis the same (the:helpcommand can be abbreviated).
Command completion can be used when entering a help topic:
- Type
:h pattthen press Ctrl-D to list all topics that contain "patt". - Type
:h pattthen press Tab to scroll through the topics that start with "patt". - If you have set the
'wildmenu'option (e.g. by using:set wildmenu), then:h pattfollowed by<Tab>opens a menu on the statusline, with all help topics containing "patt". You can select any item in the menu with the arrow keys or more presses of the<Tab>key to fill in the rest of your command line.
Links:
- Enter
:hto open the main help page. - Type
/quickto search for "quick" (should find thequickreflink). - Press Ctrl-] to follow the link (jump to the quickref topic).
- After browsing the quickref topic, press Ctrl-T to go back to the previous topic.
- You can also press Ctrl-O to jump to older locations, or Ctrl-I to jump to newer locations.
Searching:
- Search within a help file using
/like you would when searching any file. - Search all the help files with the
:helpgrepcommand, for example:
:helpgrep \csearch.\{,12}file\cmeans the pattern is case insensitive.- The pattern finds "search" then up to 12 characters followed by "file".
- You will then see the first match. To see other matches for the same pattern, use:
:cnext:cprev:cnfile:cpfile:cfirst:clast
- and even
:cc
- which brings you back to the current match after you scrolled the helpfile, or
:copen
- which will list out all the matches in a separate window. Read up on these commands with the
:helpentry for each of them!
Each week (or more often if you prefer), read a new section from the :help page to learn something new!
[edit] Context
Each help topic has a context:
| Prefix | Example | Context |
|---|---|---|
: | :h :r | ex command (command starting with a colon) |
| none | :h r | normal mode |
v_ | :h v_r | visual mode |
i_ | :h i_CTRL-W | insert mode |
c_ | :h c_CTRL-R | ex command line |
/ | :h /\r | search pattern (in this case, :h \r also works)
|
' | :h 'ro' | option |
- | :h -r | Vim argument (starting Vim) |
Sometimes you want to know what a particular control key means to Vim. For example, to see all help topics containing "ctrl-r", type :h ctrl-r then press Ctrl-D. The following examples show the help for pressing various keys in different contexts.
| Example | Help for key |
|---|---|
:h CTRL-R | Ctrl-R in normal mode |
:h i_CTRL-R | Ctrl-R in insert mode |
:h c_CTRL-R | Ctrl-R in command mode |
:h v_CTRL-V | Ctrl-V in visual mode |
[edit]
The following mappings simplify navigation when viewing help:
- Press Enter to jump to the subject (topic) under the cursor.
- Press Backspace to return from the last jump.
- Press
sto find the next subject, orSto find the previous subject. - Press
oto find the next option, orOto find the previous option.
Create file ~/.vim/ftplugin/help.vim (Unix) or $HOME/vimfiles/ftplugin/help.vim (Windows) containing:
nnoremap <buffer> <CR> <C-]>
nnoremap <buffer> <BS> <C-T>
nnoremap <buffer> o /'\l\{2,\}'<CR>
nnoremap <buffer> O ?'\l\{2,\}'<CR>
nnoremap <buffer> s /\|\zs\S\+\ze\|<CR>
nnoremap <buffer> S ?\|\zs\S\+\ze\|<CR>
The following mappings (which can go in your vimrc) simplify navigating the results of quickfix commands such as (among others) :helpgrep
:nnoremap <S-F1> :cc<CR> :nnoremap <F2> :cnext<CR> :nnoremap <S-F2> :cprev<CR> :nnoremap <F3> :cnfile<CR> :nnoremap <S-F3> :cpfile<CR> :nnoremap <F4> :cfirst<CR> :nnoremap <S-F4> :clast<CR>
[edit] References
[edit] See also
- Remember to search this wiki (see 'search' in the sidebar)!
- Search the FAQ and other guides on our documentation page
- Search the archives of the Vim mailing lists
[edit] Comments
Also see the wildmenu. My settings:
set wildmenu wildmode=longest:full,full
What it does:
- First tab: longest match, list in the statusbar.
- Following tabs: cycle through matches.