VIM practical configuration practices for Colleges and Universities

Source: Internet
Author: User

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. (In this article, <C-X> represents Ctrl + X -- is to press the Ctrl key 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. Below are some commands to move in the file: <C-F>: move down a screen. <C-B>: Move a 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. With the keyword AutoComplete function, you only need to enter the first few letters (such as iAmAL), then press <C-N> (press Ctrl, then press N) or <C-P>. 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. <C-V>: 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.

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.