Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
<BS>
key was already mentioned. It deletes the character just before the
cursor. The <Del>
key does the same for the character under (after) the
cursor.
When you typed a whole word wrong, use CTRL-W
:CTRL-W
CTRL-U
to delete
it. This keeps the text after the cursor and the indent. Only the text from
the first non-blank to the cursor is deleted. With the cursor on the "f" of
"fallen" in the next line pressing CTRL-U
does this:CTRL-U
<Esc>4blraA
<Esc>
four words back 4b
move on top of the "o" l
replace with "a" ra
restart Insert mode A<C-Left><C-Left><C-Left><C-Left><Right><Del>a<End>
<C-Left>
<C-Left>
<C-Left>
<C-Left>
move on top of the "o" <Right>
delete the "o" <Del>
insert an "a" a
go to end of the line <End>
<End>
key is hard to press without looking at the keyboard).
These special keys are most useful when writing a mapping that doesn't
leave Insert mode. The extra typing doesn't matter then.
An overview of the keys you can use in Insert mode:<C-Home>
to start of the file
<PageUp>
a whole screenful up
<Home>
to start of line
<S-Left>
one word left
<C-Left>
one word left
<S-Right>
one word right
<C-Right>
one word right
<End>
to end of the line
<PageDown>
a whole screenful down
<C-End>
to end of the file:set showmatchWhen you now type a text like "(example)", as soon as you type the ) Vim will briefly move the cursor to the matching (, keep it there for half a second, and move back to where you were typing. In case there is no matching (, Vim will beep. Then you know that you might have forgotten the ( somewhere, or typed a ) too many. The match will also be shown for [] and {} pairs. You don't have to wait with typing the next character, as soon as Vim sees it the cursor will move back and inserting continues as before. You can change the time Vim waits with the 'matchtime' option. For example, to make Vim wait one and a half second:
:set matchtime=15The time is specified in tenths of a second.
CTRL-P
, and Vim guesses the rest.
Suppose, for example, that you are creating a C program and want to type in
the following:CTRL-P
.
Vim searches for a word that starts with what's in front of the cursor. In
this case, it is "ch_", which matches with the word ch_array. So typing
CTRL-P gives you the following:CTRL-P
Vim will search again for a word that completes the
word before the cursor. Since there is nothing in front of the cursor, it
finds the first word backwards, which is "ch_array". Typing CTRL-P
again
gives you the next word that matches, in this case "total". A third CTRL-P
searches further back. If there is nothing else, it causes the editor to run
out of words, so it returns to the original text, which is nothing. A fourth
CTRL-P causes the editor to start over again with "ch_array".CTRL-N
. Since the search wraps around the end of the
file, CTRL-N
and CTRL-P
will find the same matches, but in a different
sequence. Hint: CTRL-N
is Next-match and CTRL-P
is Previous-match.CTRL-X
CTRL-F
file names
CTRL-X
CTRL-L
whole lines
CTRL-X
CTRL-D
macro definitions (also in included files)
CTRL-X
CTRL-I
current and included files
CTRL-X
CTRL-K
words from a dictionary
CTRL-X
CTRL-T
words from a thesaurus
CTRL-X
CTRL-]
tags
CTRL-X
CTRL-V
Vim command lineCTRL-N
can be used to find the next match, CTRL-P
to find
the previous match.
More information for each of these commands here: ins-completion.CTRL-X
CTRL-F
as an example. This will find file names. It scans
the current directory for files and displays each one that matches the word in
front of the cursor.
Suppose, for example, that you have the following files in the current
directory:CTRL-X
CTRL-F
. Vim now completes the
current word "sub" by looking at the files in the current directory. The
first match is sub_count.c. This is not the one you want, so you match the
next file by typing CTRL-N
. This match is sub_done.c. Typing CTRL-N
again
takes you to sub_exit.c. The results:CTRL-X
CTRL-F
. This
will match "/usr" (this is on Unix):CTRL-N
you go back to "/u". Instead, to accept the "/usr/"
and go one directory level deeper, use CTRL-X
CTRL-F
again:CTRL-X
CTRL-O
. Obviously the O stands for Omni
here, so that you can remember it easier. Let's use an example for editing C
source:{ struct foo *p; p->The cursor is after "p->". Now type
CTRL-X
CTRL-O
. Vim will offer you a list
of alternatives, which are the items that "struct foo" contains. That is
quite different from using CTRL-P
, which would complete any word, while only
members of "struct foo" are valid here.filetype plugin onOr:
filetype plugin indent onFor C code you need to create a tags file and set the 'tags' option. That is explained ft-c-omni. For other filetypes you may need to do something similar, look below compl-omni-filetypes. It only works for specific filetypes. Check the value of the 'omnifunc' option to find out if it would work.
CTRL-A
, the editor inserts the text you typed the last time you
were in Insert mode.
Assume, for example, that you have a file that begins with the following:"file.h" ~ /* Main program begins */ ~You edit this file by inserting "#include " at the beginning of the first line:
#include "file.h" ~ /* Main program begins */ ~You go down to the beginning of the next line using the commands "j^". You now start to insert a new "#include" line. So you type:
i CTRL-AThe result is as follows:
#include "file.h" ~ #include /* Main program begins */ ~The "#include " was inserted because
CTRL-A
inserts the text of the previous
insert. Now you type "main.h"<Enter> to finish the line:#include "file.h" ~ #include "main.h" ~ /* Main program begins */ ~The
CTRL-@
command does a CTRL-A
and then exits Insert mode. That's a quick
way of doing exactly the same insertion again.CTRL-Y
command inserts the character above the cursor. This is useful
when you are duplicating a previous line. For example, you have this line of
C code:CTRL-Y
14 times, until you are at the "n" of
"next":CTRL-Y
until the following "next":CTRL-E
command acts like CTRL-Y
except it inserts the character below the
cursor.CTRL-R
{register}
inserts the contents of the register. This is
useful to avoid having to type a long word. For example, you need to type
this:"vyiw"v is the register specification, "yiw" is yank-inner-word. Now edit the file where the new line is to be inserted, and type the first letters:
CTRL-R
v to insert the function name:<BS>
or other special characters,
they are interpreted as if they had been typed from the keyboard. If you do
not want this to happen (you really want the <BS>
to be inserted in the text),
use the command CTRL-R
CTRL-R
{register}
.:iabbrev ad advertisementNow, when you type "ad", the whole word "advertisement" will be inserted into the text. This is triggered by typing a character that can't be part of a word, for example a space:
:iabbrev JB Jack BennyAs a programmer, I use two rather unusual abbreviations:
:iabbrev #b /**************************************** :iabbrev #e <Space>****************************************/These are used for creating boxed comments. The comment starts with #b, which draws the top line. I then type the comment text and use #e to draw the bottom line. Notice that the #e abbreviation begins with a space. In other words, the first two characters are space-star. Usually Vim ignores spaces between the abbreviation and the expansion. To avoid that problem, I spell space as seven characters: <, S, p, a, c, e, >.
:abbreviate teh theYou can add a whole list of these. Add one each time you discover a common mistake.
:abbreviate i #e ****************************************/ i #b /**************************************** i JB Jack Benny i ad advertisement ! teh theThe "i" in the first column indicates Insert mode. These abbreviations are only active in Insert mode. Other possible characters are:
:edit ad
:abbreviate @f freshYou can remove it with this command:
:unabbreviate @fWhile you type this, you will notice that @f is expanded to "fresh". Don't worry about this, Vim understands it anyway (except when you have an abbreviation for "fresh", but that's very unlikely). To remove all the abbreviations:
:abclear":unabbreviate" and ":abclear" also come in the variants for Insert mode (":iunabbreviate and ":iabclear") and Command-line mode (":cunabbreviate" and ":cabclear").
:abbreviate @a adder :imap dd disk-doorWhen you now type @a, you will get "adisk-doorer". That's not what you want. To avoid this, use the ":noreabbrev" command. It does the same as ":abbreviate", but avoids that the resulting string is used for mappings:
:noreabbrev @a adderFortunately, it's unlikely that the result of an abbreviation is mapped.
CTRL-V
command is used to insert the next character literally. In other
words, any special meaning the character has, it will be ignored. For
example:CTRL-V <Esc>Inserts an escape character. Thus you don't leave Insert mode. (Don't type the space after
CTRL-V
, it's only to make this easier to read).CTRL-V
is used to paste text. Use CTRL-Q
instead of
CTRL-V
. On Unix, on the other hand, CTRL-Q
does not work on some
terminals, because it has a special meaning.CTRL-V
{digits}
to insert a character with the
decimal number {digits}
. For example, the character number 127 is the <Del>
character (but not necessarily the <Del>
key!). To insert <Del>
type:CTRL-V 127You can enter characters up to 255 this way. When you type fewer than two digits, a non-digit will terminate the command. To avoid the need of typing a non-digit, prepend one or two zeros to make three digits. All the next commands insert a
<Tab>
and then a dot:CTRL-V
9.
CTRL-V
09.
CTRL-V
009.CTRL-V
:CTRL-V x7fThis also goes up to character 255 (
CTRL-V
xff). You can use "o" to type a
character as an octal number and two more methods allow you to type up to
a 16 bit and a 32 bit number (e.g., for a Unicode character):CTRL-V o123 CTRL-V u1234 CTRL-V U12345678
CTRL-K CoTo find out what digraphs are available, use the following command:
:digraphsVim will display the digraph table. Here are three lines of it:
CTRL-K
Pd is the
character (£). This is character number 163 (decimal).
Pd is short for Pound. Most digraphs are selected to give you a hint about
the character they will produce. If you look through the list you will
understand the logic.
You can exchange the first and second character, if there is no digraph for
that combination. Thus CTRL-K
dP also works. Since there is no digraph for
"dP" Vim will also search for a "Pd" digraph.:digraph a" äThis defines that
CTRL-K
a" inserts an ä character. You can also specify the
character with a decimal number. This defines the same digraph::digraph a" 228More information about digraphs here: digraphs Another way to insert special characters is with a keymap. More about that here: 45.5
<Esc>
,
execute the Normal mode command, and re-enter Insert mode with "i" or "a".
There is a quicker way. With CTRL-O
{command}
you can execute any Normal
mode command from Insert mode. For example, to delete from the cursor to the
end of the line:CTRL-O DYou can execute only one Normal mode command this way. But you can specify a register or a count. A more complicated example:
CTRL-O "g3dwThis deletes up to the third word into register g.