Improved vim star search
- Support
*
search in visual mode - Make the cursor jump to the current match's beginning
- Support
[count]*
command
with vim-plug
Plug 'linjiX/vim-star'
" Or you can use vim-plug's on-demand loading
Plug 'linjiX/vim-star', {'on': '<Plug>(star-'}
vmap <silent> * <Plug>(star-*)
vmap <silent> # <Plug>(star-#)
nmap <silent> * <Plug>(star-*)
nmap <silent> # <Plug>(star-#)
nmap <silent> g* <Plug>(star-g*)
nmap <silent> g# <Plug>(star-g#)
Vim's original behavior of *
will make the cursor jump to the next match's beginning.
This plugin will make the cursor jump to the current match's beginning by default.
If you prefer to keep the default behavior, you can
" Jump to the next match when use * to search
let g:star_start_next_match = 1
Some people prefer keeping the cursor positon unchanged when using *
.
But in this case, I need to press 'N' twice to jump to the previous match
(first 'N' for jumping to the current match, second for the previous match).
That is why I prefer making the cursor to the current match's beginning.
If you still prefer keeping the cursor positon unchanged, you can
" Keep the cursor positon unchanged when use * to search
let g:star_keep_cursor_pos = 1
vim-searchindex is for display the number of search matches & index of a current match.
" Install vim-searchindex
Plug 'google/vim-searchindex'
" Avoid the echo blink by disabling this plugin's echo
let g:star_echo_search_pattern = 0
" Use 'SearchIndex' from vim-searchindex to display the number of search matches & index
vmap <silent> * <Plug>(star-*):SearchIndex<CR>
vmap <silent> # <Plug>(star-#):SearchIndex<CR>
nmap <silent> * <Plug>(star-*):SearchIndex<CR>
nmap <silent> # <Plug>(star-#):SearchIndex<CR>
nmap <silent> g* <Plug>(star-g*):SearchIndex<CR>
nmap <silent> g# <Plug>(star-g#):SearchIndex<CR>