current file to clipboard

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

current file to clipboard

Alejandro Calbazana
Hello,

Is there any way echo the current file (path and all) to the clipboard?  
For example:

after
:echo expand("%")

I see the current file name, but I am not sure how to copy this value to
the clipboard.  I see that there are registers for the clipboard, but I
am not clear how to pipe the result of an echo to this register.

Thanks,

Al
Reply | Threaded
Open this post in threaded view
|

Re: current file to clipboard

Tim Chase-2
> Is there any way echo the current file (path and all) to the
> clipboard? For example:
>
> after
> :echo expand("%")

:let @*=expand("%")

should do the trick, assigning the results to the system clipboard.

-tim



Reply | Threaded
Open this post in threaded view
|

RE: current file to clipboard

Halim, Salman
In reply to this post by Alejandro Calbazana
I usually want the filename because I intend to paste it somewhere, so
this works better:

" Copy the current file (with full path) into the clipboard
nmap <s-f4> :let @*=substitute(expand("%:p"), '/', '\\', 'g')<cr>

For what it's worth, if you're not on Windows, you can get rid of the
substition from forward slashes to back slashes:
nmap <s-f4> :let @*=expand("%:p")<cr>

Hope this helps,

Salman.

> -----Original Message-----
> From: Tim Chase [mailto:[hidden email]]
> Sent: Tuesday, August 30, 2005 12:17 PM
> To: Alejandro Calbazana
> Cc: [hidden email]
> Subject: Re: current file to clipboard
>
> > Is there any way echo the current file (path and all) to the
> > clipboard? For example:
> >
> > after
> > :echo expand("%")
>
> :let @*=expand("%")
>
> should do the trick, assigning the results to the system clipboard.
>
> -tim
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: current file to clipboard

Hari Krishna Dara
In reply to this post by Alejandro Calbazana

On Tue, 30 Aug 2005 at 11:17am, Tim Chase wrote:

> > Is there any way echo the current file (path and all) to the
> > clipboard? For example:
> >
> > after
> > :echo expand("%")
>
> :let @*=expand("%")
>
> should do the trick, assigning the results to the system clipboard.
>
> -tim

And creating a couple of maps for this will be very helpful:

" Copy the name of the current file into clipboard (in window's fashion).
nnoremap <F2> :let @*=substitute(expand("%:p"), "/", "\\", "g")<cr>
nnoremap <S-F2> :let @*=expand("%:p")<cr>
" Copy the path to the directory of current file.
nnoremap <C-F2> :let @*=expand("%:p:h")<cr>

The first one is needed only if you are on windows and 'shellslash' is set.

--
HTH,
Hari


               
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs 
 
Reply | Threaded
Open this post in threaded view
|

Re: current file to clipboard

A.J.Mechelynck
In reply to this post by Tim Chase-2
----- Original Message -----
From: "Tim Chase" <[hidden email]>
To: "Alejandro Calbazana" <[hidden email]>
Cc: <[hidden email]>
Sent: Tuesday, August 30, 2005 6:17 PM
Subject: Re: current file to clipboard


>> Is there any way echo the current file (path and all) to the
>> clipboard? For example:
>>
>> after
>> :echo expand("%")
>
> :let @*=expand("%")
>
> should do the trick, assigning the results to the system clipboard.
>
> -tim

Yes, and see also ":help redir" for more complex situations. For instance,

    :set nomore
    :redir @*
    :ver
    :set all
    :set termcap
    :map
    :map!
    :highlight
    :autocmd
    :redir END
    :set more

would echo to the clipboard the output of the commands between the two
":redir" statements.


Best regards,
Tony.