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

How to use the VIM Editor in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, I will talk to you about how to use the VIM editor in Linux. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

As a powerful editor with rich options, Vim is loved by many users. This article introduces some options that are not enabled by default in Vim but are actually very useful. Although it can be enabled separately in each Vim session, to create an efficient editing environment out of the box, it is recommended that you configure these commands in the Vim configuration file.

Skills: principles and ways to quickly improve the efficiency of using vim

Vim is the default editor for all Unix/Linux operating systems. Because of its powerful function and efficient operation, vim has also become one of the editing tools that many Unix/Linux users and administrators must master and use skillfully. Especially in the absence of a graphical interface, it is inseparable from vim. There are a lot of vim commands and its usage is very flexible, so it is difficult to master it. Combined with his own experience, the author will focus on which principles, approaches or commands can quickly improve the editing efficiency of vim files in seven aspects, so as to achieve twice the result with half the effort.

Introduction

Vi was originally implemented by Bill 喜悦 in 1976. Vim (Vi IMproved) is an improved Vi developed and released by Bram Moolenaar in 1991. Vim is the default editor for all Unix/Linux operating systems. Because of its powerful function and efficient operation, vim has also become one of the editing tools that many Unix/Linux users and administrators must master and use skillfully. Especially in the absence of a graphical interface, it is inseparable from vim. There are a lot of vim commands and its usage is very flexible, so it is difficult to master it. There are many articles about the use of vim in detail, so this article does not cover many functions and commands of vim. Combined with his own experience, the author will focus on which principles, approaches or commands can quickly improve the editing efficiency of vim files in seven aspects, so as to achieve twice the result with half the effort. The approaches or commands discussed in this article are only for vim configured by default on the system. Various customized functions of vim are beyond the scope of this article. (note: all the commands mentioned in this article passed the test on Red Hat Enterprise Linux Server release 6.1. )

Selection of Vim version

"if you want to do good work, you must first sharpen its tools." In the choice of vim version, the principle is "if you can use Vim, don't use Vi;. If you can use the latest version, don't stick to the old version." Vim provides much more functions and features than Vi, such as syntax highlighting and shading. In terms of effectiveness and efficiency, editing the same file is better than using Vim; as far as the version is concerned, the new version will often fix some of the defects and deficiencies of the old version. This requires us to use the latest version of Vim whenever possible.

Tips:

The trick to using all the features of Vim under root users is to open the Vim editor with the vim command.

Preparation before starting

The options or configurations described here are located in the Vim startup configuration file .vimrc in the user's home directory. Follow the instructions below to set options in .vimrc:

(note: the vimrc file is also used for global configurations in Linux, such as / etc/vimrc or / etc/vim/vimrc. The .vimrc mentioned in this article refers to the .vimrc file located in the user's home directory. )

In Linux systems:

Open the .vimrc file with Vim: vim ~ / .vimrc

Save and close (: wq)

)

In Windows systems:

First, install gvim

Open gvim

Click Edit-> Startup Settings to open the _ vimrc file

Copy the list of options at the end of this article and paste it into the _ vimrc file

Click File-> Save

(you should be careful here not to use the notepad that comes with Windows to edit the _ vimrc file, otherwise it may cause problems due to different line terminators. )

Next, we will delve into options to improve the efficiency of Vim editing. It is mainly divided into the following categories:

Indent-Tab character

Show & format

Search

Browse & scroll

Spelling

Other options

1. Indent-Tab character

Causes Vim to use the same indentation as the previous line when creating a new row:

Set autoindent

Use smart indentation when creating new lines, mainly for programs such as the C language. In general, when you open smartindent, you should also open autoindent:

Set smartindent

Note: Vim is language-aware, and its default settings can be changed based on the programming language in the file to improve efficiency. There are many default configuration options, including axs cindent,cinoptions,indentexpr, which are not explained here. Syn is a very useful command for setting the syntax of a file to change the display mode.

(syn here refers to syntax, which can be used to set the programming language used by the file, turn on the corresponding syntax highlighting, and execute automatic events (autocmd). )

Sets the width of the tabs (TAB) in the file (expressed as the number of spaces):

Set tabstop=4

Set shift operation > > or

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