Vim Editor Detailed

Source: Internet
Author: User
Tags exit in line editor

Outline

First, what is the vi text editor?

Second, vim common mode and switch

Third, VIM usage detailed



First, what is the vi text editor?

Text Editor can basically be divided into 2 categories: Full screen editor and line editor, such as SED is the line editor, VI, Nano, this is a full-screen editor, Open will occupy this screen. We often need to some service configuration file for some editing operations, if always use nano such as the editor, although easy to get started, but the function is simple, not very good to meet the daily work needs, so under the Linux system, master a good text editor will make our work efficiency becomes exceptionally efficient, So today we will learn VI editor use, VI full name is Visual Interface, translated into visual interface, and Vim is the enhanced version of VI, translated into VI improved. On the basis of VI, a number of functional collections have been added.


Second, vim common mode and switch

1.vim of three modes:

    • Edit mode (Command mode)

    • Input mode (insert mode)

    • Last-line mode

Note: This is the VI most commonly used three mode, next we explain how to switch between the three modes


2. Mode conversion:

(1). Edit mode--Input mode:

I: Switch to input mode before the current cursor character

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

o: Create a new row below the current cursor line and switch 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 current cursor line and switch to input mode


(2). Input mode--edit mode:

ESC key


(3). Edit mode--last-line mode:


(4). Last line mode--edit mode:

ESC key: If the last-line mode edit is currently in progress, double-press ESC is required



Third, VIM usage detailed

1. Open File

# Vim/path/to/somefile

Vim +#: Open the file and locate it on line #

Vim +: Open the file and navigate to the last line

Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN

Default in edit mode when opening a file with Vim


2. Close the file

(1). Last line mode close file

: Q exit

: Wq Save and exit

: q! Do not save and exit

: W Save

: w! Forcibly saved

: Wq---: X


(2). Exit in edit mode

ZZ: Save and exit


3. Move cursor (edit mode)

(1). Character-by-word movement:

h: Left

L: Right

J: Next

K: Up

#h: Moving a # character

(2). Move in Word units

W: Move to the beginning of the second word

e: Move to the ending of the current or next word

B: Move to the beginning of the current or previous word

#w: Move to the top of a post # word


(3). In-line jump:

0: The absolute beginning

^: first non-whitespace character at the beginning of a line

$: Absolute end of line


(4). Jump Between rows

GG: Jump to the first line of the file

#G: Jump To Line #

G: Jump to the last line of the file

In the last line mode, directly to the travel number.


4. Flip screen (edit mode)

ctrl+f: Flip one screen down

ctrl+b: Turn up one screen


ctrl+d: Flip down half screen

ctrl+u: Flip up half screen


5. Delete individual characters (edit mode)

X: Delete a single character at the cursor location

#x: Remove the total # characters from the cursor and backwards


6. Delete command: D (edit mode)

The D command is used in combination with the jump command

d$: Deletes the contents of the current cursor at the end of the line

#de: Deletes the current cursor to the bottom # Word ending content

DD: Deletes the current cursor in the row

#dd: Delete the # line including the line where the current cursor is located


In the last line mode:

Startadd,endaddd

.: Indicates when the forward

$: Last line

+#: Down # line


7. Paste command: P (edit mode)

P: If you delete or copy the entire line, paste it below the line where the cursor is located, or paste to the back of the character where the cursor is located if the copied or deleted content is not a whole line

P: If you delete or copy an entire row, paste it above the line where the cursor is located, or paste to the front of the character where the cursor is located if the copied or deleted content is not a whole line


8. Copy command: Y (edit mode)

Usage with d command

9. Modify the command: C (edit mode)

Delete content first, then convert to input mode

C: Usage with d command


10. Replace: R (edit mode)

R,string: The cursor is positioned to the character to be replaced, click R, and then click the character you want to replace to complete the replacement

R: Enter the replacement mode directly, and all the characters entered will be filled in as content to the cursor location.


11. Undo Edit Operation U (edit mode)

U: Undo the previous edit operation

The continuous u command undoes the previous n edit operations

#u: Undo Recent # edits directly) (up to 50 times in memory buffer)


Redo the most recent undo operation: Ctrl+r


12. Repeat the previous edit operation (edit mode)

.


13. Visualization mode (edit mode)

V: Select by character

V: Select by rectangle


14. Find (edit mode)

Same usage as less and man

/pattern: Finds a string matching PATTERN from the cursor location to the end of the file

? Pattern: Finds a string matching pattern from the cursor to the file header

N: The cursor jumps to the end of the file to the next searched string

N: The cursor jumps to the file header to the next searched string


15. Find and replace (last line mode)

Use the S command in the last-line mode

Addr1,[email Protected]@[email protected]

1,$

%: Full text



16. Use Vim to edit multiple files

Vim FILE1 FILE2 FILE3

: Next switches to the next file

:p Rev Switch to the previous file

: Last switch to final file

: first to switch to file one

: QA All exits


17, split screen display a file

Ctrl+w, S: Horizontal splitter window

Ctrl+w, V: Vertical splitter window


Toggle the cursor between windows:

Ctrl+w, H | l | J | K

: QA Closes all windows


18. Edit multiple files in a window

Vim-o: Horizontal Split display

Vim-o: Vertical Split display


19. Save part of the current file as a different file (last-line mode)

Use the W command in the last row mode

: w/path/to/somewhere# saves the full text to another file

: addr1,addr2w/path/to/somewhere# saves text content between ADDR1 to ADDR2 to another file


20. Fill the contents of another file in the current file (last-line mode)

: r/path/to/somefile# fills the contents of another file at the back of the current cursor


21. Interacting with the shell (last-line mode)

:! COMMAND


22. Advanced Topics

(1). Display or suppress line numbers

Display line numbers: Set NU or set number

To suppress line numbers: Set Nonu


(2). Ignore or differentiate character case

Ignore character case: Set IC or Set ignorecase

Case-sensitive: set Noic


(3). Auto Indent

Auto indent: Set AI or set autoindent

Cancel Auto indent: Set Noai


(4). Find text highlighting or canceling

Highlighting: Set Hlsearch

Suppress highlighting: Set Nohlsearch


(5). Syntax highlighting or canceling

Syntax highlighting: syntax on

Cancel syntax highlighting: syntax off


23. Configuration Files

Global VIM configuration file:/ETC/VIMRC

Personal VIM configuration file ~/.VIMRC

To save some vim settings, simply save the settings to one of the above two files based on the scope of the action.

Cases:

[[email protected] scripts]# echo "Set Nu" >> ~/.VIMRC # Displays line numbers and is only valid for the root user






This article is from the "Hello,linux" blog, make sure to keep this source http://soysauce93.blog.51cto.com/7589461/1715367

Vim Editor 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.