1

What are the commands to move to the very beginning and to move the last non-whitespace character of the current visual line? Do they exist at all?

Commands for normal lines Commands for visual lines
To move to the very beginning of a current line 0 ?
To move to the very end of a current line $ g$
To move to the first non-whitespace character of a current line ^ g^ or g0
To move to the last non-whitespace character of a current line g_ ?

Test text:

line 1

    line 2, which is indented by 4 spaces and has 6 trailing spaces. this line should be long enough to be soft-wrapped lorem ispum dolor sit amet lorem ispum dolor sit amet lorem ispum dolor sit amet      

line 3

.vimrc settings:

set wrap
set breakindent
set linebreak
1
  • It's bit of a nitpick, but I found the use of "visual" in this question confusing at first (as that usually refers to visual mode in Vim). As far as I'm aware the documentation uses only display lines or screen lines to refer to what you're talking about.
    – Rich
    Commented Sep 1, 2022 at 10:57

2 Answers 2

3
+150

g0 moves to the very beginning of the visual line, whereas g^ moves to the first non-whitespace character on the current visual line. (At least, that's what the help file says and that's what it does for me.)

g$ and g<End> seem to do the same thing; g0 and g<Home> also do the same thing.

I don't think there is an equivalent to g_ for the visual line, but you can fake it with "g$be" (which is technically "go to the end of the visual line then go back one word, then to the end of it), but that only works if the line actually ends in whitespace.

3
  • "g0 moves to the very beginning of the visual line" - It seems it depends on where the cursor is initially located. If the line is wrapped into three visual lines and the cursor is on the 1st visual line of them, g0 will move you to the very beginning. If your cursor is on the 2nd or 3rd visual lines, g0 will move you to the first non-whitespace character. (And the same for g$.)
    – user90726
    Commented Aug 28, 2022 at 9:12
  • @user90726 If your cursor is on the 2nd or 3rd visual lines, g0 will move you to the first non-whitespace character are you sure this isn't because of indentation? As soft wrap also indents, this can be confusing.
    – Biggybi
    Commented Aug 28, 2022 at 9:49
  • @user90726 "If your cursor is on the 2nd or 3rd visual lines, g0 will move you to the first non-whitespace character. (And the same for g$.)" It doesn't in my VIM. It behaves exactly as I said in the post, and g0 always takes me to beginning of the visual line.
    – karlh
    Commented Sep 1, 2022 at 20:53
1

I would propose:

Line Destination Normal Lines Visual Lines
Very beginning 0 or Home g0
Very end $ or End or CtrlEnd g$
First non-whitespace ^ or _ or CtrlHome g^
Last non-whitespace g_ g$be
1
  • Thanks for the correction :-) Commented Aug 28, 2022 at 9:24

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.