Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to append text in Vim's visual mode to another file

Tags:

vim

append

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?

like image 379
Léo Léopold Hertz 준영 Avatar asked Dec 23 '22 11:12

Léo Léopold Hertz 준영


1 Answers

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.

like image 116
Ankit Avatar answered Mar 06 '23 21:03

Ankit