I know that the register % contains the full path of the current buffer. But how to get the full path of another buffer by its number?
Is there such a function/command in VIM?
I want to explain how I came to this question…
There were 2 buffers open. The first was an XML file in the left window and the other was an XSD file in the right window. I edited both of them. During the editing I wanted to validate the XML against the schema.
However the command
!xmllint --schema /tmp/schema.xsd %
of course worked well only if the current buffer was the one with the XML. So I was curious about whether it would be possible to replace /tmp/schema.xsd
with some command or function call that would determine the full path by the buffer number. Something like:
!xmllint --schema getBufferPath(3) %
Best Answer
You can use the
expand()
call. For exampleWill print the full path of the file in buffer #2 you can list all buffers with
:ls
You can use other modifiers and other keywords (For full info page look at
:help expand()
)Here is an quick excerpt: