Which operator can be used to move the cursor to the last non-empty character of a screen line in vim?

I know that g$ can be used to move the cursor to the last character of a line of the screen, but which operator can be used to move the cursor to the last character without a space on the screen line?

+5
source share
2 answers

g_ (g followed by underscore) moves to the last non-empty character of the string strings text . (As Khan Pintyan noted in the comments).

To go to the last non-empty character of the screen line, there is not the only operator that I could find, but you could combine g$ with ge to achieve this result: use g$ to go to the last character (empty or not empty) of the screen line and then, if the cursor is in a space, use ge to move back to the last character of the previous word. (And, of course, if the character under the cursor is not empty, just omit the ge statement).

If you are trying to write a script, it will not be as useful as a separate highlighted statement, because in order to make a decision about the character under the cursor after g$ completes, it must make a decision. But if you are just trying to go to the last non-empty character in visual mode or for interactive editing, the combination g$ ge should be sufficient for what you need.

Also try substituting ge for ge , depending on whether you want to skip punctuation or not. (See :help word-motions for the distinction between e and e : basically, e counts ALL non-whitespace as word characters, and e counts only letters, numbers, and underscores.)

+5
source

Screen right

g$

Left screen

g0

Top of screen

H (high)

Middle screen

M

Bottom of the screen

L (low)

0
source

Source: https://habr.com/ru/post/1202000/


All Articles