LinuxVIM basic commands

Source: Internet
Author: User

LinuxVIM basic commands

Run the linux VIM command: vim in the command line and enter the vim editor Esc to exit the I (insert) command. Run the command sh to enter the shell command line, after the command is executed, ctrl + d and exit and re-enter vim edit. Continue to edit the command in shell. Run ctral + l to clear the screen: set number or: set nu to display the row number of the edited file: set nonumber or: set nonu is the opposite of the previous command. No line number is displayed: help I. view the help/Fedora command for Fedora characters: s/Fedora/Redhat replace Fedora with Redhat (only in the row where the cursor is located) vim + filename: Edit vim + n filename in the last line of the file to enter the nth line of the file for editing: 1 ,. s/redhat/fedora. number indicates the current row, that is, the row where the cursor is located # Move the row 1st to the current row (.) the first occurrence of the redhat character is replaced by fedora: 1,. S/redhat/fedora/g will be 1st rows to the current row (.) replace all the redhat characters with fedora, g Global flag: 1, $ s/redhat/fedora/g $ indicates the last line # replace all the redhat characters from row 1st to the last line with the same command: fedora: % s/redhat/fedora/g: % s/\/fedora/g replace all the redhat characters in the last line of the row with the fedora # character, instead of the character: f # Shows the file content, status and so on # The Same As ctrl + g command cursor control command cursor move h move to the left one character j move down one line k move up one line l move one character gg or to the right: 1. Move G from the first line of the file to w from the last line of the file to the beginning of the next word and move W to the beginning of the next word, ignore punctuation e move to the end of the next word E move to the end of the next word, ignore punctuation B move to the beginning of the previous word B move to the beginning of the previous word, ignore punctuation L move to the last line of the screen M move to the center of the screen The first line (beginning of the sentence) of the row H to move to the end of the sentence {beginning of the paragraph} to the beginning of the next paragraph 0 (number ), | move to the first column of the current row ^ move to the first non-null character of the current row $ move to the last character of the current row +, enter move to the first character of the next line-Move to the first non-empty character of the previous line add text command in vi insert action a insert text after cursor A insert text at the end of the current line I insert text in front of the cursor I insert text in front of the current Row o Insert a new row under the current Row O Insert a new row s Delete the character at the cursor, and enter insert mode S to delete the row where the cursor is located, and enter insert mode: r file reads the file content, and inserts it into the current row: nr file reads the file content, after inserting the nth line, Esc returns to command mode: delete a text command in vi delete operation x Delete the character dw at the cursor Delete to the beginning of the next word dG Delete the cursor line, until the end of the file dd Delete the entire row ndd Delete n rows of db under the cursor Delete the word before the cursor: n, md Delete n rows to m rows d, d $ delete from the cursor to the end of the line d, d ^ Delete from cursor to line first modify vi text the number before each command indicates the number of times this command is repeated command replace operation rchar Replace current with char character R text escape uses text to replace the current character until Press Esc key stext escape uses text to replace the current character S or cctext escape uses text to replace the entire line cwtext escape and changes the current word to textCtext escape to replace the current line change the remaining content to textcG escape and change it to the end of the file. Search for and replace the command in vi. Search for and replace the operation/text in the file. Search for text in the file? Text searches backward in the file. textn searches repeatedly in the same direction. N searches repeatedly in the opposite direction. case-insensitive for set ic searches: case-sensitive for set noic searches: ranges/pat1/pat2/g replace oldtext: m with newtext, ns/oldtext/newtext with n in line m, replace oldtext with newtext & repeat the last: s command: g/text1/s/text2/text3 search for rows containing text1 and replace text2: g/text/command with text3 to run the command in all rows containing text: v/text/command in all rows that do not contain text run the command expressed by command in vi copy the text command copy operation yy put the content of the current row into the temporary buffer nyy will n rows content into the temporary buffer p put the text in the temporary buffer into the cursor P will be temporary Buffer text placed before the cursor np put the text in the temporary buffer into the cursor n times nP put the text in the temporary buffer into the cursor n times in vi undo and Repeat command Undo operation u undo previous operation U undo all modifications to the current row. repeat the last modification and repeat the previous f, F, t, or T search command in the opposite direction; repeat the previous f, F, t, or t search Command "np retrieves the last n deletions (the buffer contains a certain number of deletions, usually 9) n repeats the previous/or? Search for command N to repeat the previous/or? Command to save the text and exit vi command to save and/or exit Operation: w save the file but do not exit vi: w file Save the changes in file but do not exit vi: wq or ZZ or: x save the file and exit vi: q! Do not save the file. Exit vi: e! Discard all modifications and edit the option in vi from the last time the file is saved. function: set all print all options: set nooption disable option: set nu print row number before each row: set showmode: whether to display the input mode or the replacement mode: set autoindent inherits the indent mode of the previous line, especially for multi-line notes: set smartindent provides automatic indent for C Programs: set list display tab (^ I) and line tail Symbol: set ts = 8 for text input set tab stops: set window = n set text window display n rows vi status option function ctrl + g display file name, current row number, total number of lines of the file and the percentage of the file location: l use the letter "l" to display many special characters, for example, tabs and line breaks are used to locate paragraphs and place tag options in the text. {insert in the first column. {define a paragraph [[back to the beginning of a paragraph] Move Forward to the beginning of the next paragraph. In vi zhonglian Line Selection option Action J connects the next line to the end of the current line, nJ connects the next n rows, the cursor is placed with the screen adjustment option action H move the cursor to the top line of the screen nH move the cursor to the top line of the screen line n M move the cursor to the center of the screen L move the cursor to the bottom line of the screen nL move the cursor to the nth line on the bottom line of the screen ctrl + e roll down the next line of the screen ctrl + u roll up half page ctrl + d roll down half page ctrl + B roll up one page ctrl + f roll down one page ctrl + l re-paint screen z- return: set the current row to the top line of the screen. nz-return: Set the nth row under the current row to the top line of the screen. set the current row to the center of the screen nz. set row n on the current row to the center of the screen z-set the current row to the bottom line nz-set row n on the current row to the bottom line of the screen role of the shell escape Command Option in vi :! Command :! Ls :!! Run the previous shell command: r! The command reads the input of the command and inserts it, for example, r! Ls will first execute ls and then read the content: w! Command uses the edited file as the standard input of the command and executes the command, for example, w! Grep all: cd directory change the current working directory to the directory indicated by directory: sh starts a sub-shell and returns vi using ^ d (ctrl + d: so file read and execute the macros and abbreviations in command vi in shell program file (avoid using control keys and symbols, do not use the K, V, g, q, v, *, =, and function keys.) function: map key command_seq defines a key to run command_seq, such as map e ea, at any time, you can move e to the end of a word to append text: map displays all the defined Macros in the status line: umap key to delete the key macro: AB string1 string2 defines an abbreviation to replace string1 with string2 when string1 is inserted. When you want to insert text, type string1 and Press Esc. Then the system inserts string2: AB to display all abbreviations: una string cancels the abbreviation of string. In vi, the indent text option is used to insert the moving width when ctrl + I or tab is inserted. The moving width is defined in advance: set ai Enable Automatic indent: set sw = n set the moving width to n characters n> make n rows move one width to the right, for example, 3> move each row of the next three rows to the right to move the width. If n is omitted, the current row is shifted to the right. To facilitate Text Selection, VIM introduces the Visual mode. To select a text segment, first move the cursor to the beginning of the segment, press v in normal mode to enter the visible mode, and then move the cursor to the selected content at the end of the segment (move to the beginning of the line ^, end of the line $ ). Note that the character of the cursor is included in the selection area. In this case, you can perform some operations on the selected text. Common (visual mode) Commands include: x or d cut (that is, delete the selected text and enter the clipboard) y replace all characters of the r character with the new u ~ All letters are written in lower case, written in upper case, and reversed case. After the command is input, VIM returns to the normal mode and can be pasted by p or P. Command for copying and pasting in Normal Mode: v enters the visual mode p or P to paste the clipboard content at the current position, p sticks to the character behind the cursor, P sticks to the front and has to admit, although the visual mode is introduced, copying and pasting in VIM is still troublesome, which may be the only drawback of VIM. In addition, VIM introduces the Select mode, which is similar to the visual mode. Combine key definitions and option settings.

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.