VIM visual mode: highlight last 2 chars in each line?


VIM visual mode: highlight last 2 chars in each line?



I like Vim's visual mode. v for highlight/select chars or lines, Ctrlv for rectangle highlighting, as far as I know (I am a beginner). Is there any way to use visual mode to highlight last two chars, for example, on each line for some selected lines? The selected lines are in different length. Basically, I would like to find a quick way to remove the last two chars for some selected lines. Not sure I can use visual mode to highlight irregular area.




How do I get Vim to treat underscores in a string as a word break?

1:



what does ^A stand for in vim
My approach to this sort of problem is to use line selection (shift-V, cursor movement) to select the lines-of-interest, then type:.
How to “apply” backspace characters within a text file (ideally in vim)
 :s/..$// 
That's a substitution, using the regex ..$ which will match the last two characters at the end of the line.


Vim 7.2 hangs on startup, “killall vim” fixes it
Then substitute 'nothing' i.e.


What are the typical use cases for vi?
delete..
Vim: Combining autocmd?
In vim, once you hit the : with a line selection active, the command prompt will actually show:.
Vim: padding out lines with a character
:'<,'> 
Which is the start and end of selection addresses for the next command (s in this case).
ido mode filenames for vim?


2:


I can't think of a way to do this in visual mode, but you could use a command like this to do it....
:10,20 normal $xx 
This would go to each line between line number 10 and 20, use $ to go to the end of the line, and then use x twice to delete two characters.

Normal just tells vim to use the following symbols as if they were keyboard shortcuts entered in normal mode (i.e after hitting esc).. Does that help?.



80 out of 100 based on 70 user ratings 470 reviews