
How to prevent the command-line "flash" in keymaps
I'm working on a keymap that generates a half-completed command-line string from buffer context, namely oil.nvim, akin to vim-vinegar behaviour. Right now I have something like:
nnoremap <buffer> . :<C-U><Space><C-R>=<SID>escaped(line('.'),line('.')-1+v:count1)<CR><Home>
It works but there is a kind of cosmetic issue where the command-line would briefly flashes the expression expansion (something like =<SNR>23_escaped(...)) before being replaced by the final string:
It's not breaking anything but still visually distracting
Is there any way to avoid this flash entirely? I have tried <silent> but that seems to break the keymap. Attached my full after/ftplugin/oil.vim if that matters.
let s:oil = luaeval("require('oil')")
nnoremap <buffer> . :<C-U><Space><C-R>=<SID>escaped(line('.'),line('.')-1+v:count1)<CR><Home>
xnoremap <buffer> . <Esc>:<Space><C-R>=<SID>escaped(line("'<"),line("'>"))<CR><Home>
nmap <buffer> ! .!
xmap <buffer> ! .!
function s:escaped(line1, line2) abort
return range(a:line1, min([line('$'), a:line2]))
\->map({ _, n -> fnameescape(s:line_get_relpath(n)) })
\->join(' ')
endfunction
function s:line_get_relpath(n) abort
let entry = s:oil.get_entry_on_line(0, a:n)
call assert_notequal(v:null, entry, $'got nil oil entry on line {a:n}')
let fullpath = s:oil.get_current_dir() .. entry.name
let relpath = fnamemodify(fullpath, ':.')
return fullpath is# relpath ? fullpath : './' .. relpath
endfunction