Linux-vim Learning Primer

Source: Internet
Author: User

  

1. Preface

Vi/vim is a very important text editor in Linux. The first time I used this editor, I was not used to even know how to move the cursor and insert characters.    After learning slowly, we know how to use Vi/vim. Vi/vim's role is to create, edit and display text files, in Vi/vim, without menus, only commands. 2. Common CommandsVim has three modes of operation: Command mode, insert mode, and edit mode. One enters Vim, the default is the command mode, that is, the input content, the system as a command. Automatically returns to command mode when the edit mode is finished. Here is a diagram showing the switching of these three modes: 2.1 Insert ModeAAppend text after the cursorAappend text at the end of our lineIInsert text before the cursorIstart inserting text at the bankOinsert a new line under the cursorOinsert a new line on the cursor 2.2 Positioning CommandsH, LEFT ArrowMove left one characterJ, the direction of the keyMove down one lineK, the direction of the keyMove up one lineL, RIGHT Arrowmove one character to the right$move to end of line0move to the beginning of the lineHmove to upper screenMmove to the center of the screenLmove to the bottom of the screen: Set NuSet line number: Set NonuCancel Line numberGG Gto the first lineTo the last line NGto Nth Row: Nto Nth Row 2.3 Delete commandXDelete the character at the cursor locationNxDelete the first n characters at the cursor locationDdDelete Row of cursor, NDD delete n rowsDgDelete the line of the cursor to the end of the fileDDelete content from the cursor to the end of the line: n1,n2dDelete a specified range of rows 2.4 Copy and cut commandsYY, YCopy the current rowNyy, NYcopy current row n rowsDdcut the current rowNddcut the following n rows of the current rowP, ppaste in the line or line of the current cursor note: In VI, the cut is deleted and then pasted 2.5 Replace and Cancel commandsRreplaces the character at which the cursor is locatedRto replace a character from where the cursor is, press ESC to endUCancel the previous action note: For example, change a single character, enter R first, and then enter the characters that need to be changed. For example, change the character A to B. This is suitable for use with minor modifications 2.6 Search and Replace commands /stringsearch forward for specified stringIgnore case when searching: Set IC Nsearches for the next occurrence of the specified string:%s/old/new/greplace the specified string with full text: n1,n2s/old/new/greplace the specified string within a certain range Note: n is from the go, and N is from behind.Set NOIC is case-sensitive: n1,n2s/old/new/c replace when asked whether to really replace the ZZ with: Wq function, all is to save the exit for ReadOnly file, if it is root or change the file owner, even if the file does not have write permission, use: wq! Also  Can save the file after the change. Save but do not exit: W Save as: W/root/file.bak 2.7 Other CommandsImport File: R file name executes the command in VI:! Command Definition shortcut: Map Shortcut Trigger Command example:: Map ^p i#<esc> Note: ^p is such input ctrl+v+v---^p:map ^b 0x continuous line comment: n         1,n2s/^/#/g Note: ^ Indicates the beginning of the line: n1,n2s/^#//g:n1,n2s/^/\/\//g replacement: AB huhuimail [email protected] Cancel AB command: Unan huhuimail:r!date Add command Execution results in VI shortcut key INSERT mailbox: Map ^e [email protected] 2.8 Modifying user vim settingsModify the user vim settings, such as the ability to permanently save the shortcut key VI ~/.VIMRC default this file is empty, and then you can write some shortcut keys attached: vi/vim operation keyboard diagram

Linux-vim Learning Primer

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.