レジスタ%に現在のバッファのフルパスが含まれていることを知っています。しかし、別のバッファのフルパスをその番号で取得するにはどうすればよいですか?
VIMにそのような機能/コマンドはありますか?
私がこの質問に至った経緯を説明したいと思います...
2つのバッファが開いていました。1つは左側のウィンドウのXMLファイルで、もう1つは右側のウィンドウのXSDファイルでした。両方編集しました。編集中に、スキーマに対してXMLを検証したかったのです。
ただし、コマンド
!xmllint --schema /tmp/schema.xsd %
もちろん、現在のバッファーがXMLを使用するバッファーである場合にのみうまく機能しました。そのため/tmp/schema.xsd
、バッファ番号によってフルパスを決定するコマンドまたは関数呼び出しに置き換えることができるかどうかについて興味がありました。何かのようなもの:
!xmllint --schema getBufferPath(3) %
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:
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加