Official Account: MarkerHub, Website:
https://markerhub.com

Small Hub Guide:

Knowing that you use Vim less, a lot of commands are easy to forget, so specially collected a wave of commonly used command set, I hope to help you!


The command history

Commands that begin with: and/have a history. You can select a history by first typing: or/and then pressing the up and down arrow.

Start the vim

Enter the following command in a command line window

Vim starts Vim directly

Vim Filename opens Vim and creates a file named Filename

File command

Open a single file

vim file

Open multiple files at the same time

vim file1 file2 file3 …

Open a new file in the Vim window

:open file

Open the file in a new window

:split file

Switch to the next file

:bn

Switch to the previous file

:bp

Looking at the list of currently open files, the files currently being edited are enclosed in [].

:args

Open remote files, such as FTP or Share Folder

E ftp://192.168.10.76/abc.txt

:e \qadrive est.txt

The pattern of vim

Normal mode (press ESC or CTRL +[enter) the lower left corner of the file name or empty INSERT mode (press I key to enter) the lower left corner of the display –INSERT– VISUAL mode (do not know how to enter) the lower left corner of the display — Visual —

Navigation command

% bracket matching

Insert command

I is inserted before the current position

I is inserted at the beginning of the current line

A is inserted after the current position

A inserts at the end of the current line

O Inserts a row after the current row

O Inserts a row before the current row

To find the command

/text search text, press n key to find next, press n key to find previous.

? Text search Text, reverse search, press N key to find the next, press N key to find the previous.

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

:set ignorecase ignores case lookup

:set noignorecase does not ignorecase lookup

Find a long word, if a word is long, it is difficult to type, you can move the cursor over the word, press the * or # key to search for the word, equivalent to/search. The # command is equivalent to? Search.

: Set hlsearch highlights the search results so that all results are highlighted instead of showing just one match.

: Set nohlsearch to turn off the highlighted search display

:nohlsearch turns off the current highlighting, which will be highlighted again if you search again or press the n or n key.

: Set incsearch step-by-step search mode to search for the currently typed character without waiting for it to complete.

: Set WrapScan to search again. When the header or tail of the file is searched, it will return to continue searching, which is enabled by default.

Replace the command

Ra replaces the current character with a, where the current character is the cursor character.

S /old/new/ Replace new with old, replacing the first match on the current line

S /old/new/g replaces new with old, replacing all matches on the current line

%s/old/new/ Replace new with old, replacing the first match of all rows

%s/old/new/g replaces new with old, replacing all matches in the entire file

: 10, 20 s / ^ / / g in the relevant 10 line 20 front row to add four Spaces, used for indentation.

The DDP swaps the line on which the cursor is located and the line immediately below it.

Mobile command

H to move one character to the left and l to move one character to the right. This command is rarely used. It is usually replaced by w. For example, 20j is to move 20 lines down, and 5h is to move 5 characters to the left. In Vim, many commands can be used with numbers, such as delete 10 characters 10x, insert 3 characters after the current position! 3 a!

, where Esc is required, otherwise the command does not take effect.

W moves one word forward (the cursor stops at the beginning of the word) and, if it reaches the end of the line, moves to the beginning of the next line. This command is fast and can replace the l command.

B moves back one word and B moves back two words

E is the 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.

Moves to the first non-white space character on the line.

0 (digit 0) moves to the first character of the line,

<HOME> moves to the first character of the line. With 0.

$moves to end of line 3$moves to end of line 3

Gg moves to file header. = [[

G (Shift + G) moves to end of file. =]]

The f (find) command can also be used for movement, where fx will find the first character of x after the cursor and 3fd will find the third character of d.

If F is the same as F, look in reverse.

Jump to the specified line, colon + line number, enter. For example, jump to line 240 is :240 enter. Another way to do it is to add G to the row number, so let’s say 230G jumps to 230.

Ctrl + E scroll down one line

Ctrl + Y scroll up one line

Ctrl + D scroll down half the screen

Ctrl + U scroll up half the screen

Ctrl + F scroll down one screen

Ctrl + B scroll up one screen

Undo and Redo

Ctrl + R Redo on an entire line. Undo of Undo.

The delete command

X deletes the current character

3x Deletes three characters from the beginning of the current cursor

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

Dl Deletes the current character, dl=x

DH deletes the previous character

Dd deletes the current row

DJ deletes the last line

DK deletes the next line

10d Deletes 10 lines starting from the current line.

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

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

KDGG deletes all rows before the current row (excluding the current row)

JDG (JD Shift + G) Deletes all rows after current row (not including current row)

:1,10 D Delete lines 1-10

:11,$d Deletes 11 and all subsequent rows

:1,$d Deletes all rows

J(Shift + J) deletes the empty line between two lines, essentially merging the two lines.

Copy and Paste

Yy copies the current row

Nyy copies n rows starting after the current, such as 2yy copies the current row and the next row.

Paste after the current cursor, or the next line if you used the yy command to copy a 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 visual mode, then use the JKLH command to move to select some lines or characters, and then press Y to copy

The DDP swaps the current row with the next row

XP swaps the current character and the character that follows

Shear command

In normal mode, press V (word by word) or V (line by line) to enter visual mode, and then use JKLH command to move to select some lines or characters, and then press D to cut

NDD cuts n rows after the current row. The p command can be used to paste the cut content

:1,10 D Cut lines 1-10. The p command can be used to paste the content after cutting.

:1, 10 m 20 Moves lines 1-10 to after line 20.

Exit the command

: WQ Save and exit

ZZ saves and exits

:q! Force exit and ignore all changes

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

Window command

:split or new opens a new window with the cursor over the top-level window

:split file or: new file opens the file in a new window

Split opens Windows that are horizontal, but with VSplit you can open Windows vertically.

Ctrl+ WW Move to the next window

Ctrl+wj Move to the bottom window

Ctrl+wk Move to the top window

Close the window

:close The last window cannot use this command to prevent an accidental exit from Vim.

: Q If it is the last window to be closed, then exit Vim.

ZZ saves and exits.

Close all Windows, keeping only the current one

:only

Recording macros

Press Q to add any letter to start recording, then Q to end recording (this means that macros in Vim cannot be nested). Use @ to add the macro name, such as QA… Q records a macro named a, which @a uses.

Executing shell commands

:! command

:! Ls lists files in the current directory

:! Perl-c script.pl is a handy way to check the syntax of a Perl script without having to exit Vim.

:! Perl script.pl is a handy way to execute Perl scripts without having to exit Vim.

:suspend or Ctrl-Z suspend Vim, go back to shell, press FG to return Vim.

Annotation commands

A behavior comment that begins with # in a Perl program, so to comment some lines, just add a # at the beginning of the line

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

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

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

:%s/^/#/g Comments the entire document. This method is faster.

The help command

:help or F1 shows the entire help :help XXX shows the help of XXX, For example, the help I, :help ‘number’ Vim option help enclosed in single quotes :help

special key help with <> :help -t Vim boot parameter help with – : Help i_ < Esc > insert mode Esc help, with the help of a certain mode _ subject mode Is the content of the help file is located in the | | between hyperlinks, you can use Ctrl +] into the link, Ctrl + o (Ctrl + t) returns

Other non-edit commands

Repeat the previous command

: set a ruler? Check to see if the ruler has been set. In.vimrc, you can view all the options set using the set command

: ScriptNames looks at the location of Vim script files, such as.vimrc files, syntax files, plugins, etc.

:set list displays non-print characters such as TAB, space, end of line, etc. If tabs are not displayed, make sure you set the.vimrc file with set LCS = TAB :>- and make sure you do have tabs in your file. If you turn on expendtab, tabs will be expanded to Spaces.

Vim tutorial

On a UNIX system $vimtutor On a Windows system :help tutor :syntax lists the syntax items that have been defined :syntax clear Clear the syntax rules that have been defined :syntax case match case-sensitive, Int and int will be treated as different syntax elements :syntax case ignore case, int and int will be treated as the same syntax elements and use the same color scheme

Recommended reading

Amazing, this Java website, everything! https://markerhub.com

The B station of the UP Lord, the JAVA is really good!

Too great! The latest edition of Java programming ideas can be viewed online!