查找文件名 ?f 当前在终端上的 vi 中打开的文件

Ava*_*eka 12 command-line vi

如何检查在终端中打开的文件名?也就是说,我如何检查终端中现在打开了哪个文件?

现在,每当我想查看文件名时,我都必须退出,然后再进行检查。有没有办法检查终端中的当前文件名?

Zan*_*nna 13

要在 vi(m) 中查看文件名,请按esc然后键入

:set title
Run Code Online (Sandbox Code Playgroud)

文件名出现在终端窗口的顶部栏中。你也可以这样做

:buffers
Run Code Online (Sandbox Code Playgroud)

查看当前打开的文件 - 信息显示在底部的终端内。如果您打开了多个文件,您可以%a 在当前文件旁边显示您所在的文件,例如

:buffers
  1 %a=   "unicorns"      line 19     
  2       "rainbows"      line 1
Press ENTER or type command to continue
Run Code Online (Sandbox Code Playgroud)

  • 在 ~/.vimrc 配置文件中简单地添加 `set title` 可能是个好主意...... (4认同)

rra*_*nza 9

我更喜欢 Ctrl-G:

http://vimdoc.sourceforge.net/htmldoc/editing.html

CTRL-G      or              *CTRL-G* *:f* *:fi* *:file*
:f[ile]         Prints the current file name (as typed, unless ":cd"
            was used), the cursor position (unless the 'ruler'
            option is set), and the file status (readonly,
            modified, read errors, new file).  See the 'shortmess'
            option about how to make this message shorter.
            {Vi does not include column number}
Run Code Online (Sandbox Code Playgroud)


tre*_*mby 8

当前编辑文件的文件名在%寄存器中。您可以使用 来查看它:reg %


Ser*_*nyy 7

使用:f. 它将显示文件名以及额外信息:

在此处输入图片说明

您还可以使用:args查看哪些文件名作为命令行参数提供给 vim。如果您打开多个文件(当前文件括在括号中),当您想知道正在使用哪个缓冲区时,这会很方便:

在此处输入图片说明