The reason that o
works the way it does is that, with autoindent
or smartindent
set, it will insert whitespace in order to match the indentation of the previous line.
When you move downwards in normal mode without entering insert mode, the line remains empty and no text is added, so the cursor moves to the start of the line.
The simplest way to achieve your goal is to:
Accept the fact that when you move to an empty line in normal mode the cursor will move to the start of the line, and
Use a more sophisticated method of auto indentation, and start editing the line by typing either S
or cc
. For the language in your screenshot (Go?) 'cindent'
should work fine, and when it is set S
or cc
on an empty line will insert indent as you desire, but even better than this would be to use Vim's included 'indentexpr'
for this language. You can do this by allowing Vim to set up indentation when it sets the filetype, which you can achieve by adding the following line to your .vimrc
:
filetype plugin indent on
With this in place, 'indentexpr'
will be set to GoIndent(v:lnum)
when you start editing a Go file, and using cc
or S
on an empty line will insert the appropriate indent.
See :help 30.3
for more details on automatic indenting.
set virtualedit=all
, and you can also start editing on "indent" column withS
orcc
.S
andcc
deletes the line for me?set virtualedit=all
doesn't go to the indentation level, i.e.fmt.Println(..)
in my GIF.S
orcc
when you are on the blank line. The problem is, as Matt suggests, there is nothing there for the cursor to be on, but there will be spaces/tabs inserted when entering insert mode (in some cases).set list listchars^=trail:.
is useful for seeing this.virtualedit
allows your cursor to move even where there is not textnnoremap <leader>j ^y0jpa
. (That's a quick approach that works if the next line is really blank...ie. not filled with whitespace.)