Skip to content

Instantly share code, notes, and snippets.

@sunjon
Last active May 26, 2017 13:57
Show Gist options
  • Save sunjon/ca9175d43e8435973322e4cafbbb792b to your computer and use it in GitHub Desktop.
Save sunjon/ca9175d43e8435973322e4cafbbb792b to your computer and use it in GitHub Desktop.
Tab through partial HLS
" Tab to cycle through instances of partially complete search pattern {{{
set wildcharm=<Tab>
cnoremap <expr> <Tab> BetterIncSearch('tab')
cnoremap <expr> <S-Tab> BetterIncSearch('stab')
" better incremental search
function! BetterIncSearch(key) abort
if getcmdtype() ==# '/' || getcmdtype() ==# '?'
if (a:key ==# 'tab' && v:searchforward) || (a:key ==# 'stab' && !v:searchforward)
return "\<CR>/\<C-r>/"
else
return "\<CR>?\<C-r>/"
endif
else
if a:key ==# 'tab'
return "\<Tab>"
else
return "\<S-Tab>"
endif
endif
endfunction
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment