Saving selected text in Vim as txt file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving selected text in Vim as txt file

Narayanan S. Iyer
Hi,
 
I have question on how to handle selected text in Vim. This is my requirement:
 
I need a script which when invoke by a key say <F2> would save the
selected text in Vim as a text file say "~/selected.txt". Could
someone please help me on how to do this ?
 
Regards,
Iyer
Reply | Threaded
Open this post in threaded view
|

Re: Saving selected text in Vim as txt file

Dominic Evans
vmap <F2> :w! ~/selected.txt<CR>

Cheers,
Dom

On 13/09/05, Narayanan S. Iyer <[hidden email]> wrote:

> Hi,
>
> I have question on how to handle selected text in Vim. This is my requirement:
>
> I need a script which when invoke by a key say <F2> would save the
> selected text in Vim as a text file say "~/selected.txt". Could
> someone please help me on how to do this ?
>
> Regards,
> Iyer
>
Reply | Threaded
Open this post in threaded view
|

RE: Saving selected text in Vim as txt file

Goli, Rajesh (Rajesh)
In reply to this post by Narayanan S. Iyer
vmap <F2> "ay:enew<CR>"ap:w! ~/selected.txt<CR>:bde<CR>

"ay = yank to register a
:enew = new buffer
"ap = paste from register a
:w! ~/selected.txt = force write to ~/selected.txt
:bde = do away with selected.txt buffer

Adding this in your ~/.vimrc should do it.

-Rajesh

-----Original Message-----
From: Narayanan S. Iyer [mailto:[hidden email]]
Sent: Tuesday, September 13, 2005 3:16 PM
To: [hidden email]
Subject: Saving selected text in Vim as txt file


Hi,
 
I have question on how to handle selected text in Vim. This is my
requirement:
 
I need a script which when invoke by a key say <F2> would save the
selected text in Vim as a text file say "~/selected.txt". Could
someone please help me on how to do this ?
 
Regards,
Iyer
Reply | Threaded
Open this post in threaded view
|

Re: Saving selected text in Vim as txt file

Dominic Evans
You don't need all that yanking. Visual select + :w already saves just
the selection.

On 13/09/05, Goli, Rajesh (Rajesh) <[hidden email]> wrote:

> vmap <F2> "ay:enew<CR>"ap:w! ~/selected.txt<CR>:bde<CR>
>
> "ay = yank to register a
> :enew = new buffer
> "ap = paste from register a
> :w! ~/selected.txt = force write to ~/selected.txt
> :bde = do away with selected.txt buffer
>
> Adding this in your ~/.vimrc should do it.
>
> -Rajesh
>
> -----Original Message-----
> From: Narayanan S. Iyer [mailto:[hidden email]]
> Sent: Tuesday, September 13, 2005 3:16 PM
> To: [hidden email]
> Subject: Saving selected text in Vim as txt file
>
>
> Hi,
>
> I have question on how to handle selected text in Vim. This is my
> requirement:
>
> I need a script which when invoke by a key say <F2> would save the
> selected text in Vim as a text file say "~/selected.txt". Could
> someone please help me on how to do this ?
>
> Regards,
> Iyer
>
Reply | Threaded
Open this post in threaded view
|

Re: Saving selected text in Vim as txt file

Matthew Winn
On Tue, Sep 13, 2005 at 11:05:18AM +0100, Dominic Evans wrote:
> You don't need all that yanking. Visual select + :w already saves just
> the selection.

That only saves line by line.  Yanking and pasting into another buffer
makes it possible to save block selections as well.

--
Matthew Winn ([hidden email])