Skip to content

Instantly share code, notes, and snippets.

@PeterRincker
Created March 1, 2019 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeterRincker/1ef979aee5bc0b34c074247e30897105 to your computer and use it in GitHub Desktop.
Save PeterRincker/1ef979aee5bc0b34c074247e30897105 to your computer and use it in GitHub Desktop.
" Cancel searching with `/`, but stay in place
cnoremap <expr> <c-y> <SID>search_cr("\<c-y>", getcmdtype(), getcmdline())
function! s:search_cr(cmd, type, line)
let [key, s:pos, s:search] = [a:cmd, getpos('.'), a:line]
if a:type == '/' || a:type == '?'
let key = "\<c-c>"
augroup search_cr
autocmd!
autocmd CmdlineLeave * execute "autocmd! search_cr" |
\ call setpos('.', s:pos) |
\ call search(s:search, 'bcW')
augroup END
endif
return key
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment