VIMTUTOR Tutorial Summary#
This article is based on the summary of the seven chapters of the Vimtutor tutorial, created to facilitate my review of some basic operations of Vim during daily use and leisure time. It also helps students who are interested in learning the Vim editor to have some understanding of basic operations.
Lecture One#
Cursor Movement
- The cursor can be moved in the text on the screen using either the arrow keys or the hjkl letter keys.
- h (move left)
- j (move down)
- k (move up)
- l (move right)
Entering and Exiting VIM
- To enter the Vim editor (from the command line prompt), please type: vim filename
- To exit the Vim editor, please type
<ESC>
- ! to abandon all changes.
- Type
<ESC>
<Enter>
to save changes. - Pressing
<ESC>
will return to normal mode or undo an incomplete command you did not want to input.
Text Editing: Insertion and Deletion
- In normal mode, to delete the character at the cursor position, please press: x
- To insert or add text, please type:
- i to insert text before the cursor
- A to add text after the cursor
Lecture Two#
Deletion Commands
- dw: delete from the current cursor to the next word;
- d$: delete from the current cursor to the end of the current line;
- dd: delete the entire line (actually cut)
Commands and Objects
- In normal mode, the format for modifying commands is:
operator [number] motion
For example, d2w deletes the next two words.
Where:
operator - the operator representing the action to be taken, such as d for delete
number - an optional number representing the number of times the action is repeated
motion - the action representing movement over the text being operated on,
for example, w represents word, $ represents end of line, etc.
Using Counts to Specify Actions
- 2w: move the cursor forward two words
- 3e: move the cursor to the end of the third word
- 0: move the cursor to the beginning of the line
Whole Line and Undo
- dd deletes the entire line
- u: undo the previous operation
- U: undo changes made in one line
- CTRL+R: redo
Lecture Three#
Put Commands
- p: to reinsert deleted text, press the lowercase p key. This operation will place the deleted text after the cursor. If the last deletion was an entire line, that line will be placed in the line following the current cursor line.
Replace Commands
- r: to replace the character at the cursor position, type the lowercase r followed by the new character to replace the original character.
- R: uppercase R can enter
Change Commands
- c: change commands allow you to modify the text from the current cursor position to the position indicated by the action.
For example, typing ce can replace the content from the current cursor to the end of the word; typing c$ can replace the content from the current cursor to the end of the line.
Change command format: c [number] motion
Lecture Four#
Positioning and File Status
- CTRL-G is used to display the current cursor position and file status information.
G is used to jump the cursor to the last line of the file.
Typing a line number followed by uppercase G will move the cursor to the line represented by that line number.
gg is used to jump the cursor to the first line of the file.
Search Commands
- /: typing / followed by a string will search forward for that string in the currently edited document.
?: typing ? followed by a string will search backward for that string in the currently edited document.
After completing a search, pressing n will repeat the last command, searching for the next matching string in the same direction, or pressing uppercase N will search for the next matching string in the opposite direction.
CTRL-O will take you back to older positions, while CTRL-I will take you to newer positions.
Finding Matching Parentheses
- If the cursor is on a parenthesis (, ), [, ], {, }, pressing % will move the cursor to the matching parenthesis.
Replace Command
- To replace the first occurrence of the string old with the new string new in a line, please type
/old/new - To replace all occurrences of the string old with the new string new in a line, please type
/old/new/g - To replace all occurrences of the string old with the new string new in two lines, please type :
#,#s/old/new/g
- To replace all occurrences of the string old with the new string new in the file, please type :%s/old/new/g
- To prompt the user for confirmation for each replacement during a full text replacement, add the c flag: :%s/old/new/gc
Lecture Five#
Executing External Commands
- :!command is used to execute an external command command.
- :!dir :!ls - is used to display the contents of the current directory.
- :!del FILENAME :!rm FILENAME - is used to delete the file named FILENAME.
Saving File Content
- FILENAME can save the currently edited file in VIM to a file named FILENAME.
Selective Save Command
- v motion FILENAME can save the selected content in visual mode from the currently edited file to the file FILENAME.
Extracting and Merging Files
- FILENAME can extract the disk file FILENAME and insert it after the cursor position in the current file.
- !dir can read the output of the dir command and place it after the cursor position in the current file.
Lecture Six#
Open Commands
- o: typing lowercase o can open a new line below the cursor and enter insert mode.
- O: typing uppercase O can open a new line above the cursor.
Append Commands
- a: typing lowercase a can insert text after the cursor position.
- A: typing uppercase A can insert text after the end of the line where the cursor is.
- e: the command can move the cursor to the end of the word.
Another Version of Change Commands
- The operator y copies text, and p pastes the previously copied text.
- Typing uppercase R will enter replace mode until you press
<ESC>
to return to normal mode.
Copying and Pasting Text
- y: copy
- p: paste the previously copied text
- yy: copy the current line
Setting Command Options
- Typing xxx can set the xxx option. Some useful options are as follows:
'ic' 'ignorecase' ignore case when searching
'is' 'incsearch' show partial matches when searching phrases
'hls' 'hlsearch' highlight all matching phrases
Option names can be used in full or abbreviated form.
To turn off an option, add no before the option: noic
Lecture Seven#
Getting Help Information
- Typing or pressing
<F1>
or<Help>
can open the help window. - Typing cmd can find help about the cmd command.
- Typing CTRL-W CTRL-W can allow you to jump between windows.
- Typing will close the help window.
Creating Startup Scripts
- You can create a vimrc startup script file to save your preferred settings.
Completion Function
- When typing a : command, pressing CTRL-D can show possible completion results.
Pressing can use a completion.