Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands, operation methods and shortcut keys of Vim

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the commands, operation methods and shortcut keys of Vim". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "what are the commands, operation methods and shortcut keys of Vim" together.

Command History Commands that begin with: and/have a history. You can select a history command by typing: or/and pressing the up and down arrows. Start vim by typing the following command in the command line window vim directly starts vim filename Open vim and create a file named filename command Open a single file vim file Open multiple files simultaneously vim file1 file2 file3... Open a new file in vim window:open file Open file in new window:split file Switch to next file:bn Switch to previous file:bp View the list of currently open files, the file currently being edited is enclosed in [].: args Open remote file, such as ftp or share folder:e ftp://192.168.10.76/abc.txt:e\qadrive est.txtvim mode Normal mode (press Esc or Ctrl+[Enter) shows file name in lower left corner or empty Insert mode (press i key to enter) shows--INSERT--Visual mode (don't know how to enter) shows--VISUAL--Navigation command % Parentheses match

insert command

i insert before death I insert at the beginning of the current line a insert after the current position a insert at the end of the current line O insert a line after the current line o insert a line before the current line find command/text find text press n find next press n find previous text Find text, reverse search, press n key to find next, press N key to find previous. There are some special characters in vim that need to be escaped when looking up.* []^%/?~$: set ignorecase case-ignoring search:set noignorecase case-ignoring search for very long words, if a word is very long, typing trouble, you can move the cursor to the word, press the * or #key to search for the word, equivalent to/search. Is #command equivalent? Search.: set hlsearch Highlight search results so that all results are highlighted instead of just one match.: set nohlsearch turns off highlighting:nohlsearch turns off the current highlight and highlights it again if you search again or press the n or N key.: set incsearch Progressive search mode, searches for the currently typed character without waiting for typing to complete.: set wrapscan re-searches, returns to continue searching when searching to the head or tail of the file, enabled by default. The replace command ra replaces the current character with a, the current character being the cursor character. s/old/new/replace new with old, replace first match on current line s/old/new/g replace new with old, replace all matches on current line %s/old/new/replace new with old, replace first match on all lines %s/old/new/g replace new with old, replace all matches on entire file:10,20 s/^/ /g Add four spaces before each line from line 10 to line 20 for indentation. ddp swaps the row on which the cursor is located and the row immediately below it. The move command h moves left one character l moves right one character. This command is rarely used and is usually replaced by w. k Up one character j Down one character More than four commands can be used with numbers, such as 20j is to move down 20 lines, 5h is to move left 5 characters, in Vim, many commands can be used with numbers, such as delete 10 characters 10x, insert 3! after the current position, 3a!,Esc here is required, otherwise the command does not take effect. w Move forward one word (cursor stops at the beginning of the word), 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 one word backward 2b Move two words backward e, same as w, except the cursor stops at the end of the word ge, same as b, the cursor stops at the end of the word ^ Move to the first non-white space character in the row. 0 (the number 0) moves to the first character in the row, moves to the first character in the row. Same as 0 Jian.$ Move to the end of the line 3$Move to the end of the line 3 lines below 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 x character after the cursor, and 3fd will find the third d character. F is the same as f, looking backwards. Jump to the specified line, colon + line number, carriage return, for example, jump to line 240 is:240 carriage return. Another method is line number +G, such as 230G jumping to line 230. Ctrl + e Scroll down one line Ctrl + y Scroll up one line Ctrl + d Scroll down half screen Ctrl + u Scroll up half screen Ctrl + f Scroll down one screen Ctrl + b Scroll up one screen Undo and redo u Undo (Undo) U Undo an operation on an entire line Ctrl + r Redo (Undo), i.e. undo undo. Delete command x Delete current character 3x Delete current cursor starts three characters backward X Delete the previous character of current character. X=dhdl delete current character, dl=xdh delete previous character dd delete current line dj delete previous line dk delete next line 10d delete 10 lines beginning with current line. D Delete the current character to the end of the line. D=d$d$Delete all characters after the current character (this line) kdgg Delete all lines before the current line (excluding the current line) jdG (jd shift + g) Delete all rows after the current row (excluding the current row):1,10d Delete rows 1-10:11,$d Delete all rows 11 and later: 1,$d Delete all rows J(shift + j) Delete the blank row between two rows, in effect merging two rows. Copy and paste yy copy the current line nyy copy the n lines starting after the current, e.g. 2yy copy the current line and the next line. pPaste after the current cursor, if yy was used to copy a line, paste next to the current line. shift+p Paste before current line: 1 - 10 co 20 Insert lines 1-10 after line 20.: 1,$ co $Copy the entire 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, and then use jklh command to move to select some lines or characters, and then press y to copy ddp to exchange the current line and the next line xp to exchange the current character and the next character Cut command in normal mode, press v (verbatim) or V (line-by-line) to enter visual mode, and then use jklh command to move to select some lines or characters, and then press d to cut ndd Cut n lines after the current line. The p command allows you to paste the cut:1,10d Cut lines 1-10. Use the p command to paste the cut content.: 1, 10 m 20 Move lines 1-10 to 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 commands:split or new Open a new window, the cursor stops on the top window:split file or:new file Open a file with a new window split Open windows are horizontal, use vsplit to open windows vertically. Ctrl+ww Move to next window Ctrl+wj Move to lower window Ctrl+wk Move to upper window Close window:close Last window Cannot use this command to prevent accidental exit from vim.: q If it is the last window closed, vim will exit. ZZ save and exit. Close all windows, keep only the current window:only record macros press q key plus any letter to start recording, then press q key to end recording (this means that macros in vim cannot be nested), when using @ add macro name, such as qa. q records a macro named a, which @a uses. Execute shell command:! command:! ls List files in current directory:! perl -c script.pl Check perl script syntax, you can not quit vim, very convenient.:! perl script.pl Perl script execution, you can not quit vim, very convenient.: suspend or Ctrl - Z suspend vim, return to shell, press fg to return vim. The comment command allows comments on behavior starting with #in the perl program, so to comment on certain lines, simply add #3 - 5 s/^/#/g comments at the beginning of lines 3-5 3 - 5 s/^#/g uncomment lines 3-5 1,$ s/^/#/g comments the entire document.:% s/^/#/g annotates the entire document, which is faster. Help command:help or F1 Display full help:help xxx Display xxx help, e.g.:help i, :help CTRL-[(i.e. Ctrl+[help).: help 'number' Vim option help enclosed in single quotes:help special key help extended:help -t Vim startup parameter help-: help i_insert mode Esc help, help in a mode_topic mode help file located in|| The content between is a hyperlink, you can use Ctrl+] to enter the link, Ctrl+o (Ctrl + t) to return other non-editing commands. Repeat the previous command:set ruler? Check whether ruler is set. In.vimrc, options set by the set command can be viewed through this command:scriptnames View the location of vim script files, such as.vimrc files, syntax files and plugins.: Set list displays non-printing characters such as tabs, spaces, line endings, etc. If tabs don't appear, make sure you set the.vimrc file with set lcs=tab:>-and make sure you have tabs in your file. If expendtab is enabled, tabs will be expanded to spaces. Vim tutorial on Unix $ vimtutor on Windows:help tutor:syntax List defined syntax items:syntax clear Clear defined syntax rules:syntax case match case-sensitive, int and Int will be treated as different syntax elements:syntax case ignore case-independent, int and Int will be treated as the same syntax element, and use the same color scheme Thank you for reading, the above is "Vim commands, operation methods and shortcut keys what" content, after learning this article, I believe you have a deeper understanding of Vim commands, operation methods and shortcut keys what this problem has, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report