Vim notes

Start here

Neovim + Lua

Jumps

I’ve been familiar with c-o and c-i for a while, but I have not used them effectively, some things were missing.

  • gi — Insert text in the same position as where Insert mode was stopped last time in the current buffer.

The following mappings simplify working with relativenumber and <count>j/<count>k:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
" Change j and k to add movements to the jump list.
nnoremap <expr> k (v:count > 1 ? "m'". v:count : '') . 'gk'
nnoremap <expr> j (v:count > 1 ? "m'". v:count : '') . 'gj'
" Change j and k to add movements to the jump list. nnoremap <expr> k (v:count > 1 ? "m'". v:count : '') . 'gk' nnoremap <expr> j (v:count > 1 ? "m'". v:count : '') . 'gj'
" Change j and k to add movements to the jump list.
nnoremap <expr> k (v:count > 1 ? "m'". v:count : '') . 'gk'
nnoremap <expr> j (v:count > 1 ? "m'". v:count : '') . 'gj'

Source: reddit post

inoremap and white spaces

Just found out that white spaces matter in inoremap mappings, the following are not equivalent (notice the space after <Esc>):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
inoremap <c-q> <Esc> :call Quit()<cr>
inoremap <c-q> <Esc>:call Quit()<cr>
inoremap <c-q> <Esc> :call Quit()<cr> inoremap <c-q> <Esc>:call Quit()<cr>
inoremap <c-q> <Esc> :call Quit()<cr>
inoremap <c-q> <Esc>:call Quit()<cr>

The extra white space after <Esc> was causing the command to fail when positioned on the last character of a file. I don’t know why, but it works fine after removing the space.


Posted

in

,

by

Tags: