バッファのファイルパスを取得するには?

バッファのファイルパスを取得するには?

私は%レジスタに現在のバッファのフルパスが含まれていることを知っています。しかし、他のバッファのフルパスをその番号で取得する方法は?

VIMにそのような機能/コマンドがありますか?

私がこの質問をどう思いましたかを説明したいと思います。

2つのバッファが開いています。 1つ目は左ペインのXMLファイル、もう1つは右ペインのXSDファイルです。私はそれを編集しました。編集中にスキーマに対してXMLを検証したいと思います。

しかし、注文は

!xmllint --schema /tmp/schema.xsd %

もちろん、これは現在のバッファにXMLが含まれている場合にのみ機能します。だから/tmp/schema.xsd私は、バッファ番号でフルパスを決定できるいくつかのコマンドまたは関数呼び出しで置き換えることができるかどうか疑問に思います。それは次のとおりです。

!xmllint --schema getBufferPath(3) %

ベストアンサー1

expand()通話を利用できます。例えば

:echo expand("#2:p")

バッファ#2のファイルのフルパスを印刷します。以下を使用してすべてのバッファを一覧表示できます。:ls

他の修飾語とは異なるキーワードを使用できます(完全な情報についてはページを参照:help expand())。

以下は簡単に抜粋したものです。

           When {expr} starts with '%', '#' or '<', the expansion is done
            like for the cmdline-special variables with their associated
            modifiers.  Here is a short overview:

                   %               current file name
                    #               alternate file name
                    #n              alternate file name n
                    <cfile>         file name under the cursor
                    <afile>         autocmd file name
                    <abuf>          autocmd buffer number (as a String!)
                    <amatch>        autocmd matched name
                    <sfile>         sourced script file name
                    <slnum>         sourced script file line number
                    <cword>         word under the cursor
                    <cWORD>         WORD under the cursor
                    <client>        the {clientid} of the last received
                                    message server2client()
            Modifiers:
                    :p              expand to full path
                    :h              head (last path component removed)
                    :t              tail (last path component only)
                    :r              root (one extension removed)
                    :e              extension only

           Example:
                    :let &tags = expand("%:p:h") . "/tags"
            Note that when expanding a string that starts with '%', '#' or
            '<', any following text is ignored.  This does NOT work:
                    :let doesntwork = expand("%:h.bak")
            Use this:

おすすめ記事