If i've got the code


i can insert code before or after all of the lines by using I or A in visual block mode, respectively. How can I delete the last x characters? I'm aware that I can do it with s/o// (where o would require more specific text realistically) but isn't there visual block command?

  • do you want to delete just the os or o, llo, o?
    – Mass
    Jul 31, 2018 at 22:57

2 Answers 2


One way would be to select the lines (using any of the visual modes: block, line, or regular characterwise) and then type the command:

:norm! $xxx

Vim will pre-populate the command line with a range when you press : so the actual command you will execute is:

:'<,'>norm! $xxx

This acts like visiting each line and typing $xxx. (See :help :normal.)

Note that, because of the way the x command handles a range, :norm!$3x won't work. (However, if your virtualedit setting contains onemore or all then you can use a count with a command like :norm!$ld3h: the original command given won't work.)


You can use x and d in visual (block, line) mode. They will delete exactly the selected text. This means you can normally not do things like "delete the last three chars of all selected line" (unless all the lines are the same length, then you can with visual block mode).

But according to How do you change the last n characters for a range of lines? there is a trick: Use :right to first right align the text, remove your chars with visual block mode and the :left align the text again.

  • TIL about the right and last trick, amazing. thank you
    – volk
    Aug 10 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.