Vim-A Tool for programmers

Source: Internet
Author: User
I personally think that vi can't be used without it. Using it will improve the efficiency a lot, but it may not be able to catch up with the previous speed. The following is my shameless copy and paste: (the picture shows a piece of easy learning) Vim currently has versions of mainstream systems, although Vim has improved a lot compared with VI, however, the first use of VIM is still confusing, and I do not know how to operate it. Therefore, to learn vim, we must first go through the 2 levels. The first step is to understand Vim's design philosophy. At the beginning of Vim's design, the entire text editing was completed with a keyboard instead of a mouse. Almost every key on the keyboard has a fixed usage, the producer of VIM wants the user to complete most of the editing work in the normal mode (that is, the command mode, only the command can be entered). This mode is designed as the default mode. Beginners can enable vim, if you enter words directly, the results will be messy, because Vim understands the words you enter as commands. The second is the command line. Vim has hundreds of commands for editing. If you are familiar with vim commands, the editing speed is indeed much faster than that of the mouse, but it is also difficult to remember them all. The best way to remember them is to practice a lot. Vim is indeed used in daily text editing, and don't give up when encountering problems, instead, you can find a solution. Every time you solve a problem, your vim skills will increase to a level. In fact, a major difference between vim and Other Editors is that it can complete complex editing and formatting functions. few software in these fields can compete with it, but, at the same cost as all flexibility, You need to implement it with your own hands. this actually caused several natural stages in the use of vim. in the beginning, it was notepad, word, and edit that monopolized your brain. These things are deep-rooted and the use of VIM is a nightmare for you. It reduces your productivity rather than improving your productivity. the three working modes are confusing, and you may even think of them as a software that is full of bugs or at least odd and out of touch with today's friendly user interface design. in fact, these initially seem odd features are Vim (or VI) the author and its users summed up the fastest and most practical operations in their long career of text editing and programming. In the long term that is almost equal to the history of the computer itself, through criticism and testing by countless demanding computer users, there is no room for survival in the face of VIM user groups for useless features or poor design. the careful and careful authors of VIM do not allow such a thing in the software they have designed. in the second stage, you get familiar with some basic operations that are sufficient to cope with your daily work. however, you rarely touch Vim's obscure online help documentation at these stages. it is only notepad in your mind. Edit is a barely qualified alternative. in the third stage, you are not satisfied with simple, lengthy, and boring operations. Is there a better way to achieve perfection. as a result, from the Unix reference manual, you gradually open the door to help XXX. start exploring the magic-filled spell. starting with a mix of performances, these techniques are dazzling but rarely practical. however, this is the first step in your magic. next, you begin to realize the truth behind these spells and start to secretly modify some strange symbols. As a result, the magic is still effective, and it actually acts on the text editing life in your reality. in the second stage, the dusty brain suddenly started to work due to your skillful operations. however, this process is not a smooth path, continuous setbacks, new challenges, and seemingly mission of impossible tasks after reaching a critical state. it is always accompanied by any one person's learning process. this is the last phase in which you use Vim. It is also the longest, most challenging, and interesting stage. in this phase, you start to customize some strange colors. I started to input internationalization by typing i18n, and started to ask Vim to correct the mistake that is often made into teh for you, vim began to cooperate with a variety of powerful and powerful brother tools in the system and began to write longer and longer scripts. Every time the text editing experience went viral. your mind is highly nervous because it uses Vim for efficient editing. you started to raise some problems in the vim email list. I also began to find that you have done almost everything in the shell in Vim. in fact, you have become a hopeless Vim hardcore player. repeat, edit this paragraph to move efficiently 1. Outside of the insert modeBasically, you should stay in the insert mode as little as possible, because in the insert mode, VIM is like a "dumb" editor. Many new users will stay in the insert mode because it is easy to use. But Vim is powerful in its command 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. 2. Use H, J, K, and lThe first step to use Vim for efficient editing 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 H, J, K, or l, so that Vim will move as you wish on the screen. 3. move the cursor effectively in the current rowMany editors only provide simple commands to control the movement of the cursor (such as 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. (This important concept will be used later) 4. 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. To repeat the previous F command. TX: similar to TX, but it moves back to the right of X. B: move the cursor forward to a word. W: Move a word behind the cursor. 0: move the cursor to the beginning of the current row. (0) ^: move the cursor to the first letter of the current row. $: Move the cursor to the end of the line .) : Move the cursor to the next sentence. (: Move the cursor to the previous sentence. 5. move the cursor effectively throughout the fileVim has many commands that can be used to reach the desired place in the file. The following are some commands to move a screen in the file: <Ctrl-F>: Move the screen down. <Ctrl-D>: Move the half screen down. <Ctrl-B>: Move the screen up. <Ctrl-u>: Move the half screen up. [2] 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 to move to the next text, and then press n to move to the previous text .? Text: similar to the above, but in the opposite direction. M {A-z}: Mark a single letter named a-Z at the current cursor position. 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. %: Moving between pairs of parentheses and other symbols, such as pairs. Place the cursor on any symbol, and then use % to move to the symbol that matches the symbol. % can also correctly identify the nested layers of the brackets and always move to the truly matched position. Therefore, this command is very useful when editing program code, so that you can easily move between the beginning and end of a piece of code. Edit efficient input in this section 1. Automatically complete with keywordsVim 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 words you want, continue to press until you are satisfied, VIM will keep repeating the matching strings it finds. 2. Enter the insert mode intelligentlyMany new users only use I to enter the insert mode. 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 text for moving large segmentsUnlike the original VI, VIM allows you to highlight and operate some text. 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. 4. Cut and copy in visual selection modeOnce you highlight the selection 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. In non-visual selection mode, cut and copy. 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. 5. PastePasting is simple. Press p. 6. Use multiple clipboardMany 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. 7. Avoid duplicationThe amazing. Command is in VI. Entering the. (decimal point) will repeat the previous command you entered. For example, if your last command is "DW" (delete a word), VI will delete another word. 8. Use numbersUsing numbers is also a powerful and time-saving feature of vim. 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. Y3t ″ will copy 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. To edit this efficient read code section, we recommend that you install the taglist + cssag + ctags plug-in on VIM to facilitate efficient read and learning! [3] 1. InstallationFor me, I am using ubuntu. The General Command for installing software is apt-Get install ***! For the creation of the VIM + taglist + csags + ctags combined Editor, Vim, cssag, and ctags can be easily installed using the preceding commands! (The commands for installing software in different Linux releases are not the same and must be slightly modified according to your own installation version. For example, fedora is installed using the yum command.) You cannot install taglist using this method, we need to download the plug-in first, and then install it: first download the taglist plug-in online, decompress the package, and then download the taglist under the file. vim uses the CP command to copy to home /. under the vim/plugin folder (CP-r taglist. vim ~ /. Vim/plugin) 2. Vim ConfigurationVim is a very useful editing tool. The following describes several common baseline-mode commands: (1 ). set smartindent: Set smartindent // set smartindent shiftwidth = 4 // the C language is automatically indented, And the indent value is 4 characters in width (2 ). show cursor row and column information: Set rcursor // display cursor information (bottom right corner) (3 ). view the tab: set list // display the tab, and display the position of the tab with the ^ symbol (4 ). view the number of rows: set number // display the number (left) (5 ). keyword highlighting: syntax on // keyword highlighting (6 ). multi-file Editing: when compiling a program, you may need to edit multiple files at the same time. In this case, the following settings are required: Split two. C // multi-file editing. Of course, if it is not too troublesome, you can enter the above command every time you open Vim. For example, I often use: set number: Set rsyntax: syntax on: Set SMA. Rtindent command. If you directly write the commands entered in baseline mode to the configuration file, you do not need to enter these commands again when using vim. First, try to enter the following command in the bottom-line mode of vi. If not, download a full version of VIM, sudo apt-Get install vim-full. The method for modifying the configuration file is as follows: (1) Find the vimrc file. (2) Permission to view files: ls-l vimrcshisir @ shisir-desktop:/usr/share/Vim $ CD/etc/vimshisir @ shisir-desktop: /etc/Vim $ lsgvimrc vimrc. tinyshisir @ shisir-desktop:/etc/Vim $ LS-l vimrc-r -- 1 Root 2492 vimrc (3) if you do not have the write permission, modify the permission so that we can modify the configuration file sudo chmod A + W vimrc (4) write the appeal command to the configuration file as needed. For example, my personal settings are: syntax on, set rease, set number, set smartindent shiftwidth = 4 and paste the configuration information of my vimrc file below: "display row number" check file type filetype on "record historical rows set history = 1000" automatic alignment set autoindentset cindent "intelligent choice alignment set smartindent" tab is 4 spaces set tabstop = 4 "use four spaces when the current row is staggered set shiftwidth = 4" to set the matching mode, when you enter the brackets, the right parenthesis set showmatch is displayed. When you edit the settings, the cursor status is displayed. Set ruler "Quick Match set incsearch" Modify automatic file backup if has ("VMS") set nobackupelseset backupendif
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.