vim - How to map a key in command-line mode but not in search mode -
i want map key in vim in command-line mode not in search mode(with leading /), below:
- map q q
- map w w
sometimes typed wrong command in vim, :q , :w, , want make these wrong commands right.
if can map q q , w w, can make wrong commands right.
i tried cmap q q , cmap w w, affect search mode, i.e. /query /query (actually can't type upper q).
and tried cabbrev q q, , affect search mode.
so, there other command can meet requirement?
thanks.
there number of ways it, , neither straightforward.
with command need take care of attributes:
command! -nargs=* -complete=file -range=% -bang -bar w w command! -bang -bar q q with cabbrev pitfalls described in wiki, need this:
cnoreabbrev w <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'w' : 'w')<cr> i have function purpose:
function! s:cabbrev(from, to) execute 'cnoreabbrev ' . a:from . ' <c-r>=(getcmdtype()==#'':'' && getcmdpos()==1 ? ' . string(a:to) . ' : ' . string(a:from) . ')<cr>' endfunction with cmap need <expr> qualifier, , need more or less same precautions cabbrev:
cnoremap <nowait> <expr> w getcmdtype() ==# ':' && getcmdpos() == 1 ? 'w' : 'w' the safest cabbrev way.
Comments
Post a Comment