Vi/vim command Overview & configuration file details

Source: Internet
Author: User
Some commands will still forget to find a record and save your time... By the way, you can customize the configuration.

Some commands will still forget to find a record and save your time... By the way, you can customize the configuration.
--!

1. vim # enter vim in the command line to enter the vim editor.
2. I # Press the I key and the INSERT command is displayed at the lower end. any character in vim may be used.
3. Esc # exit the I (insert) command for other commands
4.: r filename # read the content of a file and write it to the current editor.
5.: w newfilename # write the content in the editor to a new file.
6.: w # save the file during editing, which is equivalent to ctrl + s in word.
7 .:! Command temporarily leaves vi to display the result of executing command in command column mode! Example :! Ls # execute the shell command ls during editing
8.: sh # enter the shell command line. after the command is executed, ctrl + d exit and re-enter vim Edit. continue editing. under the shell command, run ctral + l to clear the screen.
9.: wq # save the file and exit
10. ZZ # save the file and exit. use the same command. Note the upper case.
11.: q! # Force exit, not save
12.: set number or: set nu # display the row number of the file in editing
13.: set nonumber or: set nonu # opposite to the previous command. no row number is displayed.
14.: help I # view the help of the insert command
15. u # undo the previous operation
16./Fedora # Find Fedora characters
17.: s/Fedora/Redhat # replace Fedora with Redhat (only in the row where the cursor is located)
18. dw # delete a word
Dd # delete a row
19. o # open a blank line
20. vim + filename # edit the last line of the file
21. vim + n filename # enter the nth line of the file for editing
22.: 1,. s/redhat/fedora #. indicates the current row, that is, the row where the cursor is located.
# Replace the redhat character that appears for the first time from 1st rows to the current row (.) with fedora
23.: 1,. s/redhat/fedora/g # replace all the redhat characters in the current row (.) with fedora, g
Global flag
24.: 1, $ s/redhat/fedora/g # $ indicates the last row
# Replace all the redhat characters from the first row to the last row with fedora
25.: % s/redhat/fedora/g # same command
26.: % s/\/fedora/g # replace all the redhat characters in the first row with fedora
# Words, not characters
27.: f # display file content, status, etc. # Same as ctrl + g commands
28.: e! # The current file is returned to the last saved file.
: E file # switch to edit file
29.: n # switch to the next file when editing multiple files (such as vim file1 file2), and
Combined use

VIM commands

The cursor control command moves the cursor h to move one character j to move one row k up one line l to move one character G to the last line of the file w to the beginning of the next word W to the next word, ignore the movement of punctuation B to the beginning of the previous word B to the beginning of the previous word, ignore punctuation L move to the last line of the screen M move to the middle line of the screen H move to the first line of the screen e move to the end of the next word E move to the end of the next word, ignore punctuation marks (move to the beginning of a sentence) move to the end of a sentence {move to the beginning of a paragraph} move to the beginning of a 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 in the current line I insert text in insert text before cursor I insert text before current row o insert new row under current row O insert new Row s delete character at cursor position above current row, and enter the insert mode S. Delete the row where the cursor is located and enter the 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 the command mode ^ v char. during insertion, the specified meaning of char is ignored, this is to insert special characters to delete text commands in vi delete operation x delete the character dw at the cursor delete to the beginning of the next word dG delete row, until the end of the file dd delete the entire row db delete the word before the cursor: n, md from row m delete n rows d, d $ delete from the cursor to the end of the row ^ h, when backspace is inserted, the previous character ^ w is deleted during insertion, delete previous words modify vi text the number before each command indicates the number of times this command is repeated command replace operation rchar replace current character R text escape replace current character with text until press Esc key stext use text to replace the current character S or cctext escape. Replace the entire line of cwtext escape and change the current word to textCtext escape. change the remaining lines to textcG escape and change ccursor_cmd text escape from the current position to the cursor command position to text search for and replace commands in vi/text search forward text in the file? Text searches for textn in the file and finds again in the same direction. N searches again in the opposite direction. ftext searches forward in the current row. textFtext searches backward in the current row. textttext searches forward in the current row. text, the cursor is located at the first character of the text, Ttext, to search for the text in the current line, and the cursor is located at the first character of the text: set ic search, case insensitive: set noic search is case sensitive: ranges/pat1/pat2/g replace oldtext: m with newtext, ns/oldtext/newtext in m rows through n, replace oldtext with newtext & repeat the final: s command: g/text1/s/text2/text3 to find the row containing text1, replace text2 with text3: g/text/command run the command in all lines containing text: v/tex T/command run the command in all lines that do not contain text in vi copy the text command copy operation yy put the content of the current row into the temporary buffer nyy put the content of n rows temporary buffer p put the text in the temporary buffer into the cursor after P put the text in the temporary buffer before the cursor "(a-z) nyy copies n rows and places them in the nameable buffer zone named parentheses. if n is omitted, it indicates the current row. "(a-z) ndd deletes n rows and places them in the nameable buffer zone named parentheses, omitting n indicates the current row "(a-z) p puts the content of the nameable buffer named parentheses after the current row" (a-z) p: put the content of the nameable buffer with parentheses into the current row. Undo and repeat the command in vi. undo the operation u undo the last modification U undo all the modifications of 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 (there is The number of deleted content, 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: set number display row: set nonumber cancels the status option of the number of lines vi :. = print the row number of the current row: = print the number of lines in the file ctrl + g display the file name, the current row number, the total number of lines of the file and the percentage of the file location: l use the letter "l" to display many special characters, such as tabs and line breaks. Tag option {insert in the first column {to define a paragraph [[return to the beginning of the paragraph] move forward to the beginning of the next paragraph m (a-z) use a letter to mark the current position. for example, use mz to Mark Z' (a-z) to move the cursor to the specified tag, for example, use 'Z to move to z to connect rows in vi option. J. connect the next row to the end of the current row. the next n rows are connected. the cursor is placed. the screen adjustment option is used. H. move the cursor to the screen. to move the cursor to line n M under the top line of the screen 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 line n on the bottom line of the screen ^ e (ctrl + e) roll down a row on the screen ctrl + y roll down a row on the screen ctrl + u roll up half page ctrl + d roll down half page ctrl + B roll up one page ctrl + f. roll down the screen. ctrl + l re-paint the 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. z. set The current row is set to the center nz of the screen. 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> to make n rows move one width to the right. for example, 3> move one width to the right of each row of the next three rows.
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.