I know g$
can be used to move the cursor to the last character of the screen line, but which operator can be used to move the cursor to the last non-blank character of the screen line?
g_
(g followed by underscore) moves to the last non-blank character of the screen line text line. (As pointed out by han pingtian in the comments).
To move to the last non-blank character of the screen line, there's no single operator that I could find, but you could combine g$
with ge
to achieve this result: use g$
to go to the last character (blank or non-blank) of the screen line, then if the cursor is on whitespace, use ge
to move backwards to the last character of the previous word. (And of course, if the character under the cursor is non-blank, just omit the ge
operator).
If you're trying to write a script, this won't be as helpful as a single dedicated operator, since it requires making a decision about the character under the cursor after the g$
has completed. But if you're just trying to go to the last non-blank character in visual mode or for interactive editing purposes, the g$
ge
combination should suffice for what you need.
Also try substituting gE
for ge
, depending on whether you want to skip over punctuation or not. (See :help word-motions
for the distinction between e
and E
: basically, E
counts ALL non-whitespace characters as word characters, while e
counts only letters, digits and underscores.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With