1

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 番目のコード スニペットが機能しない理由を教えてください。

4

2 に答える 2

0

この問題は、式の評価の結果として取得された文字を処理するためにキューに入れようとするために発生します。式を式にするか ( を参照:help :map-<expr>)、 feedkeys()関数を使用する必要があります。マッピングの変更を簡単にするために、最初のアプローチを使用して、次のようにマッピングを変更することをお勧めします。

:nnoremap <expr> <space>n ':cs find s '.expand('<cword>')."\r".s:counter."\r\r"
于 2012-03-10T10:08:23.460 に答える
0

あなたは試すことができます

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) 。

于 2012-03-09T21:45:30.977 に答える