VIM visual mode: highlight the last two lines in each line?

I like the visual mode of Vim. vto select / select characters or lines, Ctrl vto select a rectangle, as far as I know (I'm new). Is there a way to use visual mode to highlight the last two characters, for example, for each line for some selected lines? The selected rows have different lengths. Basically, I would like to find a quick way to delete the last two characters for some selected lines. Not sure if I can use visual mode to highlight an irregular area.

+3
source share
2 answers

My approach to this problem is to use the line select (shift-V, move the cursor) to select the lines of interest, and then type:

 :s/..$//

This is a regular expression lookup ..$that matches the last two characters at the end of the line. Then replace β€œnothing”, i.e. Remove.

In vim, as soon as you click :with active row selection, the command line will show:

:'<,'>

What will be the beginning and end of the selection addresses for the next command (in this case)

+9
source

I can't think of a way to do this in visual mode, but you can use a command like this to do this ...

:10,20 normal $xx

10 20, $ , x . vim , , (.. esc).

?

+3

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


All Articles