In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the example analysis of commands, operations and keyboard shortcuts in Vim. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Vim is a well-known powerful and highly customizable text editor similar to Vi, which improves and adds many features to Vi. Vim is free software.
Command history
Commands that start with: and / have a history. You can first type: or / and then press the up and down arrows to select a history command.
Start vim
Enter the following command in the command line window to start vim directly to open vimvim filename to open vim and create a file named filename command to open a single file vim file and open multiple files vim file1 file2 file3. Open a new file in the vim window: open file opens the file in the new window: split file switches to the next file: bn switches to the previous file: bp views the list of currently open files, and the files currently being edited will be enclosed in []. : args opens remote files, such as ftp or share folder:e ftp://192.168.10.76/abc.txt:e\ qadrive est.txt
The mode of vim
Normal mode (press Esc or Ctrl+ [enter) lower left corner display file name or empty insert mode (press I key to enter) lower left corner display-INSERT-- visual mode (do not know how to enter) lower left corner display-VISUAL--
Navigation command
% parenthesis match
Insert command
I insert at current position I insert an at the beginning of the current line insert an at the current position insert an at the end of the current line insert a row after the current row O insert a row before the current row
Find command
/ text look for text, press n to find the next one, and press N key to find the previous one. ? text to find text, reverse search, press n health check to find the next, press N key to find the previous one. There are some special characters in vim that need to be escaped when looking. * [] ^% /? ~ $: set ignorecase ignores case search: set noignorecase does not ignore case search to find very long words, if a word is very long, you can move the cursor to the word, press * or # key to search for the word, which is equivalent to / search. And the # command is equivalent to? Search. Set hlsearch highlights search results, all results are highlighted instead of just one match : set nohlsearch turns off highlight search: nohlsearch turns off the current highlight, and if you search again or press the n or N key, it will highlight again. The set incsearch step-by-step search mode searches the currently typed characters without having to wait for typing to complete : set wrapscan search again. When the search reaches the beginning or end of the file, return to continue the search. Default is enabled.
Replace command
Ra replaces the current character with a, which is the character in which the cursor is located. S/old/new/ replaces new with old, the first matching s/old/new/g of the current line replaces new with old, all matching% s/old/new/ of the current line replaces new with old, the first matching% s/old/new/g of all lines replaces new with old, replacing all matches of the entire file: 10meme20 s / ^ / g adds four spaces before each line 20 of line 10 for indentation. Ddp swaps the line where the cursor is located and the line immediately below it.
Move command
H moves one character to the left l moves one character to the right. This command is rarely used and is usually replaced by w. K move up one character j move down one character more than four commands can be used with numbers, for example, 20j is to move down 20 lines, 5h is to move 5 characters to the left, in Vim, many commands can be used with numbers, such as delete 10 characters 10x, insert 3 after the current position! , 3a! The Esc here is required, otherwise the order will not take effect. W move forward one word (the cursor stops at the beginning of the word), or if you have reached the end of the line, go to the beginning of the next line. This command is fast and can replace the l command. B move back one word 2b move back two words e, same w, but the cursor stops at the end of the word ge, the same as b, the cursor stops at the end of the word. Move ^ to the first non-white space character on the line. 0 (the number 0) moves to the first character of the line, to the first character of the line. Same as 0 Jian. Move to the end of the line 3$ move to the end of the line below 3 lines gg move to the head of the file. [[G (shift + g)) moves to the end of the file. The f (find) command can also be used to move, fx will find the first character x after the cursor, and 3fd will find the third character d. F is the same as f, reverse search. Jump to the specified line, colon + line number, enter, for example, jump to line 240: 240 enter. Another method is line number + G, such as 230g jumping to 230 lines. Ctrl + e scroll down one line Ctrl + y scroll up one line Ctrl + d scroll down half screen Ctrl + u scroll half screen Ctrl + f scroll down one screen Ctrl + b scroll up one screen
Undo and redo
U undo (Undo) U undo the operation Ctrl + r redo (Redo) on the entire row, that is, the revocation of the undo.
Delete command
X Delete the current character 3x Delete the current cursor begins to delete the previous character of the current character to the last three characters X. X=dhdl deletes the current character, dl=xdh deletes the previous character dd deletes the current line dj deletes the previous line dk deletes the next line 10d deletes the first 10 lines of the current line. D deletes the current character to the end of the line. All characters after deleting the current character (this line) kdgg deletes all lines before the current line (excluding the current line) jdG (jd shift + g) deletes the current line all lines (excluding the current line): 1Min 10d deletes 1-10 lines: 11grad deletes 11 lines and all subsequent lines: 1Zero deletes all lines J (shift + j) deletes the blank line between two lines, in fact merges two lines.
Copy and paste
Yy copy the current line nyy copy starts before and after the n lines, such as 2yy copy the current line and its next line. P paste behind the current cursor, and if you previously used the yy command to copy a line, paste it on the next line of the current line. Shift+p pastes before the current line: 110 co 20 inserts lines 1-10 after line 20. : 1 co $copy the whole file and add it to the end of the file. In normal mode, press v (verbatim) or V (line by line) to enter visual mode, then use the jklh command to move to select certain lines or characters, and then press y to copy ddp to swap the current line and its next line xp to swap the current character and the next character
Cut command
Press v (verbatim) or V (line by line) in normal mode to enter visual mode, then use the jklh command to move to select certain lines or characters, and then press d to cut the n lines after the current line is cut by ndd. The content of the cut can be pasted with the p command: 1 cut 1-10 lines in 10 days. The cut content can be pasted with the p command. : 1, 10 m 20 move lines 1-10 after line 20.
Exit command
Wq save and exit ZZ save and exit: Q! Force exit and ignore all changes: e! Discard all changes and open the original file.
Window command
Split or new opens a new window with the cursor over the top window: split file or: new file opens the file with a new window. Split opens a window horizontally, and you can open it vertically with vsplit. Ctrl+ww moves to the next window Ctrl+wj moves to the lower window Ctrl+wk moves to the upper window
Close the window
This command cannot be used in the last window of close to prevent accidental exit from vim. : Q if it is the last window that is closed, it exits vim. ZZ saves and exits. Close all windows, leaving only the current window: only
Recording Macro
Press Q key plus any letter to start recording, and then press Q key to end recording (which means that macros in vim cannot be nested). Use @ plus macro name, such as qa. Q records a macro called a, which @ a uses. Https://www.linuxprobe.com/vim-shortcut-key.html
Execute the shell command
:! command script.pl lists the files in the current directory:! perl-c script.pl checks the syntax of the perl script so that you don't have to exit vim, which is very convenient. :! perl script.pl executes the perl script without having to quit vim, which is very convenient. : suspend or Ctrl-Z suspend vim, return to shell, press fg to return vim.
Comment command capacity
The behavior comment at the beginning of # in the perl program, so to comment on some lines, just add the comment # 3-5 at the beginning of the line 3-5 line 3-5 / ^ # / g release the comment 1 of line 3-5. :% s / ^ / # / g comments the entire document, which is faster.
Help command
: help or F1 shows the entire help: help xxx displays xxx's help, such as: help I,: help CTRL- [(that is, Ctrl+ 's help). : the help of the help 'number' Vim option is enclosed in single quotes: the help of the help special key is expanded with the help of the help-t Vim startup parameters -: help I _ insert the help of Esc in the mode, the help in a certain mode is located in the mode help file of the mode _ topic | | the content between them is a hyperlink, which can be accessed using Ctrl+] and returned by Ctrl+o (Ctrl+ t).
Other non-editing commands
. Repeat the previous command: set ruler? to see if ruler is set. In .vimrc, options set with the set command can be viewed through this command: scriptnames to view the location of vim script files, such as .vimrc files, syntax files and plugin. Set list displays non-print characters, such as tab, space, end of line, etc. If tab cannot be displayed, be sure to set the .vimrc file with the set lcs=tab: >-command, and make sure that you do have tab in your file. If expendtab is turned on, tab will be expanded to spaces.
Vim tutorial
On Unix system $vimtutor on Windows system: help tutor:syntax lists defined grammar items: syntax clear clears defined grammar rules: syntax case match is case-sensitive, int and Int will be treated as different syntax elements: syntax case ignore is case-independent, int and Int will be treated as the same syntax elements, and using the same color scheme on "sample analysis of commands, actions and shortcuts in Vim" ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.