How do I display the full absolute path of the current file in Vim?
Answer
1<C-g>
Explanation
Pressing <C-g> shows a brief status line with the current filename and position, but it typically displays a shortened or relative path. Prefixing it with the count 1 forces Vim to show the full absolute path of the file. This is useful when you are working with :lcd (local directory changes), symlinks, or multiple projects, and need to confirm exactly which file you have open.
How it works
<C-g>— prints file info: name, modification flag, and line position percentage1<C-g>— the count1expands the filename to its full absolute path2<C-g>— on systems where a "short filename" exists (Windows 8.3 names), shows that form; otherwise behaves like1<C-g>- The output appears in the command area at the bottom of the screen and does not modify the buffer
Example
With a file open via a relative path three directories deep:
<C-g> → "models/user.go" line 1 of 58 --1%--
1<C-g> → "/home/dev/projects/myapp/models/user.go" line 1 of 58 --1%--
The full path makes it immediately clear which user.go you are editing when several projects share similar directory structures.
Tips
- If you use
:lcdto change the local working directory per window,1<C-g>shows the resolved absolute path unambiguously - In a script or mapping, use
expand('%:p')to get the full path as a string for further manipulation <C-g>without a count also shows a[+]indicator if the buffer is modified and[RO]if read-only