cscope の :tnext コマンドを置き換えたいのですが、期待どおりに動作しません。
1) 下の図は、期待どおりに動作しているコードを示しています。シンボルの 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>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 インスタンスが動的に計算されます。
space+ni を押す前に、必ず space+i を押してください
2 番目のコード スニペットが機能しない理由を教えてください。