Linux text editor Vim/Vi details, vimvi

Source: Internet
Author: User
Tags linux text editor

Linux text editor Vim/Vi details, vimvi

Ii. Text Editor Vim/Vi (later called the upgraded version of Vi) Vim/vi is a powerful full-screen text editor and the most common text editor on linux/unix, it is used to create, edit, and display text files. Vim/vi has no menu, only commands ---- official: www.vim.org three modes: vi filename command mode press I, a, o insert mode: set nu edit mode (set row number, this is the common commands in the editing mode, starting with ":"): A group: INSERT 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 on the cursor new row group 2: locate Command commands h. Move one character j to the left, move one row k to the bottom key, move one row l to the top key, and move one character to the right by right. $ move to the end of the line 0 to the beginning of the line (0 letters) H move to the top of the 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 line G to the last line nG to the n line: n to line n group 3: delete command function x Delete the character nx at the cursor position Delete the n character dd At the cursor location Delete the row where the cursor is located, ndd Delete Delete the content from the row where the cursor is located to the end in addition to n rows of dG D Delete from where the cursor is located to the end of the line: n1, n2d Delete the specified range of rows such as: 66, 67d -- Delete lines 66-67: Copy and cut command to copy the current row nyy, Y to copy the following n rows of the current row --- 5yy (copy 5 rows including the current row) dd cut the current row ndd cut the following n rows of the current row p, P paste under the current cursor row (p) or row (P) five groups: replace and cancel commands Replace the character r at the cursor position with the character R starting from the cursor position, and Press Esc to end u to cancel the previous step 6: search and replace command function/string forward search for the specified string, the search is case-insensitive: set ic (the ceil is executed before the search is case-insensitive) -- set noic off --- For example: in/leyangjun command mode, search for the next occurrence location of the specified string by n in sequence (lowercase n is searched from the front to the back, and uppercase n is searched from the back to the back): % s/old /New/g full-text replacement specified string (% s indicates full-text replacement) for example: % s/ftp/leyangjun/g replace all full-text ftp with leyangjun, g indicates that you do not need to confirm the replacement: n1, n2s/old/new/g in a certain range to replace the specified string, for example: 4,10/leyangjun/ftp/g replace all the lines 4-10 with ftp4, 10/leyangjun/ftp/c. You need to confirm to save and exit :----: wq is equivalent to shift + ZZ forcibly saving and exiting: wq! (Only the file owner/root can operate) Save as: w/root/service. bak save as root directory application example: Import file content: r file name (when you edit file a, you can import file B content into file a) for example :: r/etc/leyangjun: import the leyangjun file to the content of the currently edited file. Run the following command in vi :! Command example: I am editing a file but want to view the content of a file now :! Ls/root --> If yes, you will be prompted to press enter to return. For example, you can import the result of a command execution to a file in combination with the preceding import: r! Date ---- import the date to the file I am editing now and define the shortcut key: map shortcut key trigger command example :: map ^ p I # <ESC> ^ indicates a shortcut key. Note that you must use ctrl + v + p to obtain ^ pI # To insert a # number. (I indicates entering the insertion mode ): map ^ E iyangjun518@163.com (press ctrl + v + E, with a letter I) the shortcut key for inserting the mailbox defined to cancel: unmap ^ P (ctrl + v + p) continuous Line comment: n1, n2s/^/#/g (/^ indicates the beginning of the line) Example: s/^/#/g (4-8 rows plus # comment out ): n1, n2s/^/# // g example: 4, 8 s/^/# // g (remove 4-8 rows #) to replace it with NULL: n1, n2s/^/\/g example: 4, 8 s/^/\/g (remove the annotation symbol of 4-8 rows/) (we recommend that you use AB, more convenient than shortcuts): AB mymail leyangjun518@163.com (The AB command can be interpreted as replacing a with B.) After setting, you can return to your current edited text: Enter myemail --> press ENTER or enter a space, you will find that the leyangjun518@163.com with the unab myemail (cancel the definition of AB) vi configuration key: Change the vi configuration file (after modification next open the file will follow the configuration file ):~ Home ctor go to the main directory of the tree (for example,/home/leyangjun )~ /. Vimrc each user has his own vim configuration file. The actual operation is null by default. 1: vi/root/. vimrc or vi ~ /. Vimrc 2: Edit set nu (the row number will be displayed next time each file is opened) AB lyj leyangjun

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.