Linux study Notes-vi/vim editor command quick start

Source: Internet
Author: User
Linux Study Notes & mdash; vivim editor command Quick Start 1 preface vivim is an important text editor in linux. When I used this editor for the first time, I was not used to knowing how to move the cursor and insert characters. I learned how to use vivim. Linux study Notes-vi/vim editor command quick start
1. Preface vi/vim is an important text editor in linux. When I used this editor for the first time, I was not used to knowing how to move the cursor and insert characters. I learned how to use vi/vim. Vi/vim is used to create, edit, and display text files. in vi/vim, there are no menus and only commands. Let's talk about the differences between vi and vim: in simple terms, they are all multi-mode editors. The difference is that vim is an upgraded version of vi. vim is not only compatible with all instructions of vi, some new features are introduced. ① the direction keys in vi do not support the direction keys. ② multi-level revocation is in vi. pressing u can only undo the last command, but can undo it without restriction in vim. ③ Ease-of-use vi can only run in unix, while vim can run on not only unix, but also windows, mac, and other multi-operating platforms. ④ Syntax highlighting vim can highlight your code in different colors. ⑤ Visualized vim operations can not only run on the terminal, but also on windows and mac OS. 6. fully compatible with vi. in some cases, vim can be used as vi. 2. common command vi has three working modes: command mode, insert mode, and edit mode. Once you enter vi, the default mode is the command mode, that is, the input content, and the system treats it as a command. After the editing mode is executed, the system automatically returns to the command mode. The following figure shows the switching of the three modes: 2.1 insert mode command function a append text after the cursor A append text at the end of the line I insert text before the cursor I insert text at the beginning of the line o insert new lines under the cursor O insert new lines on the cursor insert New Line 2.2 positioning command function h. move left to one character j, move down one line k, move up one line l, right to move one character $ move to the end of the line 0 move H to the top of the screen to move M to the center of the screen L to the bottom of the screen: set nu sets the row number: set nonu cancels the line number ggG to the first line to the last line nG to the n line: line n to line n 2.3 Delete command function x delete the character nx where the cursor is located delete the n character dd after the cursor is located delete the row where the cursor is located, ndd delete n rows dG delete content from the row where the cursor is located to the end of the file D delete content from the cursor position to the end of the line: n1, n2d deletes the row 2.4 Copy and cut command in the specified range. run the command yy and Y to copy the current row nyy and nY to copy the current row. run the command n lines dd to cut the current row ndd. Cut the following n rows of p and P in the current row and paste them to the bottom or row of the current cursor. note: In vi, cut is to delete and then paste 2.5 replace and cancel command action r replace the character where the cursor is located R replace the character from where the cursor is located start replace the character, press Esc end u cancel the previous operation note: for example, to change a single character, enter r first and then the character to be changed. For example, change character a to character B. This method is suitable for using the 2.6 search and replacement command when a few modifications are made./The Case sensitivity is ignored when the string is searched for the specified string forward: set icn searches for the next occurrence location of the specified string: % s/old/new/g full-text replacement of the specified string: n1, n2s/old/new/g in a certain range to replace the specified string. note: n is from front to back, N is from the back to find the set noic is set case sensitivity: n1, n2s/old/new/c replacement, ask whether to really replace ZZ with: wq, all are saved and exited. for readonly files, if it is root or the file owner, even if the file has no write permission, use: wq! You can also save the modified files. Save only but do not exit: w save as: w/root/file. bak 2.7 Other commands Import file: r file name in vi execute command :! Command definition shortcut key: map shortcut key trigger command example: map ^ p I # Note: ^ p is the input ctrl + v --> ^ p: map ^ B 0x continuous line comment: n1, n2s/^/#/g note: ^ indicates the beginning of the line: n1, n2s/^ # // g: n1, n2s/^ // \ ///g replace: AB huimail huhuics@gmail.com cancel AB Command: unan huimail: r! Date add command execution result shortcut in vi insert mailbox: map ^ e ihuhuics@gmail.com 2.8 modify User vim settings, such as permanent save shortcut vi ~ /. Vimrc by default, this file is empty, and some shortcut keys can be written. attachment: vi/vim operation keyboard diagram

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.