Monday, July 27, 2009

[vim] Send the output of a command straight into vim

Here is a pretty cool tip I learn from the Ubuntu groups on LinkedIn.

You are working with vim on a file and, for some reason, you need the output of a command (i.e. ls to get the list of files in folder).

1) First solution is to open a new shell and type 'ls', copy the result and paste it in the file that you are currently working on
2)You can use redirection by closing the file you are working on and type:

ls >> myfile.txt

3)This cool trick from vim (and vi).
Place your cursor where you want the output to be pasted
Type

:!r<command>

In our example, it will be

:!rls

and the result of the ls will be pasted where you have place the cursor.

Tip can be found here . You may need to join the Ubuntu group.

No comments: