I came VIM

VIM

Click i in the file to enter vim mode.

vim filename can open vim and create a file named filename

Press ESC to jump to command mode

  1. : w Save the file but do not exit vim
  2. : w file Save the changes to the file without exiting vim
  3. : w! Force save without exiting vim
  4. : wq save the file and exit vim
  5. : wq! Force save the file and exit vim
  6. : q exit vim without saving the file
  7. : q! Do not save the file, forcefully quit vim
  8. : e! Discard all changes and edit from the last time the file was saved

vim mode

Normal mode (Press Esc or Ctrl + [Enter] The file name is displayed in the lower left corner or it is an empty
insert mode ( I key in normal mode ) The lower left corner displays --INSERT--

The visual mode (v, V, <Ctrl> + v in normal mode) is temporarily understood to be operable with the mouse--VISUAL-- and other
command modes (normal mode enter) The lower left corner is displayed

File commands

vim file open a single file

vim file1 file2 file3 ... open multiple files at the same time

: open file Open a new file in the vim window

: split file Open file in new window

: bn switch to the next file

: bp Switch to the previous file

: args View the list of currently open files. The files currently being edited will be enclosed in [].

: e ftp://192.168.10.76/abc.txt to open remote files, such as ftp or share folder

:e \\qadrive\test\1.txt

Navigation commands

% Bracket matching

Insert command

i Insert at the current position

I Insert at the beginning of the current line

a insert after current position

A Insert at the end of the current line

o Insert a line after the current line

O Insert a line before the current line

Find commands

/ text find text, press n key to find the next one, press n key to find the previous one.

? text find text, reverse search, press n key to find the next one, press n key to find the previous one.

There are some special characters in vim that need to be escaped when searching. * [] ^% /? ~ $

: set ignorecase ignore case search

: set noignorecase does not ignore case search

Find a very long word. If a word is very long and you have trouble typing, you can move the cursor to the word and press * or # to search for the word, which is equivalent to / search. The #command is equivalent to? Search.

: set hlsearch highlights search results, all results are highlighted instead of just showing a match.

: set nohlsearch Turn off the highlight search display

: nohlsearch Turn off the current highlight. If you search again or press the n or N key, it will highlight again.

: set incsearch Step-by-step search mode, search the currently typed characters without waiting for the completion of typing.

: set wrapscan Re-search, when it finds the beginning or end of the file, return to continue searching, it is enabled by default.

Replace command

ra replaces the current character with a, and the current character is the character under the cursor.

s / old / new / replace old with old, replace the first match of the current line

s / old / new / g replace old with old, replace all matches of the current line

% s / old / new / replace old with old, replace the first match of all lines

% s / old / new / g replace old with old, replace all matches of the entire file

: 10,20 s / ^ / / g Add four spaces in front of each line on line 10 and line 20 for indentation.

ddp swaps the line under the cursor and the line immediately below it.

Move command

h Shift one character to the left
l Shift one character to the right. This command is rarely used and is generally replaced by w.
k Move up one character
j Move down one character
or more. Four commands can be used with numbers. For example, 20j is 20 lines down and 5h is 5 characters left. In Vim, many commands can be used with numbers, such as Delete 10 characters 10x, insert 3 after the current position! , 3a! <Esc>, Esc here is required, otherwise the command will not take effect.

w Move forward one word (the cursor stops at the beginning of the word), and if it has reached the end of the line, go to the beginning of the next line. This command is fast and can replace the l command.

b Move backward one word 2b Move backward two words

e, same as w, but the cursor stops at the end of the word

ge, same as b, the cursor stops at the end of the word.

^ Move to the first non-blank character of this line.

0 (number 0) moves to the first character in this line,

<HOME> Move to the first character of this line. Same as 0 Jian.

$ Move to the end of the line 3 $ Move to the end of the next 3 lines

gg moves to the file header. = [[

G (shift + g) Move to the end of the file. =]]

The f (find) command can also be used to move, fx will find the first character after the cursor is x, and 3fd will find the third character with d.

F Same as f, reverse search.

Jump to the specified line, colon + line number, and press Enter. For example, jump to line 240 is: 240 Enter. Another method is line number + G, such as 230G jump to 230 lines.

Ctrl + e scroll down one line

Ctrl + y scroll up one line

Ctrl + d scroll down half screen

Ctrl + u scroll up half screen

Ctrl + f scroll down one screen

Ctrl + b scroll up one screen

Undo and redo

u Undo
U Undo the operation of the entire line
Ctrl + r Redo (Redo), that is, undo undo.

Delete command

x delete the current character

3x delete the current cursor starting three characters backward

X Delete the previous character of the current character. X = dh

dl deletes the current character, dl = x

dh delete the previous character

dd delete the current line

dj delete the previous line

dk delete the next line

10d Delete the first 10 lines of the current line.

D Delete the current character to the end of the line. D = d $

d $ delete all characters after the current character (this line)

kdgg delete all lines before the current line (excluding the current line)

jdG (jd shift + g) delete all lines after the current line (excluding the current line)

: 1,10d delete lines 1-10

: 11, $ d delete 11 lines and all subsequent lines

: 1, $ d delete all lines

J (shift + j) deletes the blank line between the two lines, and actually merges the two lines.

Copy and paste

yy copy the current line

nyy copies the n lines starting after the current one, for example, 2yy copies the current line and the next line.

p Paste after the current cursor. If you used the yy command to copy a line before, then paste it on the next line of the current line.

shift + p paste before the current line

: 1,10 co 20 Insert lines 1-10 after line 20.

: 1, $ co $ Make a copy of the entire file and add it to the end of the file.

In normal mode, press v (word by word) or V (line by line) to enter the visual mode, and then use the jklh command to move to select certain lines or characters, and then press y to copy

ddp exchange the current line and its next line

xp swaps the current character and the next character

Cut command

In normal mode, press v (word by word) or V (line by line) to enter the visual mode, then use the jklh command to move to select certain lines or characters, then press d to cut

ndd Cut n lines after the current line. Use the p command to paste the cut content

: 1,10d Cut 1-10 lines. Use the p command to paste the cut content.

: 1, 10 m 20 Move lines 1-10 after line 20.

Exit command

: wq save and exit

ZZ Save and exit

: q! Force exit and ignore all changes

: e! Discard all changes and open the original file.

Window commands

: split or new to open a new window, the cursor stops on the top window

: split file or: new file to open the file in a new window

The windows opened by split are horizontal, and the windows can be opened vertically using vsplit.

Ctrl + ww move to the next window

Ctrl + wj Move to the lower window

Ctrl + wk Move to the upper window

close the window

: close This command cannot be used for the last window to prevent accidentally exiting vim.

: q If it is the last closed window, then vim will exit.

ZZ Save and exit.

Close all windows and keep only the current window

:only

Record macro

Press the q key to add any letter to start recording, and then press the q key to end recording (this means that macros in vim cannot be nested), when using @ 加 宏 名, such as qa. . . q Record a macro named a, @a uses this macro.

Execute shell command

:!command

:! ls List files in the current directory

:! perl -c script.pl It is very convenient to check the syntax of perl script without exiting vim.

:! perl script.pl Execute the perl script without having to exit vim, which is very convenient.

: suspend or Ctrl-Z Suspend vim, return to the shell, press fg to return to vim.

Comment command

Perl program #behavior comment, so to comment some lines, just add # at the beginning of the line

3,5 s / ^ / # / g Comment lines 3-5

3,5 s / ^ # // g Uncomment 3-5 lines

1, $ s / ^ / # / g Annotate the entire document.

:% s / ^ / # / g Annotate the entire document, this method is faster.

Help command

: help or F1 displays the entire help
: help xxx displays the help of xxx, such as: help i,: help CTRL- [(that is, the help of Ctrl + [).
: help 'number' Help for Vim options is enclosed in single quotes
: help <Esc> Help for special keys is expanded with <>
: help -t Help for Vim startup parameters-
: help i_ <Esc> Insert in the Esc mode Help, the help in a certain mode uses the mode_ topic's mode
help file. The content between || is a hyperlink, you can use Ctrl +] to enter the link, Ctrl + o (Ctrl + t) to return

Other non-editing commands

. Repeat the previous command

: set ruler? Check whether ruler is set. In .vimrc, the options set with the set command can be viewed through this command

: scriptnames View the location of vim script files, such as .vimrc files, syntax files and plugins.

: set list displays non-printable characters, such as tabs, spaces, and line endings. If the tab cannot be displayed, make sure to set the .vimrc file with the set lcs = tab:>-command, and make sure that there is indeed a tab in your file. If expandtab is enabled, the tab will be expanded to a space.

Vim tutorial
on Unix systems
$ vimtutor
on Windows systems
: help tutor

: syntax lists the defined syntax items
: syntax clear clears the defined syntax rules
: syntax case match is case sensitive, int and Int will be treated as different syntax elements
: syntax case ignore is not case sensitive, int and Int will be treated as Same syntax elements, and use the same color scheme

Click i in the file to enter vim mode.

vim filename can open vim and create a file named filename

Press ESC to jump to command mode

  1. : w Save the file but do not exit vim
  2. : w file Save the changes to the file without exiting vim
  3. : w! Force save without exiting vim
  4. : wq save the file and exit vim
  5. : wq! Force save the file and exit vim
  6. : q exit vim without saving the file
  7. : q! Do not save the file, forcefully quit vim
  8. : e! Discard all changes and edit from the last time the file was saved

vim mode

Normal mode (Press Esc or Ctrl + [Enter] The file name is displayed in the lower left corner or it is an empty
insert mode ( I key in normal mode ) The lower left corner displays --INSERT--

The visual mode (v, V, <Ctrl> + v in normal mode) is temporarily understood to be operable with the mouse--VISUAL-- and other
command modes (normal mode enter) The lower left corner is displayed

File commands

vim file open a single file

vim file1 file2 file3 ... open multiple files at the same time

: open file Open a new file in the vim window

: split file Open file in new window

: bn switch to the next file

: bp Switch to the previous file

: args View the list of currently open files. The files currently being edited will be enclosed in [].

: e ftp://192.168.10.76/abc.txt to open remote files, such as ftp or share folder

:e \\qadrive\test\1.txt

Navigation commands

% Bracket matching

Insert command

i Insert at the current position

I Insert at the beginning of the current line

a insert after current position

A Insert at the end of the current line

o Insert a line after the current line

O Insert a line before the current line

Find commands

/ text find text, press n key to find the next one, press n key to find the previous one.

? text find text, reverse search, press n key to find the next one, press n key to find the previous one.

There are some special characters in vim that need to be escaped when searching. * [] ^% /? ~ $

: set ignorecase ignore case search

: set noignorecase does not ignore case search

Find a very long word. If a word is very long and you have trouble typing, you can move the cursor to the word and press * or # to search for the word, which is equivalent to / search. The #command is equivalent to? Search.

: set hlsearch highlights search results, all results are highlighted instead of just showing a match.

: set nohlsearch Turn off the highlight search display

: nohlsearch Turn off the current highlight. If you search again or press the n or N key, it will highlight again.

: set incsearch Step-by-step search mode, search the currently typed characters without waiting for the completion of typing.

: set wrapscan Re-search, when it finds the beginning or end of the file, return to continue searching, it is enabled by default.

Replace command

ra replaces the current character with a, and the current character is the character under the cursor.

s / old / new / replace old with old, replace the first match of the current line

s / old / new / g replace old with old, replace all matches of the current line

% s / old / new / replace old with old, replace the first match of all lines

% s / old / new / g replace old with old, replace all matches of the entire file

: 10,20 s / ^ / / g Add four spaces in front of each line on line 10 and line 20 for indentation.

ddp swaps the line under the cursor and the line immediately below it.

Move command

h Shift one character to the left
l Shift one character to the right. This command is rarely used and is generally replaced by w.
k Move up one character
j Move down one character
or more. Four commands can be used with numbers. For example, 20j is 20 lines down and 5h is 5 characters left. In Vim, many commands can be used with numbers, such as Delete 10 characters 10x, insert 3 after the current position! , 3a! <Esc>, Esc here is required, otherwise the command will not take effect.

w Move forward one word (the cursor stops at the beginning of the word), and if it has reached the end of the line, go to the beginning of the next line. This command is fast and can replace the l command.

b Move backward one word 2b Move backward two words

e, same as w, but the cursor stops at the end of the word

ge, same as b, the cursor stops at the end of the word.

^ Move to the first non-blank character of this line.

0 (number 0) moves to the first character in this line,

<HOME> Move to the first character of this line. Same as 0 Jian.

$ Move to the end of the line 3 $ Move to the end of the next 3 lines

gg moves to the file header. = [[

G (shift + g) Move to the end of the file. =]]

The f (find) command can also be used to move, fx will find the first character after the cursor is x, and 3fd will find the third character with d.

F Same as f, reverse search.

Jump to the specified line, colon + line number, and press Enter. For example, jump to line 240 is: 240 Enter. Another method is line number + G, such as 230G jump to 230 lines.

Ctrl + e scroll down one line

Ctrl + y scroll up one line

Ctrl + d scroll down half screen

Ctrl + u scroll up half screen

Ctrl + f scroll down one screen

Ctrl + b scroll up one screen

Undo and redo

u Undo
U Undo the operation of the entire line
Ctrl + r Redo (Redo), that is, undo undo.

Delete command

x delete the current character

3x delete the current cursor starting three characters backward

X Delete the previous character of the current character. X = dh

dl deletes the current character, dl = x

dh delete the previous character

dd delete the current line

dj delete the previous line

dk delete the next line

10d Delete the first 10 lines of the current line.

D Delete the current character to the end of the line. D = d $

d $ delete all characters after the current character (this line)

kdgg delete all lines before the current line (excluding the current line)

jdG (jd shift + g) delete all lines after the current line (excluding the current line)

: 1,10d delete lines 1-10

: 11, $ d delete 11 lines and all subsequent lines

: 1, $ d delete all lines

J (shift + j) deletes the blank line between the two lines, and actually merges the two lines.

Copy and paste

yy copy the current line

nyy copies the n lines starting after the current one, for example, 2yy copies the current line and the next line.

p Paste after the current cursor. If you used the yy command to copy a line before, then paste it on the next line of the current line.

shift + p paste before the current line

: 1,10 co 20 Insert lines 1-10 after line 20.

: 1, $ co $ Make a copy of the entire file and add it to the end of the file.

In normal mode, press v (word by word) or V (line by line) to enter the visual mode, and then use the jklh command to move to select certain lines or characters, and then press y to copy

ddp exchange the current line and its next line

xp swaps the current character and the next character

Cut command

In normal mode, press v (word by word) or V (line by line) to enter the visual mode, then use the jklh command to move to select certain lines or characters, then press d to cut

ndd Cut n lines after the current line. Use the p command to paste the cut content

: 1,10d Cut 1-10 lines. Use the p command to paste the cut content.

: 1, 10 m 20 Move lines 1-10 after line 20.

Exit command

: wq save and exit

ZZ Save and exit

: q! Force exit and ignore all changes

: e! Discard all changes and open the original file.

Window commands

: split or new to open a new window, the cursor stops on the top window

: split file or: new file to open the file in a new window

The windows opened by split are horizontal, and the windows can be opened vertically using vsplit.

Ctrl + ww move to the next window

Ctrl + wj Move to the lower window

Ctrl + wk Move to the upper window

close the window

: close This command cannot be used for the last window to prevent accidentally exiting vim.

: q If it is the last closed window, then vim will exit.

ZZ Save and exit.

Close all windows and keep only the current window

:only

Record macro

Press the q key to add any letter to start recording, and then press the q key to end recording (this means that macros in vim cannot be nested), when using @ 加 宏 名, such as qa. . . q Record a macro named a, @a uses this macro.

Execute shell command

:!command

:! ls List files in the current directory

:! perl -c script.pl It is very convenient to check the syntax of perl script without exiting vim.

:! perl script.pl Execute the perl script without having to exit vim, which is very convenient.

: suspend or Ctrl-Z Suspend vim, return to the shell, press fg to return to vim.

Comment command

Perl program #behavior comment, so to comment some lines, just add # at the beginning of the line

3,5 s / ^ / # / g Comment lines 3-5

3,5 s / ^ # // g Uncomment 3-5 lines

1, $ s / ^ / # / g Annotate the entire document.

:% s / ^ / # / g Annotate the entire document, this method is faster.

Help command

: help or F1 displays the entire help
: help xxx displays the help of xxx, such as: help i,: help CTRL- [(that is, the help of Ctrl + [).
: help 'number' Help for Vim options is enclosed in single quotes
: help <Esc> Help for special keys is expanded with <>
: help -t Help for Vim startup parameters-
: help i_ <Esc> Insert in the Esc mode Help, the help in a certain mode uses the mode_ topic's mode
help file. The content between || is a hyperlink, you can use Ctrl +] to enter the link, Ctrl + o (Ctrl + t) to return

Other non-editing commands

. Repeat the previous command

: set ruler? Check whether ruler is set. In .vimrc, the options set with the set command can be viewed through this command

: scriptnames View the location of vim script files, such as .vimrc files, syntax files and plugins.

: set list displays non-printable characters, such as tabs, spaces, and line endings. If the tab cannot be displayed, make sure to set the .vimrc file with the set lcs = tab:>-command, and make sure that there is indeed a tab in your file. If expandtab is enabled, the tab will be expanded to a space.

Vim tutorial
on Unix systems
$ vimtutor
on Windows systems
: help tutor

: syntax lists the defined syntax items
: syntax clear clears the defined syntax rules
: syntax case match is case sensitive, int and Int will be treated as different syntax elements
: syntax case ignore is not case sensitive, int and Int will be treated as Same syntax elements, and use the same color scheme

Guess you like

Origin www.cnblogs.com/a1431329726/p/12737076.html