TransWikia.com

v$ without trailing space?

Vi and Vim Asked by Tallboy on August 31, 2021

I want to use $ in visual mode but it always includes a trailing space (even if there isn’t one on the line).

How do I make it so $ only goes to the actual last letter?

One Answer

You can control that with the 'selection' option. To disable the "past line" cursor behavior, use the following command:

set selection=old

Beware that using a non-default setting for this option is possibly likely to break behavior of some plug-ins, so it might not be a great idea to change it.

There's also a motion that might be close to what you want: g_ moves to the last non-blank character of the line. It's not exactly the same as $ with selection=old. For example, when there are trailing blanks. Also, using $ will keep the cursor at the last character of the line as you move up or down, which is not the case if you used g_.

But g_ will work without having to mess with the 'selection' setting, so it's better in that sense.

Correct answer by filbranden on August 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP