VI command Vim command

Source: Internet
Author: User
Tags switch case

C compilation process

Step 1: Use VI to compile the. C code file

Step 2: gcc-G. C-o. Debug

Step 3 GDB

Step 4 file. Debug

List

Start debugging

Or GCC. C directly generates an executable file named A. Out.


./A. Out.

 

Run the VI command (for details about tab indentation and VIM configuration, refer to other articles in this blog)


VI filename: open or create a file and place the cursor at the beginning of the first line
Vi + N filename: open the file and place the cursor at the beginning of line N
Vi + filename: open the file and place the cursor at the beginning of the last line
Vi +/pattern filename: open the file and place the cursor at the first string matching pattern
VI-r filename: a system crash occurred when VI was being edited last time, restoring filename
VI filename... filename: open multiple files and edit them one by one.

Move cursor command
H: move the cursor one character to the left
L: move the cursor one character to the right

Space: move the cursor one character to the right
Backspace: move the cursor one character to the left
K or Ctrl + P: move the cursor up a row
J or Ctrl + N: move the cursor down a row

Enter: move the cursor down a row
W or W: move one word to the beginning of the word to the right of the cursor.
B or B: move one word left to the beginning of the word
E or E: move one word to the end of the word to the right of the cursor.
): Move the cursor to the end of the sentence.
(: Move the cursor to the beginning of the sentence.
}: Move the cursor to the beginning of the paragraph
{: Move the cursor to the end of the paragraph
NG: Moving the cursor to the beginning of line N is equivalent to: N
N +: move the cursor down n rows
N-: Move n rows above the cursor
N $: move the cursor to the end of line N
H: move the cursor to the top line of the screen
M: move the cursor to the middle line of the screen
L: move the cursor to the last line of the screen
0: (Note the number is zero) move the cursor to the beginning of the current row
$: Move the cursor to the end of the current row



Screen tumble command
CTRL + u: half screen at the beginning of the file
CTRL + D: Flip the half screen to the end of the file
CTRL + F: Flip the screen to the end of the file
CTRL + B; open a screen at the beginning of the file

NZ: Rolls row n to the top of the screen. If n is not specified, the current row is rolled to the top of the screen.

Insert text commands
I: Before the cursor
I: at the beginning of the current row
A: After the cursor
A: At the end of the current row
O: open a new row under the current row
O: open a new row above the current row.
R: Replace the current character

R: Replace the current and subsequent characters until you Press ESC.
S: Starting from the current cursor position, replace the specified number of characters with the input text
S: delete a specified number of rows and replace them with the input text
NCW or NCW: modify a specified number of characters
NCC: modifies a specified number of rows.

DELETE command
Ndw or ndw: n-1 characters starting at and following the cursor

Dd deletes the current row
Do: Delete to the beginning of a row
D $: Delete to the end of the row
NDD: Delete the current row and the next n-1 row
X or X: delete a character. x deletes the character after the cursor, and X deletes the character before the cursor.
CTRL + u: delete text entered in input mode

Search and replace commands
/Pattern: Search for pattern from the beginning of the cursor to the end of the file
? Pattern: Search for pattern from the beginning of the cursor
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the reverse direction.

: S/P1/P2/G: replace all p1 in the current row with P2.
: N1, N2s/P1/P2/G: replace all P1 from line N1 to line N2 with P2.
: G/P1/S // P2/G: replace all P1 files with P2.

Option settings
ALL: lists all options.
Term: Set the terminal type
Ignorance: Case Insensitive in search
List: displays the stop table (CTRL + I) and end mark ($)
Set nu: displays the row number.
Report: displays the number of changes made by line-oriented commands.
Terse: displays brief warning information
Warn: No write information is displayed if the current file is not saved when it is transferred to another file.
Nomagic: allows you to use special characters without "/" in search mode.
Nowrapscan: Prohibit VI from searching at both ends of the file and starting from the other end.
Mesg: Allows VI to display the information that other users write to their terminal using write.

Last-line command
: N1, N2 Co N3: copy the content from line N1 to line N2 to line N3.
: N1, N2 M N3: Move the content from line N1 to line N2 to line N3
: N1, N2 D: Delete content from line N1 to line N2
: W: Save the current file
: E filename: open the file filename and edit it.
: X: Save the current file and exit.
: Q: Exit VI.
: Q! : Do not save the file and exit vi

: WQ save and exit
:! Command: execute shell command
: N1, N2 W! Command: The content from line N1 to line N2 in the file is used as the command input and executed. If N1 and N2 are not specified, the entire file content is used as the command input.
: R! Command: place the output result of the command to the current line.

Register operation
"? Nyy: Save the content of the current row and Its n rows to the register? , Where? It is a letter, and N is a number.
"? Nyw: Save the current row and Its n characters to the register? , Where? It is a letter, and N is a number.
"? Nyl: Save the current row and Its n characters to the register? , Where? It is a letter, and N is a number.
"? P: retrieve the register? And place it at the cursor position. Here? It can be a letter or a number.
NDD: delete n lines of text from the current row and its bottom, and put the deleted content in the delete Register No. 1.



Vim commands in Linux

Some advanced editors will contain macro functions, which are certainly not missing in Vim. It is very convenient to use Macros in VIM:


: QX starts to record macros and saves the results to register x

Q exit record mode

@ X macro commands for playing records in the X register

After you enter QX in normal mode, all the edits to the text will be recorded. If you enter Q again, the record mode will be exited.

And then input @ X to repeat the recorded command. This command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeat 20 times. This is very useful in text batch processing.

Edit multiple files at the same time

Among the many Vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.

Tag command


: Tabe FN: edit the file FN in a new tab

GT switch to the next tab

GT switch to the previous Tab

: Tabr switch to the first tab

: Tabl switch to the last tab

: Tabm [N] Move the current tab to the nth Tab

Yes, as you think, it is similar to eclipse, ue, and other tabs!

Window command

CTRL + w s Horizontal Split Window

CTRL + W switch window

CTRL + w Q exit the current window (because there are multiple files at the same time, this command will not affect other Windows)

CTRL + W v Vertical Split Window

Others

Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: W.


: E file: load the file to the new buffer.

: BN jump to the next Buffer

: BD Delete buffer (close file)

: Sp fn split the window and load FN to the new window

Exit Editor


: W write the buffer to a file, that is, save the modification.

: WQ: Save the modification and exit.

: X Save the modification and exit

: Q exits. If the buffer is modified, a message is displayed.

: Q! Force exit, discard Modification

Search and replace

/Pattern: returns the string pattern.

? Pattern: returns the string pattern.

N: Next match (If yes/search, it is the next one ,? Search to the next one)

N match (same as above)

: % S/old/new/g search the entire file and replace all old with new

: % S/old/new/GC search for the entire file, replace all old with new, and each time you want to confirm whether to replace

Copy and paste

Dd deletes the row where the cursor is located.

DW deletes a word)

