Vim ex knowing the number printed before

I make a shortcut that puts # at the beginning of each line, in the next lines x. x is the type of number i before entering the shortcut, for example, input 11dddeletes the next eleven lines.

Team .,+10 s/^/#/g. Here, the number ten should really be what was printed before the label. How to change the label according to the number that was printed before it?

Added after answering the question:

So now I have the following in .vimrc:

nmap c1 :s/^/#/g<esc>``
nmap c0 :s/^#//g<esc>``

Lets me enter 13ac, add #at the beginning of the next 13 lines and 13dcto delete any #in front of the next 13 lines.

This is better than =podand =cutsince they cause nesting errors.
c1 = add comment,
c0 = delete comment.
# used in Perl.

+3
source share
1 answer

In mode, exyou can use the following command:

s/^/#/count

where countis the number of lines you want to change. You cannot put a number in front of the command because it is used to select the start line (the current line if it is omitted). In this way:

5s/^/#/3

will add '#' before lines 5, 6 and 7.

Edit

ex map , :

map CC :s/^/#/g

"xCC" vi, "#" x.

+3

Source: https://habr.com/ru/post/1760067/


All Articles