(Need a .vimrc to get you started on your way to customization glory? Use mine!)
viis the legacy, POSIX-standard program,
vimis the new, not always compatible program
:qis short for
Access Vim’s built-in help system by typing
<i>in Normal mode (or
exmode: line-oriented mode. Run screaming.
<i>to enter Insert mode
When done typing, hit
<Esc> to go back to Normal mode, then
doc.txt to save the file. (Shortcut:
<i> to add more text, then hit
<Esc>:w to write the
current file to disk.
Congratulations, you’ve used Vim to write a document!
Sure, you can use arrow keys, PageUp, PageDown, etc. with Vim.
nvi), it may not understand arrow keys
<h>moves the cursor one character left (think:
his the left-most character)
<l>moves the cursor one character right (think:
lis the right-most character)
<j>moves the cursor one character down (think:
jhangs below the line)
<k>moves the cursor one character up (think:
kascends above the line)
<C-u>to page down/up
<C-u>instead of arrow and page keys if they work?
<w>moves one word forwards
<b>moves one word backwards
<^>moves to the first non-whitespace character at the beginning of a line
<0>moves to the beginning of a line, too (think: column zero)
<$>moves to the end of a line (think: regular expressions)
<G>moves to the last line of a document (think: Goto. No, it doesn’t make sense in this context. More later.)
<gg>moves to the first line of a document
:[line]<CR>moves the cursor to the line number specified. For instance,
:16<CR>would move the cursor to line 16 of the current buffer.
<e>moves one word forwards, and places the cursor at the end of the word
<2w>moves two words forwards
<4j>moves four lines down
<12G>goto the twelfth line from the top of the document (I told you to wait for it.)
<3h>moves three characters backwards
zcommand can be useful to move the viewport around (in Normal mode)
<z<CR>>moves the current line to the top of the screen
<z.>moves the current line to the middle of the screen
<z->moves the current line to the bottom of the screen
<i>enters Insert mode and lets you start typing exactly where the cursor is located
<I>will place the cursor at the first non-space character on a line, then put you in Insert mode.
<a>will let you append text. It places the cursor one character to the right, then places you in Insert mode.
<A>appends text to the end of a line.
<o>opens a new text line below the current line.
<O>opens a new text line above the current line.
<h>to move backwards until your cursor is resting on the extra “d”
<x>to delete the character under the cursor
<BS>(Backspace) to delete it
<Esc>to go back to Normal mode
<b>to moves backwards by words until your cursor is at the beginning of the second “brown”
<dw>to delete the word at the cursor.
din the previous example). Other modifiers include:
<c>changes the following [character/word/etc.] by deleting it, then putting Vim into Insert mode so you can start typing
<dd>to delete a line.
The above is an example of a forwards search. To perform a
backwards search, use
nwhen doing a backwards search will find the next occurrence earlier in the document.
To find the previous occurrence of the same pattern, use
To find the next occurrence of the word underneath the cursor, in
Normal mode hit
Similarly, to find the previous occurrence of the word underneath the
<Esc>to get there from Insert mode) for all of these.
:s/cat/dog/g. (Note the absence of the percentage sign!)
:s/cat/dog/. (Note the absence of the
gat the end!)
<n>to search for the next occurrence of cat, and then use
<&>to replace it with dog.
<v>(this enters Visual mode)
<y>to yank the text into Vim’s clipboard.
<p>to paste it. Note: the yanked text will be placed after the cursor. Use
<P>to paste yanked text before the cursor.
<Y>commands do not work in regular
:set numberin Normal mode. Turn them off again by typing
:help command. For example:
:help w(to get help on the movement command)
:help :w(to get help on the
:help vimtutor(a very useful built-in tutorial!)