"Linux Learning 012" vim Detailed

Source: Internet
Author: User
Tags exit in

I. Three modes of VIM

There are three modes in vim: edit mode, input mode, last line mode

When you open a file by using the VIM command, it is in edit mode by default.

1. Edit mode--Input mode

I: Convert to input mode before the current cursor character

A: After the current cursor character, convert to input mode

O: Create a new line below the current cursor line and convert to input mode

I: Converted to input mode at the beginning of the line at which the cursor is currently located

A: At the end of the line where the current cursor is located, convert to input mode

O: Create a new row above the line where the cursor is currently positioned and convert to input mode

2. Input mode--edit mode

Esc

3. Edit mode---last-line mode

:

4. Last-line mode--edit mode

Esc,esc

Input mode cannot be converted directly to the last row mode, it must first be converted to edit mode and then to the last row mode

Second, open the file

1.vim +# FILENAME: Open the file and navigate to the nth row of the file

2.vim + FILENAME: Open the file and navigate to the last line

3.vim +/pattern: Opens the file and navigates to the beginning of the line that was first matched to the PATTERN

Default in edit mode after opening a file

Iii. closing files 1. Closing files in the last line mode
: Q
Exit
: q! Do not save and exit
: Wq or: X
Save and exit
: W
Save
: w!
Forcibly saved
2. Exit in edit mode

ZZ: Save and exit

3. Forced exit

CTRL + C, the result of using this method is to produce a. swp file, which will save unsaved content to facilitate the next time you edit the file to restore, so it is troublesome, strongly do not recommend the direct CTRL + C exit, according to normal process exit will not produce such a file.

Iv. cursor Movement (edit mode)
1. Move the cursor character by word
H Move one character to the left
J Move down one character
K Move one character up
L Move one character to the right
#h | J | K | L Left | down | up | Move one character to the right
2. Move the cursor by word
W Jump to the first of the next word
B Jump to the header of the previous word
E Jump to the end of the next word
#w Jump to the header of the next # words
#b Jump to the top of a # Word
#e Jump to the tail of the next # Word
3. In-line jump
0 Jump to the absolute beginning
$ Jump to absolute end of line
^ Jumps to the first non-whitespace character at the beginning of the line
4. Jump between rows
Gg Jump to First line
G | :$ Jump to the last line
#G | :#
Jump To Line #
Five, flip screen
Ctrl+f
Flip one screen down
Ctrl+b Turn One screen up
Ctrl+d Flip Down half screen
Ctrl+u Flip up half screen
Vi. deletion of
1. Delete characters
X Delete the character at which the cursor is located
#x Remove the total # characters from the cursor and back
2. Delete words
[#]dw Delete the word where the cursor is located
[#]db Delete a word before the cursor is located
[#]de Delete a word after the cursor, notice the difference between the DW
3. Delete rows
Dd Delete the row where the cursor is located
#dd Delete the line with the current cursor and a total of # lines down
Vii. Copy and paste
1. Copy, use the y command, and use the D command exactly the same way.
2. Paste

Content deleted using the D command is saved to the system pasteboard using the y command and can be pasted to the specified location using the P or P commands.

(1). P command: If the copied or deleted non-full line is pasted to the current cursor after the character, if the copy or delete the entire line, it will be pasted to the current cursor under the line.

(2). P command: If the copied or deleted non-full line is pasted to the front of the character at the current cursor, if the copy or delete is an entire row, it will be pasted to the current cursor at the top of the line.

Viii. Modification of content

Use the C command to delete the specified content in edit mode and switch to input mode, using the same method as the D command.

Nine, replace
R Replace the character at which the cursor is located
R Turn on replace mode for a large number of substitution operations
X. Revocation and counter-revocation
U Undo Last Action
#u Undo Recent # Operations
Ctrl+r Reverse Undo Last Action
Xi. Visualization
V Select by character
V Select by row
12. Find
/ Look down
? Look up
13. Replace

The command syntax of the substitution is exactly the same as the SED command syntax

ADDR1,ADDR2 S/pattern/string/gi

You can use 1,$ to specify a full-text range, but you can use% instead.

14. Use Vim to edit multiple Files 1. Single Display a file
Vim FILE1 FILE2 FILE3 ...
: Next Switch to the next file
:p Rev Switch to previous file
: Last Switch to the last file
: First Switch to the first file
: QA All
2. Edit multiple files in a window
Vim-o Horizontal split Display
Vim-o Vertical split display
Ctrl+w,j The cursor moves to the following window
Ctrl+w,k The cursor moves to the window above
Qa Close all windows
XV, splitter window
Ctrl+w,s Horizontal split Window
Ctrl+w,v Vertical splitter window
Ctrl+w,j The cursor moves to the following window
Ctrl+w,k The cursor moves to the window above
Qa Close all windows
16. Save some of the contents of the file to another file
: ADDR1,ADDR2 W FILEPATH
17. Fill the contents of another file into the current file
: R    FILENAME
18. Interacting with the shell
! COMMAND
19. Advanced Topic 1. Display or suppress line numbers
: Set Number | Set Nu Show line Numbers
: Set Nonumber | Set Nonu Do not display line numbers
2. Display ignores or distinguishes character case
: Set IgnoreCase | Set IC Ignore case
: Set Noignorecase | Set Noic Case sensitive
3. Set Auto Indent
: Set Autoindent | Set AI Set Auto Indent
: Set Noautoindent | Set Noai Cancel Auto Indent
4. The found text is highlighted or canceled
: Set Hlsearch Found text highlighting
: Set Nohlsearch Suppress the found text highlighting
5. Syntax highlighting
: Syntax on
Syntax highlighting
: Syntax off Cancel syntax highlighting
20. Configuration Files
/etc/vimrc Global configuration file
~/.vimrc Personal configuration Files





This article is from the "stolen A Plum blog" blog, please be sure to keep this source http://kdyzm.blog.51cto.com/8316029/1741437

"Linux Learning 012" vim Detailed

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.