romainl / vim-cool Goto Github PK
View Code? Open in Web Editor NEWA very simple plugin that makes hlsearch more useful.
License: MIT License
A very simple plugin that makes hlsearch more useful.
License: MIT License
How to reproduce:
'ignorecase'
and 'smartcase'
/<\Plug\>
and see how only uppercase Plugs are highlighted*
/#
search Plug, until you reach a lowercase "plug" and see how the highlighting incorrectly disappears even though "plug" is a valid targetThis happens due to the strange quirk with *
/#
/gd
where 'smartcase'
doesn't apply to them. Plus search()
always uses smartcase, so there's the inconsistency.
Perhaps I'm missing a bug or flaw with this fix, but you can simply change !search('\%#\zs'.@/,'cnW')
to:
!search((&ignorecase ? '\c' : '').'\%#\zs'.@/,'cnW')
This causes search()
to ignore 'smartcase'
during "star searches".
I have been looking for ages for vim-cool! However, I would like the highlighting when the cursor is on the search term to be optional; I often use search for just two character searches (when there is no good landing spot for F/f/T/t), and in those cases it gets annoying.
I thought about it for a while and I think I have a pretty good workaround for two issues.
First issue is to disable highlighting when using search motion in operator pending mode automatically. For example you may want to delete everything until last parenthesis in
some()
some(so|me()) # | is the cursor
You press d/)$
and remove the text, but now all parenthesis at last column are highlighted on every line.
The second one is I wanted to keep highlighting when doing replacements with *cgnnew...
which is move to the next occurrence of current word, change it to new
and repeat this three times effectively replacing next three matches. Previously I've been disabling highlighting in insert mode (I see that you restore it now upon returning to normal mode) and this removed the highlighting and I couldn't see where would the next replacement be, which made skipping replacements difficult.
So I've stopped disabling highlighting in insert mode and instead used YankTextPost
Event to check if removed text matches search pattern (most probably mean that I've removed it with dgn
) if so don't remove highlighting upon next CursorMove
(which would happen right after the change). If it doesn't I'm checking if the text after the cursor matches the search pattern (means I'm probably deleted it with d/searchstring
). If it is I'm disabling highlight.
let s:disable = 0
fu! HlSearch()
if s:disable
let s:disable = 0
return
endif
silent! if !search('\%#\zs'.@/,'cnW')
call StopHL()
endif
endfu
fu! StopHL()
if v:hlsearch && mode() is 'n'
sil call feedkeys("\<Plug>(StopHL)", 'm')
endif
endfu
fu! Temp()
if matchstr(@", @/) == @"
let s:disable = 1
elseif search('\%#\zs'.@/,'cnW')
call StopHL()
endif
endfu
augroup SearchHighlight
au!
au CursorMoved * if v:hlsearch | call HlSearch() | endif
au TextYankPost * if v:hlsearch | call Temp() | endif
augroup END
If I would press <C-o>
in insert mode and then press search related key like n
vim would insert some of your mappings into buffer which of course isn't what I wanted and not what vim should do.
I don't know if it's possible or not in vim, but you should do this actions that happens after pressing n
atomical, meaning that they should be the whole command.
Kind of a weird edge case, but this occurs when I search *
(or \v*
or \m*
) by itself, or followed by any text.
I think the source of this bug can be found in :help /star
, which says:
... Exception: When "*" is used at the start of the pattern or just after "^" it matches the star character. ...
Here is a minimal init.vim
file that installs fzf.vim
and vim-cool
- I could not reproduce in my experimentation with creating a floating window manually.
cal plug#begin(stdpath('data') . '/plugged')
Plug 'junegunn/fzf.vim'
Plug 'romainl/vim-cool'
let g:fzf_layout = { 'window': { 'height': 0.9, 'width': 0.9 } }
cal plug#end()
To trigger the bug,
fzf
plugin command that will open a floating window, such as :Files
The floating window flickers, then closes.
Sometimes, I want just want to <C-d>
through a document without losing the highlights.
It would be useful to implement a command or option for toggling vim-cool on/off.
:VimCoolToggle
Hi,
I just received this issue. Do you have any possible solutions from your side? I think this fix should be fixed within your plugin.
I want to use :TOhtml
generate html , but this plug will add (StopHL)
in first line.
Is there a way to solve this?
if you are just scrolling with j/k and you go on a empty line, after moving onto a line with text again the cursor won't return to the column it was on previously
When the first match is the very first word of the buffer, and you wrap from the very last match back to it via n, all matches are de-highlighted until you jump to the second match.
Using vim-floaterm in combination with vim-cool breaks vim-floaterm's :FloatermToggle by insert some characters (at least in neovim):
call plug#begin('~/.local/plugged')
Plug 'voldikss/vim-floaterm'
Plug 'romainl/vim-cool',
call plug#end()
nvim -u init.vim
:FloatermToggle
The floating terminal has some characters before and after the shell prompt, as well as the string (StopHL)
The floating terminal only shows prompt without these characters and the string (StopHL)
I like to use the following mapping to keep the cursor at the current word:
nnoremap * *N
When the next match is inside a closed fold, Vim won't highlight the word under the cursor (or any previous word) when I press *
. It does work without vim-cool
.
When I have set hlsearch
set in my vimrc file and I source it, vim-cool highlights the last search. From my quick look, it seems to be triggered by the OptionSet
autocmd. If I commented out set hlsearch
in my vimrc and source it, no highlighting appears. Is there a way to have set hlsearch
in your vimrc without having vim-cool re-highlight last search when I source the file?
set foldopen+=search
is being ignored because the search commands are remapped. maybe something like &foldopen =~ search
to add the zv
mapping?
Hey!
How could I check if a search is in progress, e.g. echo g:is_searching
which would return 1 when colorization is on and 0 otherwise.
I'm doing searches using /{characters}
and while I do see the current match highlighted, I don't see the other ones (i.e. hlsearch
is not turned on automatically).
I've tried disabling all plugins (besides vim-cool and Vundle, of course) but it didn't solve it. I also tried reducing the vimrc to simply vundle+vim-cool and nothing else. Still no luck.
Any idea how I can debug this? Thanks in advance.
I have installed vim-cool using Vundle by adding the line:
Plugin 'romainl/vim-cool'
to my .vimrc and running from command line:
$ vim +PluginInstall +qall
My problem is that when I start Vim, I get:
$ vim .vimrc
Error detected while processing /home/essett/.vim/bundle/vim-cool/plugin/cool.vim:
line 19:
E216: No such group or event: OptionSet hlsearch call <SID>PlayItCool(v:option_old, v:option_new)
line 24:
E216: No such event: OptionSet highlight let s:saveh = &highlight
Press ENTER or type command to continue
My vim version is:
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:42:57)
Included patches: 1-52
Extra patches: 8.0.0056
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 -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -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
Anyone have an idea what is going on?
vim-slash
has this feature and it's useful, currently vim-slash
has an issue with *
.
Would you consider implement this feature for vim-cool
?
I want to disable hlsearch
when leaving the search commandline when pressing <Esc>
.
Therefore I have following search related setup in my vimrc:
if has('patch-8.0.1206') || has('nvim-0.2.3')
augroup Hlsearch
autocmd!
autocmd CmdlineEnter /,\? :set hlsearch
augroup END
endif
cnoremap <silent><expr> <Esc> getcmdtype() == "/" \|\| getcmdtype() == "?" ? "<Esc>:set nohlsearch<CR>" : "<Esc>"
It works, but vim-cool throws an error:
Error detected while processing function <SNR>47_PlayItCool:
line 16:
E31: No such mapping
line 17:
E31: No such mapping
Do you have a clue what is going wrong?
I love this plugin, but I'm having issues with it dumping a bit of text <Plug>(StopHL)
every time I use c, a, or i to enter insert mode from a highlighted search state - it also doesn't seem to run StopHL, which I'm assuming would cut the highlights. Full reproduction:
vim myfile
/a # Search for anything, letter a works
(n*|N*) # Look around a bit, find the a to edit
...from here, any of the following:
ce # Replace word inserts the above Plug text
i # Drops into insert mode and inserts Plug
a # Same as i really
Just wanted to report it in case it hasn't been noticed and if you're still accepting bug reports.
Technical bits
Using cool.vim from master branch of repo as of yesterdayish
OS: Ubuntu 16.04
vim --version header:
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:44:48)
Included patches: 1-1689
Extra patches: 8.0.0056
Thanks to guys from neovim I've found a way to automatically turn off search highlight when it's no longer needed (for me).
Notice how I check if the cursor is on something that have been searched previously. In your plugin you're using if expand("<cword>") =~ @/
which wouldn't work if someone searched for more than one word.
So in case someone is wondering this would turn off highlight if you've moved cursor with anything except next/previous match motion or if you've entered insert mode (in operator pending mode also, yey!)
noremap <expr> <Plug>(StopHL) execute('nohlsearch')[-1]
noremap! <expr> <Plug>(StopHL) execute('nohlsearch')[-1]
fu! HlSearch()
let s:pos = match(getline('.'), @/, col('.') - 1) + 1
if s:pos != col('.')
call StopHL()
endif
endfu
fu! StopHL()
if !v:hlsearch || mode() isnot 'n'
return
else
sil call feedkeys("\<Plug>(StopHL)", 'm')
endif
endfu
augroup SearchHighlight
au!
au CursorMoved * call HlSearch()
au InsertEnter * call StopHL()
augroup end
Hello,
I noticed that I always get padded append when doing a visual-block append (:he v_b_A
) and managed to track it down to the setpos
call in the Cooler()
function in this plugin.
I'm guessing that calling setpos
is seen as movement which forces the appended text to be padded to the longest line. This may be a bug in Vim.
One workaround is to check if the cursor has actually moved before calling setpos
. e.g.
let cur_cursor = exists("*getcurpos") ? getcurpos() : getpos(".")
if cur_cursor != save_cursor
call setpos('.', save_cursor)
endif
But I'm not sure if you actually need to save and restore the cursor position. I don't see anything in that function that might move the cursor. So perhaps it could just be removed. I have removed the save/restore of cursor position in my local copy and it seems to be working fine.
Why do you say that this plugin works only with vim
? I've installed it and it works pretty well with neovim
.
I use the below snippet to use a visual selection to search for a string, however it seems to conflict with vim-cool and ends up disabling the hlsearch on usage.
I tried appending :set hls<CR>
at the end of the snippet but I am guessing there must be some sort of timeout thing that this plugin is using to set hlsearch after? However I think it also struggles with state, because I have to press n
twice to see the highlighted results. Is there a way I can work around this?
" Search for selected text
vnoremap <silent> <c-s> :<C-U>
\ let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\ gvy/<C-R><C-R>=substitute(escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\ :call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\ let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\ gvy?<C-R><C-R>=substitute(
\ escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\ gV:call setreg('"', old_reg, old_regtype)<CR>
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.