X Delete the current character

X Delete the previous character

D. Delete it to the end of the row.

YY: copy a row. The command can be followed by a number to identify multiple rows. For example, 6yy indicates that six rows are copied from the current row.

Copy one word from YW

Y $ copy to the end of the row

P paste the clipboard content to the current row

P paste the clipboard content to the current row

] P is indented and VIM automatically adjusts the code indent.

"A puts the content into/into register a, and supports multiple clipboard

Note: for example, a commonly used register is a system register with the name +. Therefore, the "+ P" command is pasted from the system clipboard to VIM. Note that the "+" operator is not represented here, 21 registers.

Move cursor

In vim, the moving cursor is very different from other editors, but once learned, it will quickly move in the text.


H, J, K, L upper, lower, left, right

CTRL-f.

CTRL-B

% Jump to the brackets matching the current brackets. If the current value is {, the jump is to the matching value }.

W jumps to the next beginning and is separated by punctuation or words.

W jumps to the beginning of the next word and performs a long jump. For example, end-of-line is considered to be a word.

E. Jump to the end of the next word.

E. Jump to the end of the next character, Long Jump

B jumps to the previous word.

B jumps to the previous word, Long Jump

Jump from 0 to the beginning of the line, whether indented or not, that is, jump to 0th characters

^ Jump to the first character of the line

$ Jump to the end of a row

Gg jumps to the first line of the file

GD jumps to the declaration of the variable where the current cursor is located

[N] G jump to the nth line, such as 0g, is equivalent to Gg, 100th G is rows

FX finds x characters in the current row, and jumps

; Repeat the previous F command, instead of repeatedly inputting FX

TX is similar to Fx, but only jumps to the first character of X.

FX and FX are in the opposite direction

), (Jump to the previous or next statement

* Find the word where the cursor is located and look down

# Search for words at the cursor and search up

'. Jump to the previous editing position

Move on screen


H move the cursor to the top line on the current screen

M move the cursor to the middle line on the current screen

L move the cursor to the bottom line of the current screen

Bookmarks

Ma stores the current position as tag

'A jump to tag

Edit

R to replace one character

J. Connect the next row to the current row.

CC deletes the current row and enters the editing mode

CW deletes the current word and enters the editing mode.

C $ erase the content from the current position to the end of the row and enter the editing mode

S. Delete the current character and enter the editing mode.

S. Delete the row where the cursor is located and enter the editing mode.

XP exchanges the current and next characters

U undo

CTRL + R redo

. Repeat the previous edit command.

~ Switch case sensitivity, current character

G ~ IW switches the case sensitivity of the current word

Guiw converts the current word to uppercase

Guiw converts the current word to lowercase

> Move the current row to the right of a unit.

<Shifts the current row to one unit (one Tab character) to the left)

= Automatically indent the current row


Insert mode

I enter insert mode from the current cursor

I enters the insert mode, and the cursor is placed at the beginning of the line.

A append mode, after the current cursor

A append mode, with the cursor placed at the end of the row

O Add a new row under the current row and enter the insert mode.

O Add a new row to the current row and enter the insert mode.

ESC exit insert mode

Visual Mode

Mark text

V enters the visual mode, Single Character Mode

V enters the visual mode, and the row Mode

CTRL + V enter the visual mode, column mode, similar to the column mode of UE

O jump cursor to another endpoint of the selected block

U converts the content in the selected block to uppercase

O jump cursor to another endpoint of the block

Aw select a word

AB Selects all the content in the brackets, including the brackets themselves.

All content in brackets selected by AB

The content in the column selected by IB, excluding the brackets

Content in {} selected by IB, excluding {}


Actions on tags

> Block shifted to the right

<Move left

Y copy Block

D. delete a block.

~ Change the case sensitivity of block content

Http://www.cnblogs.com/zhanglong0426/archive/2010/10/07/1845268.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.