[Linux Learning Notes] Linux Text editor Vim/vi

Source: Internet
Author: User
Tags save file linux text editor

Text editor Vim:

Vim/vi is a powerful full-screen text editor that is the most commonly used text editor on Linux/unix. Its role is to create, edit, display text files.

Vim/vi no menus, only commands.

Insert Command
Command Role
A Append text after the cursor
A Append text at the end of our line
I Insert text before the cursor
I Start inserting text at the bank
O Insert a new line under the cursor
O Insert a new line on the cursor
position Command
Command Role
H Left ARROW key. Move left one character
J The direction key. Move down one line
K The key in the direction. Move up one line
L Right ARROW. Move one character to the right
$ Move to end of line
0 Move to the beginning of the line
H Move to upper Screen
M Move to the center of the screen
L Move to the bottom of the screen
: Set Nu Set line number
: Set Nonu Cancel line number
Gg To the first row
G To the last line
NG to Nth row
: N to Nth row
Delete command
Command Role
X Delete the character at the cursor location
Nx Delete the first n characters at the cursor location
Dd Delete Row of cursor, NDD delete n rows
Dg Delete the contents of the line to the end of the cursor
D Delete from the cursor to the end of the line
: N1, n2d Delete a specified range of rows
copy and cut commands
Command Role
YY, Y Copy when moving forward
Nyy, NY Copy the following n rows of the current row
Dd Cut when moving forward
Ndd Cut the following n rows of the current row
P, p Paste at current cursor sitting under line or row
Replace and Cancel commands
Command Role
R Replaces the character at which the cursor is located
R To replace a character from where the cursor is, press ESC to end
U Cancel the previous action
Search and Replace commands
Command Role
/string Searches forward for the specified string, ignoring case when searching: Set IC
N Searches for the next occurrence of the specified string
:%s/old/new/g Replace the specified string with full text
: n1,n2s/old/new/g Replace a specified string within a certain range

Application Tips

Import file: R [FileName]

Execute the command in VIM:! Command

Define shortcut keys: map [shortcut] [trigger command]

Example:

: Map ^p i#what<esc> Description: Press ctrl+p, insert "#What" at the beginning of the line, and return to command mode when the insert is complete. Note: Use Ctrl + V, ctrl+p input ^p

Continuous line Comment: n1,n2s/^/#/g (^ Indicates the beginning of a row, with a # comment before the beginning of the header )

N1,n2s/^#//g (Remove the # comment at the beginning of the line)

N1,n2s/^/\/\//g (add "//" before the beginning of the line)

Replacement:: AB MyBlog LvSantorini.oschina.net (cancellation with Unab)

Note: The various shortcut keys that are set when you vim a file are only available for this edit file, and editing again after exiting will no longer work. If you want to use these shortcuts permanently, you need to edit the. VIMRC configuration file in the host directory to save all the shortcuts you need to use

Example:

[Email protected] ~]$ VI ~/.VIMRC

Shortcut keys:

: Wq and Shift+zz

: wq! If the file is read-only, only the file owner and root user can force modification of the save file.

[Linux Learning Notes] Linux Text editor Vim/vi

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.