5

In the visual mode the $ extends selection til 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 til 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?

5

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
3

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. – Boris Brodski Jan 15 at 14:31

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.