Move cursor to beginning of non-whitespace characters in a line in Vim
If I understand correctly - from :h ^
:
^ To the first non-blank character of the line.
|exclusive| motion.
(in contrast to 0
, which gets you to the beginning, regardless of whitespace or not)
Instead of pressing ^
you can press _
(underscore) to jump to the first non-whitespace character on the same line the cursor is on.
+
and -
jump to the first non-whitespace character on the next / previous line.
(These commands only work in normal mode, not in insert mode.)
Also possibly useful: +
and -
will move the cursor up or down, respectively, to the first non-blank character.
below is a snippet from by .vimrc^[[1~
is created by pressing ctrl+v
and Home
"jump to first non-whitespace on line, jump to begining of line if already at first non-whitespace
map <Home> :call LineHome()<CR>:echo<CR>
imap <Home> <C-R>=LineHome()<CR>
map ^[[1~ :call LineHome()<CR>:echo<CR>
imap ^[[1~ <C-R>=LineHome()<CR>
function! LineHome()
let x = col('.')
execute "normal ^"
if x == col('.')
execute "normal 0"
endif
return ""
endfunction