Learn Vim's four-week plan

Source: Internet
Author: User
Tags line editor

Vim has a custom color scheme, syntax highlighting, linting and auto-fill capabilities.

Vim is a very difficult-to-learn command-line editor (with a joke about vim: ask how to generate a bunch of true random numbers and a web developer to quit vim). So why study it, especially if you're used to the existing text editor or IDE? The advantages of learning vim include the following points:

    • Vim is built into any Unix-like system, This means you can edit the file directly on the server (this is useful)

    • Vim is lightweight compared to most text editors and Ides, so it is fast and efficient even on weaker hardware

    • Vim is completely keyboard-driven (and most actions are centered on the main row), so it will make you more efficient?

I made a question mark after the last increase in efficiency, which is a point you'll often hear, but I don't think it applies to everyone. Basically, to make the use of vim more efficient, you need not only spend a lot of time to understand it, but also need to master it. This means that the time it takes to save is usually offset by the time it takes to master it, and you need to take the time to master it. I would say the best reason to study vim is that you enjoy the process of spending time learning to master a complex skill. In this sense, this is no different from the mindset of people who want to learn a new instrument.

If you think the reasons listed above are attractive, you can follow the four-week plan listed below to learn vim. This is the way I used to learn vim, which comes from the similar suggestions I have encountered many times in various forums and tutorials. I also joined some of my own experience in the process of learning.

Week 1th: Study once a day Vimtutor

Many people believe that the best way to learn the basics of vim is to simply enter this command at the terminal:

This command opens a text file with a step-up instruction in Vim that contains the basic VIM command. It takes about 30 minutes to navigate through the document. If you understand the commands covered in Vimtutor, then you are ready to use VIM.

If your goal is to understand vim enough to be able to edit files remotely on the server, you can stop here-you already know enough! If you want to use Vim as your editor, you can proceed to the next step.

Week 2nd: Do as few other configurations as possible, without using plugins

Learn the navigation and editing in Vim, and next you will want to personalize it. The default configuration for Vim is fairly common and obsolete, but you can customize features with the VIMRC profile. It is important not to add too many plugins trying to make vim a complete ide--vim as Vim is good, as the IDE is very bad.

Please follow this article to build your own VIMRC file. As a start, these are just a few of my recommended configurations:

    • Add a color scheme (I'm using Vim-code-dark, based on the visual Studio code)

    • Open syntax highlighting

    • Set spaces and tabs

    • Set auto indent

    • Open line number

    • Use tab to find files in subfolders

    • is configured to press ESC to quickly exit Insert mode (I change my CAPS LOCK key to CTRL and use CTRL C to exit insert mode)

> Actually, that's all! (The only exception to the plugin-free rule is if you need specific support for language installation languages that Vim does not support). The goal is to avoid any other configuration or fancy plugins within a week--which may be painful, but this will prevent you from spending all your time configuring VIM instead of practicing vim.

tip: When you configure VIM, use the following. Vim folder in the home directory. A newer version of Vim will find the VIMRC file in the. Vim folder to keep everything in one folder. This allows you to make your. Vim folder a git repo that you can easily copy to any computer!

Week 3rd: Use as few plugins as you can

After using Vim to complete the actual project, you will have a better understanding of Vim's functionality, and you can make some custom configurations. However, you should still be careful not to install plugins that fundamentally change how vim works. Some of the most popular plug-in types are listed below, but I recommend that you do not use them now:

    • Do not install the plugin manager (a newer version of Vim native plugin management is sufficient)

    • Do not install the tree browser or the fuzzy file Finder plug-in (using: Find and sub-folders search is good)

    • Do not install plugins for visual labels (try to get used to native vim caches: B <TAB> useful)

    • Do not install the AutoComplete plugin (native vim can already be completed using <ctrl n>)

    • Do not install plug-ins for multiline comments (try to use visual mode)

    • Do not install plug-ins for multiple cursors (use/search with N and repeat if required.)

The point is that many times the plugin will hinder your ability to learn the actual functions of vim. All of the above types of plugins are great and can save time, but only if you fully understand how to use native vim to accomplish the same tasks, you can install these plugins.

In other words, there are plugins that do not change the core behavior of vim and make daily use more convenient. Here are some of the plugins I used:

    • Consider installing Auto-pairs.vim (insert or delete parentheses, curly braces, quotation marks)

    • Consider installing Endwise.vim (in Ruby, adding end automatically after If,do,def etc.)

    • Consider installing Ragtag.vim (label helper in Html,erb, etc.)

4th week: Using verbs and nouns to combine VIM commands

Now that you have enough knowledge of vim, you can begin to assemble new commands instead of remembering new commands. The combination of new commands represents the formal use of vim as a language. Chris Toomey's speech "Mastering the Vim language" is well worth seeing, and it shows the power of the concept.

In short, you need to know some verbs and nouns:

    • Verb-d (delete), C (modify), Y (copy),> (indent)

    • noun (action)-W (word), B (move forward one word), 2j (Move down two lines)

    • Noun (text object)-IW (internal word), it (internal label), I "" (Internal Reference)

Then, you can combine verbs and nouns to create any number of commands

    • DW: Delete to the end of the word

    • DIW: Delete the word with the cursor

    • y4j: Copy four lines

    • CIT: modifying content within HTML tags

In the speech, remember that about 30 commands allow you to combine more than 2000 different commands. Please note that I raised this point in week 4th-this thing is very powerful, but only when you have a good grasp of vim. After 3 weeks, you should be able to master 30 necessary commands to reach this level!

    • Consider installing Surround.vim (add a new modifier to change enclosed quotes, parentheses, etc.)

    • Consider installing Commentary.vim (add a new verb to the comment line)

    • Consider installing Repeat.vim (Add. Repeat support for specific plugins)

(all of the above plugins are provided by Time Pope, a name you will inevitably encounter in the course of learning vim)

hint: in the speech, they use the relative line number, in fact I do not recommend. A lot of people became fans when the relative line was first introduced, but I've also heard of people who have problems after some time (such as poor code readability, sometimes causing performance problems, etc.). Because you can use the normal vim command G or GG to easily do the same thing (move to or delete a particular line), so I personally think it has no practical use.

Summarize

Learning Vim is a heavy task, but it can also be fun. If you're shy about spending one months learning a text editor, it might not be for you. However, I think most developers can benefit from the first week's advice and at least get the ability to edit files directly on the server. You will be able to actually use VPS to write code on ipad or Chromebook. At the very least, when Vim is opened in your terminal, you will not look silly to be trapped!

If you do complete the 4-week plan, your programming skills will be upgraded to a level. In fact I don't know if this will make you more efficient (because you might be using the time spent writing code to learn more cool tricks and try out new configurations). As I said before, it's more like learning a musical instrument (depending on your personality), and you can get happy from the process of mastering vim gradually. I hope these suggestions are helpful to your study!

This article is supported by the Marco School of Linux.

Learn Vim's four-week plan

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.