Common usage and settings for the VIM editor

Source: Internet
Author: User

First, the common editor:

Nano, Gedit, VI, Vim.

The difference between VI and VIM:

Vim is an enhanced version of VI.

Three, the principle:

When opened with an editor, it is opened in memory. After the save is written to the file.

Four, several modes:

    Command mode ——— > Insert mode ——— > Last-line mode (tail-line mode) 

  

1, Command mode: With Vim is opened after the command mode

Set NU Display line number

Set Nonu does not display line numbers

U rollback, return (cancel the previous action)

Ctrl+r forward

YY copy when moving forward

5yy copying 5 rows Starting from the current line

P Paste (after copying, you can move the cursor to another location to copy)

DD Delete When moving forward

5DD Delete 5 rows starting from the current line

R replaces the character at the current cursor position (r+ replaces the content)

X Delete the current cursor out of the character (5x--> from the current cursor to delete, delete 5 characters)

 

2. Insert mode:

I current cursor insertion

I Insert the bank at the beginning

A the next character of the current cursor is inserted

A Bank End Insert

o The next line of the current cursor is inserted

O Insert the previous line of the current cursor

ESC exits from insert mode to command mode

3, the last line mode:

How to enter the last line mode:

Way One: shift+:

  What you can do: Save exit, replace, locate, modify parameters, and modify the content again.

Save exit:

: W Save

: Q exit

:! Forced

: q! Forced exit does not save modified content

: wq! Force Save and exit

Replacement:s/the content to replace/replace the content/g (note that the previous ' s ' must not be leaked)

Replace our first: s/rhce/rhca/(The following principle is the same as this one)

Replace All of our: s/rhce/rhca/g

Replace 10-15 lines of content: 10,15s/rhce/rhca/g

Replace the contents from the current cursor to 15 lines:., 15s/rhce/rhca/g

‘.’ On behalf of the forward

' $ ' represents the last line

' $-1 ' represents the penultimate line

'% ' represents the full text

Replace full-text content:%s/rhce/rhca/g

Delete full-text RHCE:%s/rhce//g (do not preserve whitespace deletion)

:%s/rhce//g (leave space deleted, four spaces reserved)

 

Add comment (' # '): ' ^ ' represents the beginning of the bank

Full text add Comment:%s/^/#/g

Add a comment from the current cursor to the last line:., $s/^/#/g

Uncomment:%s/#//g (full-text uncomment)

Note: Sometimes a line has two #, you cannot use the method above, can be used:%s/^#//g or:%s/#//

Positioning:

: 10 cursor is positioned to line 10th

: $ cursor navigates to last row

   

Way two:/

function is to find

/rhce Find Rhce

Input parameters: N Find Next (↓)

N Find Previous (↑)

4, block selection:

Selection BLOCK: Ctrl + V

Copy block: Y

Paste Block: P

Delete Block: D

5, multi-File selection:          

Open three files vim xx yy zz

View a few files:

View the latter file: n

View Previous file: N

View First file:

View Final file: Last

6, the same file split screen operation:

: SP turns on split screen operation

Ctrl+w+w Choose which screen

Ctrl+w+↓

Ctrl+w+↑

:p Exit split Screen

7, the settings of the VIM environment (set up after the vim is not set to open)

CD ~ Switch to the user's home directory below:

Vim. VIMRC Open the VIMRC file without creating a

Set Nu Add line number

8, DOS non-Linux breaking characters

    

[Email protected] ~]# Dos2unix [-kn] file [NewFile]
[Email protected] ~]# Unix2dos [-kn] file [NewFile]

-K retains the original mtime time format for this file

-N preserves the original old file, outputting the converted content to the new file

Common usage and settings for the VIM editor

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.