Created
November 2, 2013 14:57
-
-
Save orange-tangerine/7279735 to your computer and use it in GitHub Desktop.
Vimscript function to make searching slightly more visible
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
"remap the searching commands to my new function. The function is called first, then immediately calls itself | |
"after the search is finished. This allows me to get the advantage of incsearch being unimpeded by anything | |
noremap <space> :call DoSearch('search')<Cr>/ | |
noremap n :call DoSearch('search')<Cr>n | |
noremap N :call DoSearch('search')<Cr>N | |
noremap * :call DoSearch('search')<Cr>* | |
noremap # :call DoSearch('search')<Cr># | |
noremap ? :call DoSearch('search')<Cr>? | |
"DoSearch takes a 'command' that specifies whether it needs to call itself again after exeution | |
function! DoSearch(command) | |
"if it has been called with 'search' | |
if a:command == 'search' | |
"remember wrap set/not set, turn off wrapping | |
if &wrap | |
let g:waswrap = 1 | |
else | |
let g:waswrap = 0 | |
endif | |
set nowrap | |
"set highlighting and our cursorline/column, since cursor not visible during function execution | |
"my highlighting for cursorline is light grey | |
set hls | |
hi CursorLine cterm=underline ctermbg =0 | |
hi CursorColumn cterm=NONE ctermbg=0 | |
set cursorline cursorcolumn | |
redraw | |
"This sets the autocommand CursorHold to execute after 1ms, calling DoSearch | |
setl updatetime=1 | |
augroup flicker_command | |
au! | |
au CursorHold * call DoSearch('iterate') | |
augroup end | |
elseif a:command == 'iterate' | |
"kill the autocommand and set the updatetime to normal setting | |
setl updatetime=4000 | |
au! flicker_command | |
augroup! flicker_command | |
augroup end | |
"get a character from the user | |
let c = nr2char(getchar()) | |
"while it is one of the search forward/back commands, just keep searching forward | |
while c =~ '\v^(n|N)$' | |
execute "normal! ".c | |
redraw | |
let c = nr2char(getchar()) | |
endwhile | |
"revert wrapping to previous state | |
if g:waswrap | |
set wrap | |
endif | |
"if we want to do any other key, temporarily turn off highlighting (so I can use :%s) | |
let str = ":nohls\<Cr>" | |
call feedkeys(str) | |
call feedkeys(c) "pass the user's non-searching key to vim | |
set nocursorline nocursorcolumn | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment