Add commands executed in mappings to the command history

1 Point

Romain Lafourcade Romain Lafourcade

4 years ago

The command history only records actual commands, not those that are executed in mappings. This template gives us the possibility to build a command and add it to the command history before executing it.

" template                ||||| <--- customize this part
map <key> :<C-u>let cmd = 'foo'<bar>call histadd("cmd", cmd)<bar>execute cmd<CR>

" example:
xnoremap [I "vy:<C-u>let cmd = 'ilist /' . @v<bar>call histadd("cmd", cmd)<bar>execute cmd<CR>: