我想替换cscope的:tnext命令,但它没有按我的预期工作。
1) 下图显示了按预期工作的代码。我可以达到符号的第二个实例。
function MyCounter()
if !exists("s:counter")
let s:counter = 1
echo "script executed for the first time"
else
let s:counter = s:counter + 1
echo "script executed " . s:counter . " times now"
endif
endfunction
nmap <space>w :ls<CR>
nmap <space>i :call MyCounter()
nmap <space>n :cs find s <C-R>=expand("<cword>")<CR><CR>2<CR>
2) 以下代码不起作用
function MyCounter()
if !exists("s:counter")
let s:counter = 1
echo "script executed for the first time"
else
let s:counter = s:counter + 1
echo "script executed " . s:counter . " times now"
endif
endfunction
nmap <space>w :ls<CR>
nmap <space>i :call MyCounter()
nmap <space>n :cs find s <C-R>=expand("<cword>")<CR><CR><C-R>=str2nr(s:counter)<CR>
1和2代码段之间的差异为=str2nr(s:counter)即在用户按下n个时动态计算n个符号实例
在按空格+n之前,我总是按空格+i
请告诉我为什么第二段代码不起作用。
您可以尝试
nmap <space>n :exec "cs find s" expand("<cword>") "| norm" str2nr(s:counter)
您似乎在正常模式下使用<C-R>=str2nr...
,这将不起作用。
免责声明:我还无法测试上述方法是否有效。
编辑
您可能需要使用cscopetag
设置:
*cscopetag* *cst*
If 'cscopetag' set, the commands ":tag" and CTRL-] as well as "vim -t" will
always use |:cstag| instead of the default :tag behavior. Effectively, by
setting 'cst', you will always search your cscope databases as well as your
tag files. The default is off. Examples: >
:set cst
:set nocst
这将为您提供一组使用标签的丰富命令,这些命令可能会为您提供执行所需操作的方法(:tjump
、:tnext
等)
问题是由于尝试排队处理字符而引起的作为表达式评估的结果而获得的。有必要表达式为表达式一(请参见:help :map-<expr>
)或使用CCD_ 6函数。为了便于修改映射,我会建议使用第一种方法,并按如下方式更改映射。
:nnoremap <expr> <space>n ':cs find s '.expand('<cword>')."r".s:counter."rr"