New answers tagged

2

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 ...


2

I assume "doesn't hold the cursor" applies to the corner case when the cursor is at the end of the line and virtualedit is empty (then <esc> will move cursor one position backward, to the last existing character). That's often an issue for insert-mode mappings. There's :h i_ctrl-\_ctrl-o which executes one normal mode command without touching the ...


1

That's a bell (a visual bell). You can turn off bells for Esc in normal mode using belloff: *'belloff'* *'bo'* 'belloff' 'bo' string (default "") global Specifies for which events the bell will not be rung. It is a comma separated list of items. For each item that is present, the bell will be silenced. ...


0

To insert a char at the end of a word (instead of at the cursor position), use nnoremap <C-a> a <ESC>r This maps to Ctrl + a, you can map it to anything else of course. I have the two in my .vimrc just so I don't hustle much :) " Insert char at cursor position nnoremap <C-i> i <ESC>r " Append char after cursor position nnoremap &...


3

Yes, just use the <C-O> keystroke to temporarily leave insert mode for a single command. You can then run :w<CR> to write the file and you'll be back to insert mode. You can use that to create a mapping in insert mode and assign that to a key combination such as <F3> or <C-W>, using: inoremap <F3> <C-O>:w<CR> ...


2

If you're looking to completely disable folding (i.e. open all folds) while typing, see D. Ben Knoble's answer. If you'd just like to prevent Vim from opening and closing folds based on syntax while typing, leaving closed folds closed, check out Vim tip "Keep folds closed while inserting text" or the FastFold plugin. These use a variation on that theme ...


2

Sure, just disable folding in insert mode, and restore it when you leave: augroup folds au! au InsertEnter * let w:oldfen = &l:foldenable \| set nofoldenable au InsertLeave * \ if exists('w:oldfen') \ let &l:foldenable = w:oldfen \ unlet w:oldfen \ endif augroup END


4

Neovim's terminal has "a specialty": a mouse click automatically switches it to "Terminal-Normal" mode. (BTW. That's not a case for Vim, so it does not suffer from this issue.) So it won't work from <LeftMouse>, but we can map <LeftRelease> instead: if has('nvim') augroup terminal_setup | au! autocmd TermOpen * nnoremap <buffer&...


Top 50 recent answers are included