Guide |
There is no doubt that Vim is a very powerful text editor. It provides a number of features, which means learning and remembering all of the functions of Vim is virtually impossible. But we can at least continue to learn simple ways to do things, so that as time grows, our experience with the editor will be better. |
This article is an article in the Vim User Guide series:
Vim Beginner Getting Started Guide
Vim Accelerator Quick Check Table
5 Vim Tips for experienced users
3 Practical tips for advanced users with Vim editor
Keep in mind that some of the Vim editor tips we'll discuss in this article are for advanced users.
Note: If you are touching Vim for the first time, you can first read our Getting Started Guide. For users who have already used the Vim editor, I am confident that the VIM accelerator quick Check table will be helpful to you. If you are already an experienced user, you may be interested in some skills that are specific to experienced users.
Please note that most of the techniques mentioned in this article are explained in a simple, easy-to-understand code environment, as they are really useful in software development. But this does not mean that ordinary users (not programmers, not using Vim as a general text editor) are not used in their work.
1. Set specific variables for the file
Sometimes, in a particular file, you may want to replace the input tab with a space, or you want to indent the source code file with two spaces, even if the default indentation of the editor is four spaces.
Basically, we're here to discuss changes to the file. This feature provided by Vim allows you to change specific settings for a specified file. This feature is called a "pattern line (modeline)".
For example, if you want to replace each tab of the input with a space, you only need to include the following pattern line in the first few lines or the last few lines of the file:
# Vim:set Expandtab:
If you want to change the default indentation from 4 spaces to 2 spaces, you can add the following pattern line to the source file:
vim:noai:ts=2:sw=2
Here are a few important points to keep in mind when working with pattern lines:
A pattern line can only be added to the first five or five elements in a file.
In order to use this feature of the pattern line, it must be added in the. vimrc file: Set Modeline
This feature is invalidated when the file is edited as the root user.
For more information, please read the official documentation for this feature.
2. Key word Completion
When you start to write more complex code or start editing on a large source file, you will encounter some variable names. Sometimes it's not easy to remember all the variable names, so when you need to enter the name of the variable, you usually copy it from the place you've already used it.
Fortunately, with Vim you only need to enter a few initial letters of the variable. In ' Insert mode ', press CTRL + N or CTRL + P to get a list of matching keywords. CTRL + N is used to insert the next matching word, and CTRL + P gives a list of previously matched keywords.
is a demonstration of this feature:
650) this.width=650; "src=" Http://www.linuxprobe.com/wp-content/uploads/2017/02/211721bfccf82z26hffz7c.jpg "alt=" 3 Practical tips for advanced User Vim Editor "style=" Height:auto; "/>
As the screen above shows clearly, the words contained in the other source files appear in the list as well.
3. Search
If you are debugging code, one of the things you need to do is to quickly see where a variable appears in a file. A common method is to exit the ' Insert mode ', enter the/[variable name command, press ENTER, and then return ' Insert mode ', using N and p to navigate between keywords.
There's nothing wrong with this approach, but there's an easier and quicker way to do that. Using this method, you first need to exit ' Insert mode ' and then move the cursor below the word/variable you want to search, which is not time consuming. Next, you just need to press SHIFT + *.
Repeat this, and then the editor will take you to the place where all the words/variables are used in the file.
Conclusion
Although it is for advanced users, the techniques discussed in this article are not difficult to understand and easier to use. If you have a certain foundation, then you can benefit a lot from it. Needless to say, whether it's any new feature or concept, you need to be diligent in practicing these skills to turn them into a habit.
Original address: http://www.linuxprobe.com/3-vim-editors.html
This article is from the "blog" blog, please be sure to keep this source http://coderhsf.blog.51cto.com/12629645/1940072
A practical technique for Vim editing for advanced users