Reputation: 5029
I was wondering: is it possible to write the content of a variable (in my case, the last search) to a file with a command?
I tried the following:
:echo @/ >> /tmp/foo.txt
:@/w /tmp/foo.txt
But that didn't work. Any idea on what is the correct way to do this?
Upvotes: 1
Views: 608
Reputation: 11983
An alternative solution to romain’s proposal is to use the redir
command which redirects messages to a file. As described in :help redir
,
The messages which are the output of commands are written to that file, until redirection ends.
To append the contents of the search register, run the following sequence of commands:
redir >> /tmp/foo.txt
echo @/
redir END
This sequence could be turned into a function and/or used as a key mapping.
Upvotes: 4