Vim Tips Wiki
Register
m (Copy current file name into windows clipboard moved to Copy filename to clipboard: This works for other OS's too, not just Windows, also make the title a bit shorter.)
Line 9: Line 9:
 
|rating=23/17
 
|rating=23/17
 
}}
 
}}
  +
  +
[[Category:File Handling]]
   
 
Sometimes I need to use the name of the file that I'm editing in another application (compiler, e-mail attachment, reference in a document, etc).
 
Sometimes I need to use the name of the file that I'm editing in another application (compiler, e-mail attachment, reference in a document, etc).

Revision as of 21:01, 15 April 2008

Tip 600 Printable Monobook Previous Next

created October 30, 2003 · complexity basic · author Igor Keselman · version 5.7


Sometimes I need to use the name of the file that I'm editing in another application (compiler, e-mail attachment, reference in a document, etc).

These mappings are useful for copying the file name to the clipboard.

" Convert slashes to backslashes for Windows.
if has('win32')
  nmap ,cs :let @*=substitute(expand("%"), "/", "\\", g)<CR>
  nmap ,cl :let @*=substiture(expand("%:p"), "/", "\\", g)<CR>
  
  " This will copy the path in 8.3 short format, for DOS and Windows 9x
  nmap ,c8 :let @*=substitute(expand("%:p:8"), "/", "\\", g)<CR>
else
  nmap ,cs :let @*=expand("%")<CR>
  nmap ,cl :let @*=expand("%:p")<CR>

This maps the following keys:

  • ,cs copies just the filename.
  • ,cl copies the filename including it's full path.
  • ,c8 copies the filename in 8.3 format for DOS and Windows 9x

You can then simply paste the name into another document using the regular paste command.

References

Comments