Vim: Shortcut to move to beginning of next line / end of previous line?
Solution 1
To move to the beginning of the next line, hit Enter
. See :help <CR>
.
To make right
and l
wrap to the beginning of the next line, add >
and l
to the 'whichwrap' option, e.g.,
:set whichwrap+=>,l
Similarly, to make left
and h
wrap to the end of the previous line, add <
and h
to the 'whichwrap' option, e.g.,
:set whichwrap+=<,h
See :help 'whichwrap'
.
I don't know of a single-key shortcut to move to the end of the previous line, but with those 'whichwrap' settings, 0h
or 0left
would work, and you could possibly map either of those to some key you don't often use.
Solution 2
For your first question, I am not aware of any shortcut that will do what you want, but you could map it. For example:
:nnoremap <c-p> k$
:nnoremap <c-n> j0
For your second question, look at ":help 'whichwrap'
" (with the single quotes as part of the command).
Solution 3
+
/-
let you move up and down on the start of every line. $
will go to the end of line, and you'll stick there with k
/j
.
Related videos on Youtube
Kevin H. Lin
Updated on September 18, 2022Comments
-
Kevin H. Lin over 1 year
Is there any shortcut in vim to move to the beginning of the next line or the end of the previous line? Is there any way to do it without having to use
$
or^
?Also, is there any way to make it so that if I hit
right
orl
at the end of a line, it moves to the beginning of the next line? Similarly forleft
orh
at the beginning of a line to move to the end of the preceding line? I'm using MacVim if that makes any difference. -
Heptite almost 12 yearsPressing enter goes to the beginning of the next line, not the end. (Which is what the OP wanted, but your answer reversed the terminology.)
-
garyjohn almost 12 years@Heptite: That's what I meant. Bad fingers! Thank you for catching that. Fixed.
-
Kevin H. Lin almost 12 yearsThank you! Also I just figured out that to get this to work in insert mode, you can do
set whichwrap+=[,]
. -
G-Man Says 'Reinstate Monica' about 4 yearsThe OP knows about
$
(and^
) and said that he does not want to use them. -
DZet about 4 yearsgood point, -/+ still stands though