e !: Return to the last saved state cw: Modify the word (automatically enter the insert mode) cc: Modify the content of a whole line cs: Modify a word (automatically enter the insert mode).: You can repeat the previous command J: will The next line is merged to the end of the line, and spaces are automatically added.
EX Command The logic of the EX command is to apply the command to the specified address. Some commands only have the source address parameter, and some commands have the destination address parameter. EX command: d: delete line m: move line (with destination address) t / co: copy line (with destination address) p: print line nu: display line number w: save line #: display line number
The EX method of positioning the line is absolute: a. "." Means the current line, which is the default value, or the default line if no display is specified (equivalent to a ".") B. "$" The last line c. "0" Before the first line, d. "Num", line num, e. / Pattern / Pattern matching occurs in the first relative line: a. [An absolute line number] + [num] if there is no "absolute line number", then For the current line, it is 1 if there is no num, and the num line b after the absolute line. [An absolute line number]-[num] If there is no "absolute line number", it is relative to the current line, or 1 if there is no num. The relative address and absolute address combination in the num line before the absolute line constitutes a variety of addresses and address ranges. For example, the command:: 1,20 s / awk / sed / g: / ^ luo /, / ^ lcm / s / awk / sed / g Replace all lines starting with "luo" to "lcm": g / ^ luo / s / awk / sed / g Replace all lines starting with luo : =-> List the total number of lines:. =-> List the current line: / pattern / =-> List the line number of the first match Sometimes, I hope that the subsequent address is offset from the address of the previous match. Use a semicolon to represent the address separator, for example: (current cursor is on line 120), then 100, +20 means the range of 100,140 lines and 100; +20 means 100,120 access
g means all matching in the positioning range, g! instead. If there is no g, it is the first time. You can use ‘|’ to combine multiple commands. Subsequent commands act on the results of the previous order. The difference between the ": x" and ": wq" commands is that the former writes only when the file is changed, while the latter writes unconditionally. : w file_name-> saveas file_name-> Save as: range w file_name-> save the contents of the range to a new file: w >> file_name-> append the contents of the current file to the new file: address r file_name-> save the file Read multiple files under the address of the current file. Add multiple file names as parameters in the command line to open multiple files. The view is on the first file. Use the command ": ar [gs]" to view the list of open files. The file names included by "[]" are really edited files. Use: n, ctrl + ^ to switch files. "Rew" switches to the first file "last" switches to the last file. : e!-> Load the last saved file%: Represents the current file name #: Represents the name of the alternate file When loading a new file with the ": e" command, the contents of the named buffer are not cleared. : ya-> drag content into buffer: pu-> copy content from buffer to file.
: g / pattern / s / old / new / g: do the replacement operation on the lines that satisfy the pattern local). : g / pattern / s // new / g Replace the content of the matched line with "//" after new s to indicate the special character meaning in the previously matched content replacement string (new) \ n: Represents capture &: Represent Matching string ~: Represents the string used for the last replacement \ u: Changes the following character to uppercase \ U: Changes the following character to uppercase \ l: Changes the character after to lowercase \ L: Make the following string lowercase &: Repeat the last replacement operation
Option settings 1.vi first reads the configuration information of the current terminal from the terminfo database 2.vi Before executing it, first execute the command in the environment variable EXINIT, and then the command in the ".exrc" file in the home directory. 3. The ": set" command supports two types of option settings: a.: Set option / set nooption (turn an option on or off) b.: Set option = number or string 4. ": Set all" shows the current status of all options Setting value ": set" displays special setting value ": set option?" View the current setting value of an option.
.exrc file 1. Commands in .exrc do not need to be preceded by a ":" sign. 2. For the local .exrc file to take effect, you need to set the command "set exrc" in .exrc in your home directory. 3. You can write the command to any other file, and then use the command ": so file name" to set the file in vi Effective. Use unix command 1.:!: Generate a sub sh followed by the command 2.: sh Open a shell to execute the command continuously, ctrl + d returns vim 3.: [linenum] r! Command Insert the command result into linenum
4.: [linenum] r file Read the contents of the file into linenum // Use the contents of the file as the input of the command, and the output of the command will overwrite the current content of the file 5.: [linenum1, linenum2]! Cmd 6. vi's You do not need a colon [replay times]! [Text line range positioning command] unix command 7. You can set the abbreviation in vi (enter the abbreviation in insert mode and it will be completed when you press a non-letter key): ab View all currently defined Abbreviation: ab lcm luo cai min // Set "luo cai min" to the abbreviated string lcm: unab lcm Cancel the abbreviation 8. Set the command abbreviation: map shortcmd cmd cmd cmd // The function keys appearing in the command need to press ctrl + first v Then enter map rd: r! date + '\% Y \% m \% d' <CR> ^ ywI / * luocaimin delete begin <Esc> A * / <CR> #if 0 <CR> #else <CR > #endif <CR> <Esc> pI / * luocaimin delete end <Esc> A * / <CR> map ra: r! date + '\% Y \% m \% d' <CR> ^ ywI / * luocaimin add begin <Esc> A * / <CR> <Esc> pI / * luocaimin add end <Esc> A * / <CR> map rae: r! date + '\% Y \% m \% d' <CR> I / * luocaimin add end <Esc> A * / <CR>
map rab: r! date + ‘\% Y \% m \% d’ <CR> I / * luocaimin add begin <Esc> A * / <CR>
map ra: r! date + '\% Y \% m \% d' <CR> ^ ywI / * luocaimin add begin <Esc> A * / <CR> <Esc> pI / * luocaimin add end <Esc> A * / <CR>
map rd: r! date + '\% Y \% m \% d' <CR> ^ ywI / * luocaimin delete begin <Esc> A * / <CR> #if 0 <CR> #else <CR> #endif <CR> <Esc> pI / * luocaimin delete end <Esc> A * / <CR> "Find the sum of the formulas represented by the current row map lsum yyp:.! Bc <CR> I <CH> i = <Esc> in Enter insertion mode at the end of the word: map e ea reverse two words: map K dwwp save a file and go to the next file: map q: w ^ M: n ^ M Annotation code: map rmk I / * ^ [A * / ^ [9. Need to insert an insert value as a command in insert mode, you need to add it after map! Eg: xml tag auto-completion: map!>> ^ [F <lyf> f> a <\ ^ [p 10 Enter the command string in edit mode, then read the command cache (by deleting the command "gdd" to read the command into the named cache g), and execute the command with "@naming cache". "@" Will be interpreted as vi command "@@" or "." Can be used to repeat the command. 11. Automatic indentation: ": set autoindent" is used to make the new line have the same indentation as the previous line. When entering code under automatic indentation (insert mode), the next level of indentation is performed at the beginning of the line, "ctrl t", and "ctrl d" is the opposite.
"5 <<" indents the following 5 lines to the left by 8 characters including the current line "5 >>" instead: set tabstop = 4 sets the width of the tab to 4 characters 12: ": set list" Show hidden characters for the entire file. ": l" shows the hidden characters of the current line 13: "%" If it is not on the parenthesis character ‘{([])}’, it moves to the first parenthesis found on this line. 14: ": set showmatch" highlights the matching parentheses when entering parentheses. 15: ctags 15.1 ctags -R Iteratively searches source files from the current directory and creates tags files. 15.2 ": set tags = tags file" Specify the tags file 15.3 ": tag GET_BALANCE" Find and jump to the file and location where GET_BALANCE is located, ": stag tagname" displays the symbol in a horizontal screen and pagination 15.4 Place the cursor over the symbol, ctrl +] jump to the file and position where the symbol is located, ctrl + w +] display the symbol in a horizontal screen pagination 15.5 ctrl + t return to the position before the jump 15.6 ": stag [!] tagname" new window opens tab 16: ' * 'Highlight the word under the cursor and enter search mode,' # 'Highlight the word under the cursor and enter reverse search mode. 17: Select a word in 'viw' visual mode 18. Automatically add tags (automatically update tags files when the file changes) autocmd BufWritePost * .cpp, *. C, *. H:! Cur_dir = `pwd` && cd ~ && ctags -a%: p && cd-Note%: p represents the current file name with path 19. Selected area in visual mode 19.1 "niw": Select the n words under and after the cursor, punctuation and Null characters are counted as one word 19.2 "niW": Select the n words under and behind the cursor, and spaces count as one word 19.3 "naw": Select n words under and after the cursor, punctuate as one word, and space as separator 19.4 "naW": Select n words under and after the cursor, punctuation is not counted
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.