google / vim-searchindex Goto Github PK
View Code? Open in Web Editor NEWvim-searchindex: display number of search matches & index of a current match
License: Apache License 2.0
vim-searchindex: display number of search matches & index of a current match
License: Apache License 2.0
Hello, thank you for this useful plugin.
Does it make sense to print matches like this:
/<pattern here> (1 of n)
instead of:
[1/n] /<pattern here>
I'm using this plugin with https://github.com/haya14busa/incsearch.vim and the matches seem to flicker a lot when using the current display, maybe because it has to switch from /<pattern here>
to [1/n] /<pattern here>
.
I believe /<pattern here> (1 of n)
is more consistent with how Vim works right now, for example the quickfix list is using this: qf (1 of n)
.
I have a shortmess+=c
in my configuration, but I still get "Pattern not found" error which I need to click enter to dismiss. This wasn't the case without this plugin.
I am using the plugin from master. Case-insensitive match is not working for me though I have set ic
in my .vimrc
.
my .vimrc:
set nu
set ai
set incsearch
set hlsearch
set expandtab
set ts=4
set shiftwidth=4
set cindent
set ic
set wic
set splitright
"set bg=dark
setlocal spell spelllang=en_gb
set whichwrap+=<,>,h,l,[,]
set shell=/bin/bash
set backspace=indent,eol,start
"set mouse=a
"set cursorline
"set colorcolumn=140
"highlight chars beyond 80 lines in red
"highlight OverLength ctermbg=red ctermfg=white guibg=#592929
"match OverLength /\%81v.\+/
"auto-remove trailing whitepaces
autocmd BufWritePre * :%s/\s\+$//e
"format pasted text automatically
":nnoremap p ]p
":nnoremap <c-p> p
syntax enable
set hidden
"noremap <F8> <Esc>:syntax on<CR>
"inoremap <F8> <C-o>:syntax on<CR>
"allow saving of files as sudo when I forgot to start vim using sudo.
"cmap w!! w !sudo tee > /dev/null %
command W w !sudo tee "%" > /dev/null
set t_Co=256
"Transparent bg
"hi Normal guibg=NONE ctermbg=NONE
"colorscheme solarized8_dark_high
colorscheme solarized8_light_high
"autocmd BufEnter *.h,*.c colorscheme despacio
autocmd BufEnter *.h,*.c,Makefile* set noexpandtab
autocmd BufEnter *.h,*.c set ts=8
autocmd BufEnter *.h,*.c set shiftwidth=8
"autocmd BufEnter *.py colorscheme gruvbox
"autocmd BufEnter *.py set bg=dark
"Transparent bg
"autocmd BufEnter *.h,*.c,*.py hi Normal guibg=NONE ctermbg=NONE
let Tlist_WinWidth = 10
let NERDTreeDirArrows=0
nmap <F7> :TrinityToggleTagList<CR>
nmap <F12> :TrinityToggleNERDTree<CR>
let g:LargeFile=3
"Shortcut for Highlight.vim <^a>
:map <silent> <C-a> :normal! gv"zy<CR>
"vim-bookmarks config
highlight BookmarkSign ctermbg=NONE ctermfg=160
highlight BookmarkLine ctermbg=194 ctermfg=NONE
let g:bookmark_highlight_lines = 1
let g:bookmark_auto_save = 0
"ctrlp config
"let g:ctrlp_extensions = ['tag']
"let g:ctrlp_map = '<c-p>'
"let g:ctrlp_cmd = 'CtrlPTag'
"vim system copy
let g:system_copy#copy_command='xclip -sel clipboard'
let g:system_copy#paste_command='xclip -sel clipboard -o'
cnoreabbrev rg Rg
cnoreabbrev hex %!xxd
let g:nnn#set_default_mappings = 0
let g:nnn#layout = 'tabedit'
nnoremap <leader>n :NnnPicker '%:p:h'<CR>
if has("patch-8.1.0360")
set diffopt+=internal,algorithm:patience
endif
vim version details:
$ vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jan 07 2019 10:34:10)
Included patches: 1-700
Modified by [email protected]
Compiled by [email protected]
Huge version without GUI. Features included (+) or not (-):
+acl +extra_search +mouse_netterm +tag_old_static
+arabic +farsi +mouse_sgr -tag_any_white
+autocmd +file_in_path -mouse_sysmouse -tcl
+autochdir +find_in_path +mouse_urxvt +termguicolors
-autoservername +float +mouse_xterm +terminal
-balloon_eval +folding +multi_byte +terminfo
+balloon_eval_term -footer +multi_lang +termresponse
-browse +fork() -mzscheme +textobjects
++builtin_terms +gettext +netbeans_intg +textprop
+byte_offset -hangul_input +num64 +timers
+channel +iconv +packages +title
+cindent +insert_expand +path_extra -toolbar
-clientserver +job -perl +user_commands
-clipboard +jumplist +persistent_undo +vartabs
+cmdline_compl +keymap +postscript +vertsplit
+cmdline_hist +lambda +printer +virtualedit
+cmdline_info +langmap +profile +visual
+comments +libcall -python +visualextra
+conceal +linebreak +python3 +viminfo
+cryptv +lispindent +quickfix +vreplace
+cscope +listcmds +reltime +wildignore
+cursorbind +localmap +rightleft +wildmenu
+cursorshape -lua -ruby +windows
+dialog_con +menu +scrollbind +writebackup
+diff +mksession +signs -X11
+digraphs +modify_fname +smartindent -xfontset
-dnd +mouse +startuptime -xim
-ebcdic -mouseshape +statusline -xpm
+emacs_tags +mouse_dec -sun_workshop -xsmp
+eval +mouse_gpm +syntax -xterm_clipboard
+ex_extra -mouse_jsbterm +tag_binary -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -fdebug-prefix-map=/build/vim-ZE_R5I/vim-8.1.0700=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lnsl -lselinux -lacl -lattr -lgpm -ldl -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lm
When using folds, match counts may sometimes be off. One specific example is when searching inside a function, then folding this function and searching for the same term near the fold.
This is because searchindex uses Ex command :s///n
to count matches, and expects to get results exactly for the specified range. However, Vim silently expands the range to adjacent folds, breaking our assumption. I've asked on StackOverflow for a way to override this annoying behavior: http://stackoverflow.com/questions/33190754/vim-ran-ex-command-on-specified-lines-ignoring-folds.
If there's no way to do that, we should provide an option to disable caching. Then matches would be recalculated each time, giving a correct (or at least reasonable) result. With caching enabled, any kind of error tends to accumulate.
The demo image is nice, but it would showcase the plugin's functionality better if it was animated, like the demo image in the README for https://github.com/Valloric/YouCompleteMe is.
I'd like a way to disable and re-enable the custom search messages for working around possible bugs and comparing plugin behavior to vim's default behavior for troubleshooting.
For instance:
/it<CR>
[1/7] /it
:SetSearchIndex OFF
/it<CR>
/it
:SetSearchIndex ON
/it<CR>
[1/7] it
A lot of features from https://github.com/haya14busa/vim-asterisk are also implemented here, but not all. searchindex overrides the mappings in the .vimrc for vim-asterisk. Is there any way to have both working at once? I tried disabling searchindex_improved_star, but that doesn't prevent the mappings from being overwritten.
It would be great to see if we could add this feature natively into vim so it could have less overhead and fewer quirks. I filed FR vim/vim#453 in the vim tracker to request it.
Is it possible to have it automatically update the number of matches as you type out the regex search query? As opposed to it only showing the number of matches when you hit enter?
Issue #11 may have been alluding to this issue.
Basically, the msg
variable is never displayed in the command line. However, if the anything else is echoed right before or after it, both are displayed.
function! s:PrintMatches()
let dir_char = v:searchforward ? '/' : '?'
if line('$') > g:searchindex_line_limit
let msg = '[MAX] ' . dir_char . @/
else
" If there are no matches, search fails before we get here. The only way
" we could see zero results is on 'g/' (but that's a reasonable result).
let [current, total] = searchindex#MatchCounts()
let msg = '[' . current . '/' . total . '] ' . dir_char . @/
endif
echo "here"
echo msg
" foldopen+=search causes search commands to open folds in the matched line
" - but it doesn't work in mappings. Hence, we just open the folds here.
if &foldopen =~# "search"
normal! zv
endif
endfunction
The above will result in the following displayed in the command line (the search string I used was "echo msg"):
If instead I put the echo "here"
right after echo msg
, this is the result:
Thing is it works just fine if I run Vim in a terminal. It's just in MacVim that the problem occurs.
I have no other plugins running (not even Pathogen).
I often want to search for the word under the cursor without losing my cursor position. I suspect I'm not the only person who does this (http://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump).
Because of the way vim-searchindex maps *, I can't seem to map this in my vimrc. It would be nice if that option were supported within the plugin.
Without this plugin, if I have folding enabled, moving to the next search (including initiating a search) will open all folds necessary to expose the matched text. With the plugin, the folds don't open; the cursor moves to the correct fold containing the matched text but doesn't open any folds.
If I search "foo", I get correctly the match indicator (i.e.: [1/10]), but hitting "n" for the next match causes my command line to get cleaned and replaced with "/foo".
Is there something to configure to avoid this behaviour?
I don't use a plugin manager (no git submodules, or anything)
git clone [email protected]:google/vim-searchindex.git
cp vim-searchindex/plugin/* ~/.vim/plugin/
cp vim-searchindex/doc/* ~/.vim/doc/
rm -rf vim-searchindex/
open vim, type q:
, then see error:
Error detected while processing CmdwinEnter Auto commands for "*":
E117: Unknown function: getcmdwintype
Error detected while processing CmdwinEnter Auto commands for "*":
E15: Invalid expression: getcmdwintype() =~ '[/?]' | nmap <silent> <buffer> <CR> <CR><Plug>SearchIndex| endif
I googled for the 2nd line of the error message but it isn't clear to me what's wrong. In case it is helpful, here's my vim --version
output:
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 2 2014 19:39:47)
Included patches: 1-52
Modified by [email protected]
Compiled by buildd@
Huge version with GTK2-GNOME GUI. Features included (+) or not (-):
+acl +farsi +mouse_netterm +syntax
+arabic +file_in_path +mouse_sgr +tag_binary
+autocmd +find_in_path -mouse_sysmouse +tag_old_static
+balloon_eval +float +mouse_urxvt -tag_any_white
+browse +folding +mouse_xterm +tcl
++builtin_terms -footer +multi_byte +terminfo
+byte_offset +fork() +multi_lang +termresponse
+cindent +gettext -mzscheme +textobjects
+clientserver -hangul_input +netbeans_intg +title
+clipboard +iconv +path_extra +toolbar
+cmdline_compl +insert_expand +perl +user_commands
+cmdline_hist +jumplist +persistent_undo +vertsplit
+cmdline_info +keymap +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak +python +viminfo
+cscope +lispindent -python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con_gui +lua +rightleft +windows
+diff +menu +ruby +writebackup
+digraphs +mksession +scrollbind +X11
+dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent +xim
+emacs_tags +mouseshape -sniff +xsmp_interact
+eval +mouse_dec +startuptime +xterm_clipboard
+ex_extra +mouse_gpm +statusline -xterm_save
+extra_search -mouse_jsbterm -sun_workshop +xpm
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/harfbuzz -pthread -DORBIT2=1 -D_REENTRANT -I/usr/include/libgnomeui-2.0 -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-keyring-1 -I/usr/include/libgnome-2.0 -I/usr/include/libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gtk-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/x86_64-linux-gnu/gnome-vfs-2.0/include -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/orbit-2.0 -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/libxml2 -I/usr/include/pango-1.0 -I/usr/include/gail-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/cairo -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/libpng12 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -I/usr/include/tcl8.6 -D_REENTRANT=1 -D_THREAD_SAFE=1 -D_LARGEFILE64_SOURCE=1
Linking: gcc -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lglib-2.0 -lfreetype -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lfreetype -lgconf-2 -lgthread-2.0 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lnsl -lselinux -lacl -lattr -lgpm -ldl -L/usr/lib -llua5.2 -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.18/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lieee -lm -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm -L/usr/lib
Support for centring the current search result using
nnoremap n nzz
nnoremap N Nzz
it does work in vim, but does not work in mcvim
Inside the function s:MatchesInRange()
, this command is executed:
silent! execute a:range . 's///en' . gflag
I think it has several undesired effects, some of which could be mitigated.
It adds an entry in the jumplist: this could be solved with :keepjumps
:
silent! execute 'keepjumps '.a:range . 's///en' . gflag
It alters the [
and ]
marks: this could be solved by saving/restoring the marks:
let marks_save = [ getpos("'["), getpos("']") ]
...
silent! execute a:range . 's///en' . gflag
...
call setpos("'[", marks_save[0])
call setpos("']", marks_save[1])
It makes you lose some metacharacters and flags like ~
and &
(see :h :&
and :h :~
).
For this issue, I have no idea how to fix it. I've tried to think about mechanisms to save and restore them, but they are not reliable.
You would need to find a way to execute the substitution without Vim logging anything, but I don't know if it's possible.
Because of the following cmap
in this plugin, the vim debug mode could not work in some case.
cmap <expr> <CR> <SID>handle_cr()
If remove this map, there won't be such problem.
Execute :debug 1
and then press q
, the debug mode could not be quitted. Following message will be shown:
When I use the command ? or / to do searching, searchindex such as [4/5] does not show immediately . After I press N or n, the searchindex such as [4/5] will appear immediately.
Is there a way that help me to achieve this goal, show searchindex after doing searching.
Thanks for helping me.
Hey hey,
Love this plugin, it is the best of its kind!
I just wanted to point out that I found the wording in the first line of the README quite awkward. I have to sign the google CLA to submit a PR and I don't want to do that right now.
I just suggest your change the first line to:
"This plugin shows how many times a search pattern occurs in the current ...
"
It would be great if the search under the cursor was highlighted in a different color than the other.
First I used this script but rightly n
and N
are now handled by searchindex.
function! HLNext (blinktime)
highlight RedOnRed ctermfg=red ctermbg=red
let [bufnum, lnum, col, off] = getpos('.')
let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/))
echo matchlen
let ring_pat = (lnum > 1 ? '\%'.(lnum-1).'l\%>'.max([col-4,1]) .'v\%<'.(col+matchlen+3).'v.\|' : '')
\ . '\%'.lnum.'l\%>'.max([col-4,1]) .'v\%<'.col.'v.'
\ . '\|'
\ . '\%'.lnum.'l\%>'.max([col+matchlen-1,1]) .'v\%<'.(col+matchlen+3).'v.'
\ . '\|'
\ . '\%'.(lnum+1).'l\%>'.max([col-4,1]) .'v\%<'.(col+matchlen+3).'v.'
let ring = matchadd('RedOnRed', ring_pat, 101)
redraw
exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
call matchdelete(ring)
redraw
endfunction
Maybe not all this stuff, different color is enough
Custom star commands (*, #) doesn't work well with haya14busa/incsearch.vim with the following mappings:
map / (incsearch-forward)
map ? (incsearch-backward)
map g/ (incsearch-stay)
I have both plugins installed, and repeatedly pressing * or # selects the next / previous word instead of word under cursor, as shown below.
Every time more than one line should be printed, vim asks you to press enter.
The 'shortmess' option of vim let you choose how to shorten the various printed values in the output, to let the user short the output printed to less than one line, and avoid pressing enter every time more than one line is needed to be printed.
The 'T' option of shortmess enables vim to shorten any string longer than one screen line, replacing the middle of the string with '...'.
In this plugin, since the print is happening with simple echo, those options are ignored.
Meaning, when the user searches for a string longer than one screen line, the search would include all the string regardless of the value of shortmess and ask the use to press enter.
Hello again,
I just notice an issue when using vim-searchindex with incsearch.vim: when you search for something using /
the index is not shown after pressing enter. All that is shown after pressing enter is /
, if searchindex is not active, /pattern
is shown.
Hopefully this can be fixed, thank you.
repro instructions:
observe the count reads [4/2] rather than [4/4]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.