1
Is there a vim plugin or other program that copy-pastes a selected text to a permanent file in one keystroke? E.g. You select a text, do Ctrl + s
and instead of copying to clipboard, it copies to a permanent file.
It can be via a vim plugin because I'll always do this action from inside a vim session. Ultimately I would want to first paste the relative path of the current file I'm in, then paste the selected text and then insert a blank line to separate for the next entry.
I am using Ubuntu 11.10 btw.
When I select a text in visual mode and do
:write! >> ~/myfile.txt<CR>
it works. But when I put:vnoremap <C-s> :write! >> ~/mytext.txt
in my.vimrc
and press<C-s>
after restarting a vim session it doesn't do anything strangely. – Bentley4 – 2013-04-02T10:14:09.583Also, when executing
:<C-u>execute '!echo "%" >> ~/myfile.txt'<Bar>'<,'>write! >> ~/myfile.txt<CR>
after selecting a text I get an error messagetrailing characters
, seems it's not correctly formatted. – Bentley4 – 2013-04-02T10:14:48.6331The mappings must include the trailing
<CR>
, but if you type it as commands, instead of<Bar>
type the literal|
. Failure may also be due to your settings, see:help map-special
. – Ingo Karkat – 2013-04-02T10:18:43.253I did
– Bentley4 – 2013-04-02T10:34:03.940:noremap <C-s> :write! >> ~/Desktop/ho.txt<CR>
and:noremap <special> <C-s> :write! >> ~/Desktop/ho.txt<CR>
confer to the example in:help map-special
, still the same thing. Do you recognise anything in my .vimrc that could interfere with this command?1
No, looks fine. Can you try another key, e.g.
– Ingo Karkat – 2013-04-02T11:17:45.193<F9>
? Maybe it's this issue.It looks like
<C-s>
was the culprit(and apparently also<C-q>
did not work), I tried it withQ
and both commands worked. Any idea how I can add a blank line in the file after each insertion? – Bentley4 – 2013-04-02T11:42:57.287Ah, glad you've found it! Another
!echo ""
should work for a blank line. – Ingo Karkat – 2013-04-02T12:04:30.120:vnoremap Q :<C-u>execute '!echo "%" >> ~/Desktop/hi.txt'<Bar>'<,'>write! >> ~/Desktop/hi.txt<CR><CR><CR>:<C-u>execute '!echo " " >> ~/Desktop/hi.txt'<Bar>'<,'><CR><CR>:echo "Pasted!"<enter>
is the full command I was looking for. It skips the confirmation screen and shows a "Pasted!" message after you pasted your lines to that file. – Bentley4 – 2013-04-02T12:05:41.923Simply adding
!echo
does not work (:vnoremap Q :<C-u>execute '!echo "%" >> file'<Bar>'<,'>write! >> file<CR>!echo ""<CR>
). But that's probably not what you meant. Anyway, with that command in my previous comment it does what I want, although I think that newline could be added in a less verbose as I wrote it. Thanks for your help! – Bentley4 – 2013-04-02T12:17:01.913