惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
A
About on SuperTechFans
GbyAI
GbyAI
宝玉的分享
宝玉的分享
爱范儿
爱范儿
博客园 - 【当耐特】
博客园 - 司徒正美
博客园 - 聂微东
P
Proofpoint News Feed
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
J
Java Code Geeks
博客园 - 叶小钗

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
How Do I Show the Current File Path In Neovim?
2019-07-31 · via jdhao's digital space

I saw on StackExchange that someone asked about how to see the full path of current file in Vim. I think it would be helpful to write about how I do it.

Temporary solution#

To show the full path of current file, you can press {count}Ctrl-G, that is, a count bigger or equaling to 1, followed by Ctrl-G. If you press 1<C-G>, only the full path of the file will be shown. If you press a number bigger than 1, the buffer index of current file will also be shown. For more info, see :h Ctrl-G.

You can also use expand() function to see the full path of current file:

In the above command, % is special character which represents the name of current file. :p is a path modifier which is used to show the full path of the file. Please see the expand() doc on other types of path modifiers.

Permanent solution#

If you want to show the current file path permanently so that you can see its path whenever you like. A good place to put the file path is the title bar. In order to do that, you need to set the title and titlestring. Currently, I am using the following settings:

set title
set titlestring=%{hostname()}\ \ %F\ \ %{strftime('%Y-%m-%d\ %H:%M',getftime(expand('%')))}

It will show the hostname of Vim, then the complete path of the file and followed by last modified time of the file.

The titlestring is just a string. You can use pre-defined modifier to show the content of various variables and the results of various functions. It seems a bit complicated. But in fact, it is not so scary. It uses the same syntax as the statusline (see :h statusline).

In the above setting for titlestring, we first show the hostname of the Nvim using the hostname() function. %{} is a special modifier, which will evaluate the expression inside and subsititute the returned result as a string. %F is a modifier used to show the full path of the file. The getftime() function is used to show the last modified time of the current file. strftime() function is used to convert the time to pre-defined format, that is YYYY-mm-dd HH:MM.

The end result is something like the following