Line 57: | Line 57: | ||
Hey quick question, Ctrl-G worked but I'm wondering if there is a special way to examine the contents of the % register? According to the vim docs above |
Hey quick question, Ctrl-G worked but I'm wondering if there is a special way to examine the contents of the % register? According to the vim docs above |
||
− | *@* @{0-9a-z".=*} Execute the contents of register {0-9a-z".=*} [count] times. Note that register '%' (name of the current file) and '#' (name of the alternate file) cannot be used. Is there a special way to echo its contents? I'm on vim version 7.3 with patches: 1-154. |
+ | *@* @{0-9a-z".=*} Execute the contents of register {0-9a-z".=*} [count] times. Note that register '%' (name of the current file) and '#' (name of the alternate file) cannot be used. Is there a special way to echo its contents? In case it's useful information, I'm on vim version 7.3 with patches: 1-154. |
Revision as of 17:45, 10 November 2011
Duplicate tip
This tip is very similar to the following:
These tips need to be merged – see the merge guidelines.
created 2003 · complexity basic · author Geoff Hubbard · version 5.7
To get the name of the file you are currently editing use:
@%
If you want to make sure of the path as well use:
expand("%:p")
References
- :help @
- :help expand()
- :help cmdline-special
- Copy filename to clipboard shows why it might be useful
Comments
To enter the name of the current file in insert or command mode, use <C-R>%.
If you want to use it as part of a command line just use %, for example:
!echo %
Without the extention:
!echo %:r
Ctrl-G is an easier way to get this info.
If you need to insert otherfile names (say the *.h name in an #include), you can do C-X+C-F for filename completion.
Complete path, filename and extension:
2+Ctrl-G
It can be useful to get the name of the current file in command mode, and be able to edit it. The % sign can be used to get the name, but that will not allow you to edit the path. By pressing ^R#, the current path will be inserted, and you can edit it to open another file.
Hey quick question, Ctrl-G worked but I'm wondering if there is a special way to examine the contents of the % register? According to the vim docs above
- @* @{0-9a-z".=*} Execute the contents of register {0-9a-z".=*} [count] times. Note that register '%' (name of the current file) and '#' (name of the alternate file) cannot be used. Is there a special way to echo its contents? In case it's useful information, I'm on vim version 7.3 with patches: 1-154.