When VIM is used for editing practical configurations in colleges and universities, by default, the editing interface does not display line numbers, syntax high-brightness display, smart indentation, and other functions. To better work in vim, you need to manually set a configuration file:. vimrc. When vim is started, when... when VIM is used for editing practical configurations in colleges and universities, by default, the editing interface does not display line numbers, syntax high-brightness display, smart indentation, and other functions. To better work in vim, you need to manually set a configuration file:. vimrc. When vim is started. the vimrc file is automatically read, which can contain some settings or even scripts. it is easier to create a vimrc file in the root directory of the current user, that is, to create a command: $ vi ~ /. After vimrc is set, save $: x or $ wq and exit. The following is an example that lists frequently used settings. for detailed settings, see reference: "Comments of behavior starting with double quotation marks, the same below" remove annoying vi consistency modes, avoid bugs and limitations in earlier versions: set nocompatible "show row number" check file type filetype on "record number of rows set history = 1000" background black set background = dark" syntax on "the following two lines show syntax on, it is useful in the format pair. "in the first line, vim uses automatic start, that is, applies the format of the current row to the next line." in the second line, based on the preceding start-up format, you can intelligently select the start-up mode. it is useful for writing similar to C language. "set autoindentset smartindent" sets the tab key to four spaces in the first line, the second row is set to use four spaces set tabstop = 4 set shiftwidth = 4 "to set the matching mode when the lines are staggered. Similarly, when you enter a left brace, it will match the corresponding right brace set showmatch "to remove toolbarset guioptions = T in vim's GUI version. if the command is incorrect when vim is edited, this setting removes the set vb t_vb = "in the editing process, the status line set ruler at the cursor position is displayed in the lower right corner." by default, search for matching is highly highlighted. it is very convenient to disable the set nohls highlighted Display. for example, to search for the book word, when/B is entered, the first word starting with "B" is automatically found. when/bo is input, the first word starting with "B" is automatically found, and so on, using this setting will quickly find the answer. when you find the matching word ", do not forget to press set incsearch" to modify a file and then perform automatic backup, the backup file name is the original file name plus "~ "Suffix if has (" vms ") // note that double quotation marks must be enclosed in half-width quotation marks" "set nobackupelseset backupendif. if annotations are removed, a complete one is provided. vimrc configuration information is as follows: set nocompatibleset numberfiletype on set history = 1000 set background = dark syntax on set multicast tabstop = 4 set keys = 4 set showmatchset guioptions-= Tset vb t_vb = set rulerset nohlsset incsearchif has (" vms ") set nobackupelseset backupendif this tutorial describes some basic tips for using VIM in different working modes-insert mo De), command mode, and file access. The goal is to help new users who have just been familiar with VIM use this excellent editor more efficiently. Note: in this article, Ctrl + X -- press Ctrl and then press X. In addition, you can use the: help command to get help from most commands in many cases. this is the internal help file command of VIM. 1. efficiency move 1.1 apart from the insert mode. basically, you should stay in the insert mode as little as possible, because VIM is like a "dumb" editor in the insert mode. Many new users will stay in the insert mode because it is easy to use. But VIM is powerful in its command line mode! You will find that after you get to know VIM more and more, you will spend less and less time using the insert mode. 1.2 when using the h, j, k, and l commands using VIM for efficient editing, the first step is to discard the arrow keys. With VIM, you do not need to move between the arrow keys and the keys frequently, which saves you a lot of time. In command mode, you can use h, j, k, and l to implement the left, bottom, top, and right arrows respectively. You may need to adapt to this method at the beginning, but once you get used to this method, you will find the efficiency of this operation. When you edit your email or other text with paragraphs, you may find that the direction keys are different from what you expected. sometimes you may skip many lines at a time. This is because your paragraph is a long line in VIM's view. In this case, you can type a g before pressing h, j, k, or l, so that VIM will move according to the rows on the screen as you wish. 1.3 cursor effectively moves the cursor in the current row. many editors only provide simple commands to control the movement of the cursor (for example, left, top, right, bottom, to the beginning/end of the line ). VIM provides many powerful commands to satisfy your desire to control the cursor. When the cursor moves from one point to another, the text between the two points (including the two points) is called "crossing", and the command here is also called "motion. (For a brief description, this important concept will be used later) here are some commonly used commands (motion): fx: Move the cursor to the next x of the current row. Obviously, x can be any letter, and you can use; to repeat your previous f command. Tx: similar to the preceding command, but it is moved to the left of x. (This is really useful) Fx: Similar to fx, it's just looking back. W: Move the cursor forward to a word. B: move a word behind the cursor. 0: Move the cursor to the beginning of the current row. ^: Move the cursor to the first letter of the current row. $: Move the cursor to the end of the row. ): Move the cursor to the next sentence. (: Move the cursor to the previous sentence. 1.4 swap effectively moves the cursor in the entire file. VIM has many commands that can be used to reach the desired place in the file. The following are some commands for moving data in a file: : Move a screen down. : Move the screen up. G: to the end of the file numG: Move the cursor to the specified row (num ). (For example, 10 GB is to 10th rows) gg: to the first file H: Move the cursor to the top of the screen M: Move the cursor to the middle of the screen L: Move the cursor to the bottom of the screen *: read the string at the cursor and move the cursor to where it appears again. #: It is similar to the above, but it is looking in the opposite direction. /Text: Search for the string text from the current cursor and reach the place where the text appears. You must press enter to start the search command. If you want to repeat the previous search, press n. ? Text: similar to the above, but in the opposite direction. Ma: Mark a bookmark at the position of the current cursor. Its name is. Only lowercase letters are allowed. You can't see the existence of bookmarks, but it is already there. 'A: to bookmarks. Note that this is not a single quotation mark. it is generally located on the left of 1 of most keyboards. '.: The last time you edited the file. This command is useful, and you do not need to mark it yourself. 2. efficient keyword input 2.1. using keywords to automatically complete VIM has a very beautiful keyword auto-completion system. This means that you can enter a part of a long term, and then press a key. then VIM completes the long term input for you. For example, you have a variable named iAmALongAndAwkwardVarName somewhere in your code. Maybe you don't want to input it one by one every time. To use the keyword auto-completion function, you only need to enter the first few letters (such as iAmAL), and then press (Press Ctrl, and then press N) or . If VIM does not give the word you want, basically press it until you are satisfied, VIM will keep repeating the matching string it finds. 2.2 tips smart entry into the insert mode many new users enter the insert mode only use I. In this way, you can enter the insert mode, but it is usually not that appropriate, because VIM provides many commands to enter the insert mode. Below are some of the most commonly used: I: insert I to the left of the current character: insert a at the beginning of the current line: insert A to the right of the current character: insert o at the end of the current line: insert a new line O under the current line: insert a new line c {motion} on the current line: delete the character crossed by the motion command and enter the insertion mode. For example: c $, this will delete the characters from the cursor position to the end of the line and enter the insert mode. Ct !, This removes the exclamation point from the cursor position to the next one (but not included), and then enters the insert mode. The deleted character is stored in the clipboard and can be pasted out. D {motion}: similar to the above, but does not enter the insert mode. 3. valid for moving large text segments 3.1 using visual selections and the appropriate selection mode does not require the original VI, VIM allows you to highlight (select) some text and perform operations. There are three visual modes: v: Select by character. Frequently used mode, so try it yourself. V: Select by row. This is especially useful when you want to copy or move many lines of text. : Select by block. Very powerful. This function is available only in a few editors. You can select a rectangle and the text in the rectangle is highlighted. When selecting a mode, use the arrow keys and commands described above (motion ). For example, vwww highlights the three words in front of the cursor. Vjj will highlight the current line and the following two lines. 3.2 crop cut and copy in visual selection mode once you highlight the selected area, you may want to perform some operations: d: cut the selected content to the clipboard. Y: Copy the selected content to the clipboard. C: Paste the selected content to the clipboard and enter the insert mode. 3.3 cutting and copying in non-visual selection mode if you know exactly what you want to copy or cut, you do not need to enter the visual selection mode. This also saves time: d {motion}: cut the characters crossed by the motion command to the clipboard. For example, dw cut a word and dfS cut the character from the current cursor to the next S to the clipboard. Y {motion}: similar to the above, but it is a copy. C {motion}: similar to d {motion}, but enters the insert mode. Dd: cut the current row. Yy: copy the current row. Cc: cut the current row and enter the insert mode. D: cut from the cursor position to the end of the row to the clipboard. Y: copy the current row. C: similar to D, and finally enters the insert mode. X: cut the current character to the clipboard. S: similar to x, but enters the insert mode at last. 3.4 paste and paste the cursor. Press p. 3.5 Using multiple clipboard many editors only provide one clipboard. There are many VIM instances. The clipboard is called a register in VIM ). You can list all register names and their contents defined Currently. the command is ": reg ". It is best to use lower-case letters as the register name, because some of the upper-case letters are occupied by VIM. The Register command is double quotation marks. For example, we want to copy the current row to register k. You should press "kyy. (You can also use V "ky. Why ?) Now the current row should already exist in register k until you copy something into register k. Now you can use the "kp" command to paste the content in register k to the desired position. 4. avoid repeating 4.1. the command is amazing. in VI, enter. (decimal point), and the last command you gave will be repeated. For example, if your last command is 'dw '(delete a word), VI will delete another word. 4.2 using numbers in NLP is also one of VIM's powerful and time-saving features. You can use a number before many VIM commands. this number will tell VIM how many times this command needs to be executed. For example, 3j moves the cursor down three rows. 10 DD will delete 10 rows. Y3 "copies the content from the current cursor to the third quotation mark to the clipboard. Numbers are very effective methods to extend the scope of the motion command. 4.3 when recording macros, you will find that you repeat the same series of actions in each segment or line of the article. VIM allows you to record a macro to fulfill your special needs. Qregister: record macro to register. here, register is your register name. For example, qa records and stores macros in register. Q: The record of the ending macro. @ Register: Use a macro with a register. For example, @ a will use macros in register. You must remember that macros only record your series of keys and repeat them. They are not magic. There are many methods to accomplish the goal in VIM, so sometimes you need to carefully select commands to record your macros. Because they will be executed in all the places where you want to execute it. 5. Using VIM to write code VIM is an excellent editor for writing code, because it has some features dedicated to programmers. Here are some common features:] p: is similar to p, but it automatically adjusts the indent of the pasted text to adapt to the position of the current code. Try it! %: Matching curly braces, square brackets, and brackets. On the top of a bracket, press %, and the mouse will appear at the other half of the matching bracket. >>: Indent all selected code. <: similar to the above code, but the gd is reversed. it reaches the function or variable definition where the cursor is located. K: Search for the word at the current position of the cursor in Man.
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.