How can I access the contents of a modified buffer in Vim?
For example, if I want to concatenate the contents to a temporary file, like:
:! cat % > /tmp/modified.txt
But that gives me the last saved contents of the file (rightly so?). I do want to avoid saving the file before because this interaction is meant to allow some analysis without saving the buffer first.
It seems that the Python extension for Vim allows you to do something like:
def buffer_contents(buffer=vim.current.buffer):
contents = buffer[:]
But I can’t find any VimL references for the same functionality.
EDIT: It seems I could do something like:
:let buffer_contents = join(getline(1, '$'), '$')
At this point I just wonder if there is a builtin approach.
If you want to append current contents to temporary file you can use
,
for overwriting that file (like in your cat example). To pass it to stdin of some script
. Wondering though what’s wrong with your
getline(1, '$')?