highlight_string() 函数

这段摘要包含了博客的关键信息,忽略所有与信息技术无关的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

忘记你之前写的程序,基于我的如下程序做修改,使得整个关键词都能高亮,而不是只高亮首字母:" highlight color highlight BeginEndPair guibg=#00FF00 ctermbg=10 guifg=#000000 ctermfg=0 " Add Ctrl+F2 key mapping with debugging feedback nnoremap <silent> <C-F2> :call HighlightBeginEnd()<CR> " Toggle for debug messages (1 = on, 0 = off) let g:highlight_debug = 1 " Define highlight function with debugging function! HighlightBeginEnd() " Debug: Function started if g:highlight_debug | echom "HighlightBeginEnd() triggered" | endif " Get word under cursor let current_word = expand('<cword>') if g:highlight_debug | echom "Current word: '" . current_word . "'" | endif " Only process 'begin' keyword if current_word !=# 'begin' if g:highlight_debug | echom "Not 'begin' - aborting" | endif return endif if current_word !=# 'end' if g:highlight_debug | echom "Not 'end' - aborting" | endif return endif " Clear previous highlights call clearmatches() if g:highlight_debug | echom "Cleared existing highlights" | endif " Save original cursor position execute "normal! b" let save_pos = getcurpos() if g:highlight_debug | echom "Original position: line " . save_pos[1] . ", col " . save_pos[2] | endif if g:highlight_debug | echom "Original position: line " . save_pos[0] . ", col " . save_pos[0] | endif " Use matchit to find matching end try " Debug: Attempting match jump if g:highlight_debug | echom "Attempting jump to match..." | endif " Jump to matching position " silent! normal! % " echom "use matchit internal func to match" " call matchit#Match_wrapper('',0,0) " execute "normal! %" if g:highlight_debug | echom "call searchpairpos ..." | endif let match_pos = searchpairpos( '\<begin\>', '', '\<end\>', 'nW', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"' ) if g:highlight_debug | echom "call done ..." | endif if g:highlight_debug | echom "New1 position:line " . match_pos[0] . ", col " . match_pos[1] | endif " Check if jump was successful " execute "normal! b" " let match_pos = getcurpos() if match_pos[0] == save_pos[1] && match_pos[1] == save_pos[2] if g:highlight_debug | echom "No match found!" | endif return endif if g:highlight_debug echom "Match found at line " . match_pos[0] . ", col " . match_pos[1] endif " Highlight original begin let begin_hl = matchadd('BeginEndPair', '\%' . save_pos[1] . 'l\%' . save_pos[2] . 'c') if g:highlight_debug | echom "Added begin highlight" | endif " Highlight matching end let end_hl = matchadd('BeginEndPair', '\%' . match_pos[0] . 'l\%' . match_pos[1] . 'c') if g:highlight_debug | echom "Added end highlight" | endif finally " Restore original cursor position call setpos('.', save_pos) if g:highlight_debug | echom "Cursor restored" | endif endtry if g:highlight_debug | echom "Operation completed successfully" | endif endfunction
最新发布
07-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值