Closed fuelen closed 3 years ago
Hi. Yeah, actually I also feel the same as you... If there is a good suggestion, I’m ok to change it:) Changing marking color is also fine.
#468080
#438db1
maybe something like this?
Just tried to work with these colours - not much better :disappointed:
I've been using the following:
Every time the cursor moves in normal mode, check whether it is in a highlighted search match.
Cursor
highlight group to a custom one (CursorSearch
) which stands out.Cursor
highlight group to a copy of the original.Obviously adjust CursorSearch
to meet your needs.
function! CursorInSearchMatch(...)
if !&hlsearch || !v:hlsearch | return 0 | endif
let [match,start,stop] = matchstrpos(getline('.'), @/, (a:0 ? a:1 : 0))
if empty(match) | return 0 | endif
let col = getcurpos()[2]
if col <= start | return 0 | endif
if col <= stop | return 1 | endif
return CursorInSearchMatch(stop)
endfunction
let s:group = synIDtrans(hlID('Cursor'))
let s:cursor_gui_fg = synIDattr(s:group, 'fg', 'gui')
let s:cursor_gui_bg = synIDattr(s:group, 'bg', 'gui')
let s:cursor_cterm_fg = synIDattr(s:group, 'fg', 'cterm')
let s:cursor_cterm_bg = synIDattr(s:group, 'bg', 'cterm')
execute 'highlight CursorOriginal guifg='.s:cursor_gui_fg.' guibg='.s:cursor_gui_bg.' ctermfg='.s:cursor_cterm_fg.' ctermbg='.s:cursor_cterm_bg
" FIXME doesn't work in terminal vim
highlight CursorSearch guifg=red guibg=white ctermfg=160 ctermbg=231
autocmd CursorMoved * if CursorInSearchMatch() | highlight! link Cursor CursorSearch | else | highlight! link Cursor CursorOriginal | endif
Unfortunately CursorSearch
's highlighting doesn't work for me in terminal MacVim, whether or not termguicolors
is set – any tips would be welcome.
Update: here is a slightly different approach where the whole current search match is highlighted slightly differently (specifically, with the StatusLineTerm
highlight):
" Returns [start, stop] if the cursor is in a search match, where start and
" stop are column numbers.
" Returns [0, 0] if the cursor is not in a search match.
function! CursorInSearchMatch(...)
if !&hlsearch || !v:hlsearch | return [0,0] | endif
let [match,start,stop] = matchstrpos(getline('.'), @/, (a:0 ? a:1 : 0))
if empty(match) | return [0,0] | endif
let col = getcurpos()[2]
if col <= start | return [0,0] | endif
if col <= stop | return [start,stop] | endif
return CursorInSearchMatch(stop)
endfunction
let s:current_search_pos = []
let s:current_search_match = 0
function! UpdateCursor()
let [start, stop] = CursorInSearchMatch()
if [start, stop] != [0, 0]
if s:current_search_pos != [start, stop]
let s:current_search_pos = [start, stop]
if s:current_search_match | call matchdelete(s:current_search_match) | endif
let s:current_search_match = matchaddpos('StatusLineTerm', [[line('.'), start+1, stop-start]])
endif
else
let s:current_search_pos = []
if s:current_search_match | call matchdelete(s:current_search_match) | endif
let s:current_search_match = 0
endif
endfunction
autocmd CursorMoved * call UpdateCursor()
I've extracted this to a plugin: https://github.com/airblade/vim-current-search-match.
@airblade I've tried it and left an issue in your repo
vim-current-search-match
plugin works fine for me. I'll close the issue.
Thank you for help!
Hello! Thank you for this beautiful theme!
I find this combination of colours unreadable. It is very hard to find a cursor Any suggestions? :)