Linux Study Notes _ 3_Vim/Vi usage tips

Source: Internet
Author: User

Vim Editor:

Vi is installed by default for all Linux/UNIX systems, and vim is installed by default for mainstream Linux systems.

Vim/Vi is a powerful full-screen text editor, the most common text editor on Linux/UNIX,

It is used to create, edit, and display text files.

Vim/Vi has no menu and only commands.

Official Website: www.vim.org

Vim is so cool: You can complete all operations without leaving the keyboard!

Vi working mode:

Frequently Used commands to improve the efficiency of Vi editing (without leaving the keyboard ):

1. Insert command:

Command function

A attaches text behind the cursor

A adds text at the end of the line

I insert before the cursor

I. Start inserting text in this row

O Insert a new row under the cursor

O Insert a new line to the cursor

2. Positioning command:

Command function

H shifts one character to the left

J. Move one row down

K move one row up

L move one character to the right

$ Move to the end of a row

0 move to the beginning of the row

H move to the top of the screen

M moves to the center of the screen

L move to the bottom of the screen

: Setnu: display the row number

: Setnonu cancel row number

Move gg to the first line

Move G to the last row

NG to n

: N to row n

3. delete command:

Command function

X: Delete the cursor character

Nx Delete n characters

DdDelete the row where the cursor is located and ndd Delete n rows

DG deletes all rows from the current row to the end of the file, including the current row

D. Delete the content from the cursor position to the end of the line.

: N1, n2d Delete n1 ~ N2 row

4. Copy the command:

Yy and Y copy the current row

Nyy, nY copy n rows

DdCut the current row. ndd cut the current row and the next n rows.

P paste under the current row

P paste on the current row

5. replace or cancel the command:

R replaces the character at the cursor

R replace the character from where the cursor is located and Press Esc to finish

U cancel the previous operation. First, you have not saved the file. The file is still in memory and has not been synchronized to the hard disk.

6. replacement or search commands:

/String: searches for the specified string backward. case-insensitive: setic is ignored during search. Cancel: setnoic.

N turning back

N forward from the back

: % S/old/new/g Replace the specified string in full text, and old is the keyword to be replaced.

: N1, n2s/old/new/g Replace the specified string within a certain range

: % S/old/new/g Replace the specified string in full text and ask

7. Save and exit:

ZZ: wq shortcut

: Wnew_filename save as the specified file

: Wq! Save the modification and exit (the file owner or root can ignore the read-only attribute of the file)

Instance tips:

1. Import files

: R file name

: Rissue

2. Run the command without exiting vi

:! Command

:! Ls-l/home/xiaofang

Extended: import the command execution result to the file!

: R! Date

3. Define shortcuts

: Map shortcut key trigger command

E.g.: map ^ p I # <ESC> // ^ P is typed by ctrl + p !!!

: Map ^ O 0x <ESC>

Appendix: Command Execution: ctrl + p, ctrl + o

Command canceled: unmap ^ P

4. Continuous Line comment

: N1, n2/^/#/g // Add # At the beginning of the row

Appendix: n1, n2/# // g // remove # From the row #

: N1, n2/^ # // g // remove the first # Number of the row in a row

: % S/^/\/g // Add a // symbol at the beginning of the line

: % S/\ ///g // remove the beginning of the line //

5. Replacement command

: Abmymail280441589@qq.com

// After mymail is entered, it will be replaced by the following content.

Unabmymail // cancel the definition of mymail

Appendix: edit the Vi configuration file

Vi configuration files are stored in ~ In the home directory, it is called. vimrc ~ /. Vimrc

[You can specify the location where your home directory is stored. By default, it is stored in the home directory]

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.