vimrc 腳本獲取當(dāng)前文件名

Register % contains the name of the current file, and register # contains the name of the alternate file. These registers allow the name of the current or alternate files to be displayed or inserted. The name, or full path, or directory containing the file can be used.

For example, in directory /abc the command vim def/my.txt would edit file /abc/def/my.txt. The following commands could be entered to display the information shown.

:echo expand('%:t')     my.txt  name of file ('tail')
:echo expand('%:p')     /abc/def/my.txt full path
:echo expand('%:p:h')   /abc/def    directory containing file ('head')
:echo expand('%:p:h:t') def First get the full path with :p (/abc/def/my.txt), then get the head of that with :h (/abc/def), then get the tail of that with :t (def)
:echo expand('%:r')     my  name of file less one extension ('root')
:echo expand('%:e')     txt name of file's extension ('extension')```
For more info run :help expand

If all that is wanted is to display the name of the current file, type Ctrl-G (or press 1 then Ctrl-G for the full path).

When using @%, the name is displayed relative to the current directory.

In insert mode, type Ctrl-R then % to insert the name of the current file.

In command mode (after typing a colon), type Ctrl-R then % to insert the name of the current file. The inserted name can then be edited to create a similar name.

In normal mode, type "%p to put the name of the current file after the cursor (or "%P to insert the name before the cursor).

The following commands insert lines consisting of the full path of the current and alternate files into the buffer:

:put =expand('%:p')
:put =expand('#:p')


#打賞
如果這篇文章解決了您的問題,讓我買根煙抽抽。

![支付寶.jpg](http://upload-images.jianshu.io/upload_images/4765606-b13a42b44fd975a7.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/340)


![微信.jpg](http://upload-images.jianshu.io/upload_images/4765606-3ad5592b17125067.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/340)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,996評(píng)論 0 0
  • 為何叫做 shell ? shell prompt(PS1) 與 Carriage Return(CR) 的關(guān)系?...
    Zero___閱讀 3,334評(píng)論 3 49
  • 提起尿,人們覺得這不過是一種人體代謝的“副產(chǎn)品”。其實(shí),尿液也是身體狀況的晴雨表。每天排尿多少,尿頻的原因,尿液顏...
    jnrk120閱讀 493評(píng)論 0 2
  • 又快期末考試了,大楊平時(shí)的努力在這一刻體現(xiàn)出了價(jià)值,至少在我看來是,大楊開始幫我輔導(dǎo),去自習(xí)室,大楊坐在我旁邊嚼著...
    Shinnflove閱讀 398評(píng)論 0 0

友情鏈接更多精彩內(nèi)容