In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain how to sequence vim for you in detail. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Pending text
Assume that the original content of the text is
This is the first line, this is the second line, this is the fourth line, and this is the fifth line.
Insert line number becomes
1 this is the first line 2 this is the second line 34 this is the fourth line 5 this is the fifth line
Another desired effect is
This is the first line line [1], this is the second line line [2], the third line line [3], this is the fourth line line [4]
The answers to both of the above requirements are given below, and more complex digital sequence insertion can actually be achieved by using the methods mentioned below. Includes replacing the specified character, followed by a sequence of numbers.
Use line ()
Line (.') You can return the current line number
: G / ^ / sbind /\ = line ('.').''/
Very simple, but not very flexible, can only be used to display the line number of the current line
Use the ex command
Vim provides some ex commands that can print line numbers, such as "=", "p #", "#"
To get the command output of vim, you need to use redir here
"add a line number to the first five lines: redir @ a | 1 redir END:1,5d | put! a | 1D | 6d
There is an extra line before and after pasting, so delete it with d
Use range, setline, getline
Range () can produce a list of numeric sequences
: for i in range (6): call setline (I, i.' .getline (I)): endfor
Range (6) produces a list of numbers 1-5, excluding 6
Variable product addition
: let iTunes 1 | g / ^ / s _ let i=i+1 /\ = i.' / |
This method is more flexible, and the inserted value can be controlled by controlling the change of I value.
Macros and Ctrl-A
You can press ctrl-An on the number to add one, and Ctrl-X to subtract the number by one.
The process is as follows:
Manually add the serial number and space of the first line
Enter 0 "ayw to put the sequence number and space in register a
Move to the next line and execute the following key
Qz0 "AP 0 ^ A" ayawjq
Execute 4roomz to execute the sequence of commands saved in register z on the following four lines
The above command sequence is explained in detail as follows
Qz: start recording macros and save them in register z
0: move to the beginning of the line
"aP: paste the contents of register a (line numbers and spaces) here
0 ^ A: move to the beginning of the line and press ctrl-A to add one to the number under the current cursor
"ayaw: copy the word under the current cursor to register a
J: move to the next line
Q: end of recording
If there is no space to mark, then you cannot use aw to copy a word, use v to select the corresponding numeric part
Note: on the command line, ctrl-a needs to use ctrl-v and ctrl-a to represent this button
Macros are more powerful in vim, but it takes a lot of debugging to write a viable macro
External command
Seq is the command to output sequence under linux.
Harriszh Sat 22 512345harriszh Sat 14 @ ~ / trunk/go$ seq 5-2 1531harriszh Sat 22 1531harriszh Sat 14 @ / trunk/go$ seq 1 512345harriszh Sat 22 14 @ ~ / trunk/go$ seq 12 5135
If there are three parameters, the middle parameter is step, and the two parameters are the start number and the end number. Step is 1.
Insert a sequence of numbers into a file through r! seq 1 5, and then copy using column mode
Use printf
Insert the line number directly
:% s / ^ /\ = printf ('%-4 days, line ('.'))
Where-left alignment, default right alignment
Inserts a sequence at the specified row
First, select the block to insert the serial number in V
:'
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.