Home  >  Article  >  Operation and Maintenance  >  Let VIM work better - VIM basic configuration

Let VIM work better - VIM basic configuration

齐天大圣
齐天大圣Original
2020-06-12 08:29:342058browse

Let me give you a suggestion. Before learning the configuration of vim, you should first practice the basic operations of vim. For example, how to move quickly and delete quickly, etc. I have seen many developers who have been using vim for a while. They still use the up, down, left and right keys to move the cursor, which basically loses the meaning of learning vim configuration. Therefore, it is recommended that you lay a solid foundation in vim before learning the configuration, so that you can get twice the result with half the effort.

Why configure vim

Before learning vim configuration, let’s answer this question first. I often encounter this problem. I want the line number to be automatically displayed every time I open vim, without having to type: set nu every time. At this time, we can write the vim configuration file and write set nu into the configuration file. In this way, the requirements for persistent configuration can be achieved.

In addition to persistent configuration, you can also set some shortcut keys using the configuration file to facilitate our operations. For example, we can set two consecutive keys jj to replace the esc key.

In addition, if you are a vim master, you can also write custom configuration scripts.

~/.vimrc

If you want to write your own vim configuration, you need to create the ~/.vimrc file, and then add the file you want The configuration can be written into the configuration file. Below, we will demonstrate the simplest case:

# vim ~/.vimrc

" 设置行号
set nu
" 取消行号
" set nonu
  • Configuration items generally have two options: enable and cancel. Generally, to cancel, add no before "open". As shown above, set nu means to display the line number, and set nonu means not to display the line number.

  • Lines starting with single-sided double quotes indicate comments

  • After editing the configuration file, save and exit, the configuration will take effect immediately .

Common configurations

The following will introduce several common configurations from multiple aspects. First, we introduce a configuration item that automatically checks syntax and highlights it

" 开启语法高亮
syntax on

An option about text encoding. Generally, we will use utf8 encoding.

" 使用 utf-8 编码。
set encoding=utf-8

Options about indentation

  • set autoindent means that when the enter key is pressed, the next line will be indented the same as the previous line

  • set softtabstop 4 means that pressing the tab key will insert 4 spaces. The default is generally 8 spaces.

The above configuration items are almost necessary to configure in vim configuration. In addition to the above, vim has many other configuration items, you can check and learn by yourself!

The above is the detailed content of Let VIM work better - VIM basic configuration. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn