tags:

views:

320

answers:

1

I have selected text by visual mode and pressed :.

I run the following command unsuccessfully

w >> ~/Documents/Test/test.java

The result is an empty file.

How can you append text in Vim's visual mode to another file?

+8  A: 

After selecting the text in visual mode and typing ":", you should see ":'<,'>" already typed out for you. This means between the start and end of your visual selection. You can add "w >> ~/Documents/Test/test.java" after the ":'<,'>". What you will see before hitting enter will be:

:'<,'>w >> ~/Documents/Test/test.java

If the file doesn't exist or you don't have appropriate permissions, you will get an error, otherwise it should say "appended" and work. I tested that out and it works on Vim 7.2.

Ankit
Vim 7.0 works too.
Glorphindale
@Ankit: It works now for me too. I looked at a wrong file about the result. -- I obviously need to get some Zs. Thank you for your answer!
Masi