Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic configuration of the vim editor

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

What is the vim Editor

Vim is a text editor developed from vi. Code completion, compilation and error jump are particularly rich in convenient programming functions, which are widely used among programmers, and Emacs has become the favorite text editor for users of Unix-like systems.

Vim's design philosophy is a combination of commands. Users have learned a variety of text-to-text move / jump commands and other normal mode editing commands, and if they are able to combine them flexibly, they can edit text more efficiently than editors without patterns. At the same time, VIM is similar to many shortcut key settings and regular expressions to aid memory. And vim is optimized for programmers.

To give you a suggestion, practice the basic operation of vim before learning the configuration of vim. For example, how to move and delete quickly, I have seen many developers who have been using vim for some time, but they still use the keys above and below to move the cursor, which basically loses the meaning of learning vim configuration. Therefore, it is recommended that you first lay a solid foundation of vim before learning the configuration, so that you can get twice the result with half the effort.

Why vim configuration

Before you learn the vim configuration, answer this question. I often encounter this problem, and I want to automatically display the line number every time I open vim instead of typing: set nu every time. At this point, we can write the vim configuration file and write the set nu to the configuration file. In this way, you can meet the requirements of persistent configuration.

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

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

~ / .vimrc

If you want to write your own vim configuration, you need to create a ~ / .vimrc file, and then write the configuration you want into the configuration file. Next, let's demonstrate the simplest case:

# vim ~ / .vimrc "set line number set nu" cancel line number "set nonu

Configuration items generally have two options: open and cancel. Generally, cancel is to add no before "open". As shown above, set nu indicates that the line number is displayed, while set nonu indicates that the line number is not displayed.

Lines that begin with unilateral double quotation marks indicate comments

When you finish editing the configuration file and save the exit, the configuration takes effect immediately.

Common configuration

Here are a few common configurations from several aspects. First, introduce a configuration item that automatically checks syntax and highlights it.

"enable syntax highlighting syntax on

An option about text coding, generally speaking, we will use utf8 coding.

"use utf-8 encoding. Set encoding=utf-8

Options for indentation

Set autoindent says that when the enter key is pressed, the next line will be the same as the indentation of the previous line

Set softtabstop 4 indicates that pressing the tab key inserts four spaces. The default is usually 8 spaces.

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report