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 turn the line number on and off by vi in linux

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to open and close the line number of vi in linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Open and close line number

There are many options in the vi editor that control the look and feel of the editing session. Use the: set command to modify the session settings in vi. After pressing Escape to enter command mode, you can use the: set all command to display a list of options and settings.

One of the options you can set is number, which turns line numbers on and off (see listing 1).

Listing 1. # # Internet host table#::1 localhost127.0.0.1 localhost loghost192.168.0.6 centos5192.168.0.10 appserv192.168.0.11 webserv192.168.0.12 test192.168.0.5 solaris10 # Added by DHCP~~~:set number before opening the line number

This command causes vi to display the line number on each record in the currently edited file. After putting vi into command mode, type: set number and press enter to open the line number (see listing 2).

Listing 2. After opening the line number, 1 # 2 # Internet host table3 # 4:: 1 localhost5 127.0.0.1 localhost loghost6 192.168.0.6 centos57 192.168.0.10 appserv8 192.168.0.11 webserv9 192.168.0.12 test10 192.168.0.5 solaris10 # Added by DHCP~~~:set number

You can turn off the line number using the: set nonumber command. You can also use the abbreviations of this command and the: set number command, namely: set nu and: set nonu.

Displaying line numbers can be very helpful if you need to quickly calculate the number of lines to be processed with the vi function. Line numbers are especially useful when there are a large number of lines that may span multiple screens. In addition, sometimes you know the range of lines to deal with, but you need to find out the initial and ending line numbers to use in the vi command.

If you want the line number to be displayed every time you enter a vi session, add the set number line to the .exrc file in the home directory.

This is the end of the article on "how to open and close line numbers in vi in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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: 206

*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

Development

Wechat

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

12
Report