我想为 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 个实例
在按空格+ni 之前总是按空格+i
请告诉我为什么第二个代码片段不起作用。