In the visual mode the $ extends selection until the end of the line including the new line character at the end, so I need to press an additional h to exclud the new line character.

  • Is it possible to extend the visual selection until the last character on the line (excluding the new line character) easier as with $h?

  • Are there some set options controlling the behavior of the $?

  • Bonus question: Is it possible to extend the selection (or jump) to the last non-whitespace character on the line?


2 Answers 2


Your first and third points are answered by g_, which moves to the last non-whitespace character on the line. So, vg_ will visual select to the end of the line, excluding any whitespace and the newline.

There is no option to control the behavior of $ here, as far as I know. However, you can remap it in your .vimrc if you prefer a different behavior:

vnoremap $ $h  " if you prefer including trailing whitespace by default
vnoremap $ g_  " if you prefer excluding trailing whitespace by default
  • vnoremap $ g_ in .vimrc is all what one needs to know. Feb 12, 2023 at 15:58

It seems that we can also set the selection option to achieve what you want. If we use

set selection=exclusive

the newline character will not be included the selected characters.

  • This is a great answer! Thank you! But trying it out I ended up using the 'selection=old' value. Jan 15, 2019 at 14:31
  • I'd still use xnoremap $ g_ because set selection=exclusive causes that when you select from right to left (with the mouse), it excludes the first character on the part where the mouse started (it's okay when select is left to right).
    – strboul
    Feb 11, 2022 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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