简体   繁体   English

如何在vim中具有不同的标题和标签标题

[英]How to have different title and tab title in vim

As of now I have put the following in my .vimrc file in order to display the name of the currently open file in the screen title of my Terminal: 到目前为止,我已经在我的.vimrc文件中添加了以下内容,以便在终端的屏幕标题中显示当前打开的文件的名称:

autocmd BufEnter * let &titlestring = expand("%:@")
set title

Is it possible to also set a specific tab title? 是否还可以设置特定的标签标题? That is, when I have a number of vim tabs open in Terminal on my Mac I would Terminal to display the directory path in the Terminal header when I have selected the tab related to the file and I would like to display only the name of the file in the header of the tab. 也就是说,当我在Mac的Terminal中打开了多个vim选项卡时,当我选择了与文件相关的选项卡并且仅想显示文件名时,我将使Terminal在Terminal标头中显示目录路径。标签标题中的文件。

Some comments to your goal 对您的目标的一些评论

Personally I hardly use tabs in vim. 我个人几乎不在vim中使用制表符。 What you want to have can be achieved by setting some options. 您可以通过设置一些选项来实现。 Before I talk about the options, I would say that what you want to do could be inconvenient. 在讨论选项之前,我想说您想做的事可能会带来不便。 Because in vim, tab is a collection of windows, which means, it can have splitted windows, and in a tab page, you can show more than one buffers. 因为在vim中,tab是窗口的集合,这意味着它可以分割窗口,并且在选项卡页面中可以显示多个缓冲区。 That is, in a tab page, it is not always showing one file. 也就是说,在选项卡页面中,它并不总是显示一个文件。 As you are switching from split to split in a tab page, both your terminal title and the tab label could be changing. 当您在选项卡页面中从拆分切换到拆分时,终端标题标签标签都可能会更改。

For example, you have 3 dirs, /one /two and /three and two tab pages in your vim. 例如,您的vim中有3个目录, /one /two and /three和两个标签页。

Now you have: 现在您有了:

tab1:
/one/file1

tab2 (in split-windows):
/one/file1
/two/file1
/three/file1

When you are in tab1 , your terminal title would be /one , tab1-label would be file1 , fine. 当您进入tab1 ,终端标题为/one ,tab1-label为file1 ,很好。 But when you are in tab2, your terminal title will change as you are switching from split to split. 但是当您进入tab2时,终端名称将随着您从split切换到split而改变。 In this example, the tab-label would be same file1 , so you have to check terminal window and the tab label to know which buffer/file you are currently editing. 在此示例中,选项卡标签将是相同的file1 ,因此您必须检查终端窗口选项卡标签以了解当前正在编辑的缓冲区/文件。 I don't think this is convenient. 我认为这不方便。

Answer to your question 回答你的问题

Okay, if you want that to happen, :h setting-tabline and check the example in the help text, it shows how to set the label of tabs. 好的,如果您希望这样做,请:h setting-tabline并查看帮助文本中的示例,该示例显示了如何设置选项卡的标签。 This should achieve your goal for vim in Terminal. 这应该可以在Terminal中实现vim的目标。

FYI, to get only parent dir name you can use %:p:h . 仅供参考,您可以使用%:p:h来仅获取父目录名称。 to get only filename, you can use %:p:t . 要仅获取文件名,可以使用%:p:t

Plus, some other things you may want to check: 另外,您可能还需要检查其他一些事项:

  • There is another autocommand event: TabEnter . 还有另一个自动命令事件: TabEnter
  • :h setting-tabline if you want your tabline to show some complex text or other highlighting :h setting-tabline如果您希望您的选项行显示一些复杂的文本或其他突出显示
  • if you want to play with filename/dirname further, you can check :h expand() and :h filename-modifiers 如果您想进一步使用文件名/目录名,可以检查:h expand():h filename-modifiers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM