Last active
September 2, 2015 18:55
-
-
Save qstrahl/638780bfba2262bb1d2b to your computer and use it in GitHub Desktop.
safesearch.vim: start a search safely, without the risk of clobbering the last pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"" safesearch: start a search in vim without overwriting the last pattern | |
"" trivial? Yup. Useful? Ehhh maybe. | |
function! s:SafeSearch () | |
augroup SafeSearch | |
autocmd CursorMoved,CursorMovedI,InsertEnter,CursorHold,CursorHoldI,CmdWinEnter,CmdWinLeave,WinEnter,WinLeave * call <SID>Teardown() | |
augroup END | |
let s:pattern = @/ | |
return '/' | |
endfunction | |
function! s:Teardown() | |
call histdel('search', -1) | |
let @/ = s:pattern | |
augroup SafeSearch | |
autocmd! | |
augroup END | |
endfunction | |
noremap <expr> <Plug>(SafeSearch) <SID>SafeSearch() | |
map gj <Plug>(SafeSearch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment