Luc Hermitte (talk | contribs) m (Added to Windows Category + minor enhancements) |
(adjust previous/next navigation + minor manual clean) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{review}} |
{{review}} |
||
+ | {{TipImported |
||
− | {{Tip |
||
|id=432 |
|id=432 |
||
+ | |previous=431 |
||
− | |title=Putting the current file on the Windows clipboard |
||
+ | |next=434 |
||
− | |created= |
+ | |created=2003 |
|complexity=basic |
|complexity=basic |
||
|author=Salman Halim |
|author=Salman Halim |
||
|version=6.0 |
|version=6.0 |
||
|rating=5/4 |
|rating=5/4 |
||
+ | |category1=Windows |
||
− | |text= |
||
+ | |category2= |
||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | For example, for my _vimrc file, I get c:\vim\_vimrc in the clipboard. |
||
}} |
}} |
||
⚫ | |||
+ | <pre> |
||
⚫ | |||
+ | </pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | :map <leader>cf :Copyfile<cr> |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
+ | <pre> |
||
− | salmanhalim--AT--hotmail.com |
||
+ | :map <Leader>cf :Copyfile<CR> |
||
− | , March 5, 2003 6:42 |
||
+ | </pre> |
||
− | ---- |
||
⚫ | |||
− | nn <silent><C-G> :let --AT--*='<C-R>=expand("%:p")<CR>'<CR>:f<CR> |
||
− | |||
⚫ | |||
⚫ | |||
− | maxiangjiang--AT--hotmail.com |
||
− | , March 5, 2003 7:52 |
||
---- |
---- |
||
⚫ | |||
⚫ | The problem with your mapping is you're corrupting the clipboard every time you want to simply get information about where one is in the file. (I actually use |
||
+ | <pre> |
||
⚫ | |||
+ | </pre> |
||
⚫ | |||
⚫ | |||
− | You don't need the quotes around the let expression in your mapping. |
||
− | |||
− | salmanhalim--AT--hotmail.com |
||
− | , March 6, 2003 6:22 |
||
---- |
---- |
||
⚫ | The problem with your mapping is you're corrupting the clipboard every time you want to simply get information about where one is in the file. (I actually use Ctrl-g every so often and it would be nice if it didn't have a side effect.) Basically, for new users, overloading existing commands with side effects can become confusing and not intuitive. |
||
− | Let me correct myself: you DO need the quotes around your mapping the way you have it. However, you can simply change it to: |
||
⚫ | |||
⚫ | |||
− | Assignments accept expressions that aren't literals so you don't need the register expansion. |
||
− | salmanhalim--AT--hotmail.com |
||
− | , March 6, 2003 11:04 |
||
---- |
---- |
||
+ | To copy current file contents (rather than just the file name) to clipboard: |
||
− | |||
+ | <pre> |
||
− | Wow. Thanks. That is great! |
||
+ | :%y* |
||
− | I just modified all register assignment statements in my vimrc! |
||
+ | </pre> |
||
+ | And map it, if you want: |
||
− | maxiangjiang--AT--hotmail.com |
||
+ | <pre> |
||
− | , March 7, 2003 14:56 |
||
+ | :map <F3> :%y*<CR> |
||
− | ---- |
||
+ | </pre> |
||
− | For vim rookies -like me- the way to copy current file content in Windows clipboard is |
||
− | :1,$ y * |
||
⚫ | |||
− | that is, yanking from line 1 to end-of-file -represented by $- into register '*'. After that, go to Notepad and do a simply CTRL + V. And map it, if you want |
||
− | :map <F3> :1,$ y * <CR> |
||
− | epoc--AT--bsab.com |
||
− | , March 8, 2003 2:50 |
||
---- |
---- |
||
− | |||
− | simpler one: |
||
− | :%y*<CR> |
||
− | |||
− | maxiangjiang--AT--hotmail.com |
||
− | , March 9, 2003 20:04 |
||
− | ---- |
||
⚫ | |||
− | |||
− | Anon |
||
− | , March 10, 2003 6:02 |
||
− | ---- |
||
− | <!-- parsed by vimtips.py in 0.515946 seconds--> |
||
− | |||
− | [[Category:Windows]] |
Latest revision as of 10:18, 23 April 2011
created 2003 · complexity basic · author Salman Halim · version 6.0
Sometimes I want to use the file I'm editing in Vim (on Windows) in another application; I created the following command:
command! Copyfile let @*=substitute(expand("%:p"), '/', '\', 'g')
This copies the entire path and filename of the current file (with any slashes replaced with backslashes) onto the clipboard. You can then paste the value wherever needed, such as a File, Open dialog.
Comments[]
As an addendum, I didn't want to make a mapping out of this because I don't do it often enough; however, one can easily do something like:
:map <Leader>cf :Copyfile<CR>
I noticed that hitting :C<tab> was almost as fast as the mapping characters anyway.
Here is my map to do the same thing:
nn <silent><C-G> :let @*=expand('%:p')<CR>:f<CR>
I overloaded <C-G>, and because I set ssl, I don't need worry about backslash.
The problem with your mapping is you're corrupting the clipboard every time you want to simply get information about where one is in the file. (I actually use Ctrl-g every so often and it would be nice if it didn't have a side effect.) Basically, for new users, overloading existing commands with side effects can become confusing and not intuitive.
The whole point of 'ssl' is to replace backslashes with FORWARD slashes. It doesn't help with pasting the filepath into another Windows application -- SOME of them may understand forward slashes but many will not, hence the substitution.
To copy current file contents (rather than just the file name) to clipboard:
:%y*
And map it, if you want:
:map <F3> :%y*<CR>
File-content copying probably should be a separate tip altogether. Plus, it's not complete without a mention of the 'clipboard' and 'guioptions' options. Try :help gui-clipboard for more details.