The most common commands used in vim are covered in the Tutor me! section. You did the tutor right? The following sections contain some additional commands.
Movement commands
Move to the end of the file.
Move to the beginning of the file.
Move back a page.
Move forward a page.
Scroll up.
Scroll down.
If you don't like the way the scrolling works you can adjust it with the scroll, scrolloff, and scrolljump options. Type :help scroll for more information. The vimrc files section explains how to make these adjustments permanent. |
Expose another line at the top. Useful for scrolling the screen without moving your cursor from its position.
Expose another line at the bottom. Useful for scrolling the screen without moving your cursor from its position.
Move forward a paragraph. Useful for moving through documents which have blank lines separating paragraphs or blocks. An easy way to distinguish between this and { is to remember it points in the direction you wish to go.
Move backward a paragraph. Useful for moving through documents which have blank lines separating paragraphs or blocks.
Move forward a sentence. An easy way to distinguish between this and ( is to remember it points in the direction you wish to go
Move backward a sentence.
Where number is a decimal number indicating the line number you wish to jump/move to.
Vim creates a "bookmark" each time you exit Vim. The last "bookmark" is '0. So if you have a file you haven't edited in a long time and can't remember where you left off simply type this command and it will take you to the place you last edited. You can find out what marks are set by typing :marks.
Reference :help navigation and :help motion for more information on motion commands.
Search commands
Search forward in the document for text. If found, vim will move the cursor to that position in the file. Once / is typed, text will show up in the status bar as you type it.
Search backward in the document for text. If found, vim will move the cursor to that position in the file. Once ? is typed, text will show up in the status bar as you type it.
Normally the search commands stop at the end or beginning of the file depending on which direction you are searching. You can force the search to "wrap around" the file using the wrapscan option. Type :help wrapscan for more information. |
This is a search command which will find the next occurance (forward) of the word the cursor is currently on.
Find the (n)ext occurance of the previous search. It will use the same direction (i.e. forward vs. backwards) of the previous search as well.
There are several options which allow you to enhance your searching. The hlsearch option highlights the text of the search. The incsearch option highlights and shows possible matches as you type the text. You can get more information on these options by typing :help hlsearch and :help incsearch. The vimrc files section explains how to make these adjustments permanent.
Deleting/selecting parts of a line
Delete forward until you find x (inclusive). If x is found, vim will delete everything from the current cursor position to and including x.
This one and its variations dFx, dtx, and dTx are very useful when editing mark-up languages like html and sgml. It is especially useful in deleting and changing quoted attributes within mark-up tags.
This is a combination of the (d)elete command and the (f)ind motion command. You may also substitute other commands for the delete portion of that command, such as visual by character, or yank.
Delete backward until you find x (inclusive). If x is found, vim will delete everything from the current cursor position to and including x.
Delete forward until you find x (exclusive). If x is found, vim will delete everything from the current cursor position to, but not including x.
Delete backward until you find x (exclusive). If x is found, vim will delete everything from the current cursor position to, but not including x.
Deleting/selecting spanning multiple lines
Delete forward until you find x (exclusive). If x is found, vim will delete everything from the current cursor position to, but not including x, spanning multiple lines if necessary.
x doesn't have to be one character. It's most likely to be a word or several characters. If you're editing your email, you could use this to delete all text up to your signature by executing d/--.
This is a combination of the (d)elete command and the (/) search forward motion command. You may also substitute other commands for the delete portion of that command, such as visual by character, Visual by line, or yank.
Delete backward until you find x (exclusive). If x is found, vim will delete everything from the current cursor position to, but not including x, spanning multiple lines if necessary.
Cut, copy, and paste
V selects the text by the line. Simply use j, k, or the paragraph motion commands ({, }) to select the block of text. Now type d to delete (cut) it, y to yank (copy) it, and p to paste it.
Spell checking
TODO.
Find and replace
This topic is covered extremely well by Sven Guckes. You can read the document here: http://www.math.fu-berlin.de/~guckes/vi/subst.html
Do you have a simple editing option you use frequently? Please send it to us at newbiedoc-discuss@lists.sourceforge.net so we can add it to this document.