我已经看到了在Vim中使用选项卡(使用:table,:tabnew等)的能力,以取代我目前在隐藏缓冲区的同一个窗口中打开多个文件的做法。
我想每个不同的文件,我已经打开,总是在自己的选项卡。然而,有一些事情阻碍了这一点。我如何解决这些问题:
When commands like gf and ^] jump to a location in another file, the file opens in a new buffer in the current tab. Is there a way to have all of these sorts of commands open the file in a new tab, or switch to the existing tab with the file if it is already open?
When switching buffers I can use
:b <part of filename><tab>
and it will complete the names of files in existing buffers. <part of filename> can even be the middle of a filename instead of the beginning. Is there an equivalent for switching tabs?
与这里的其他一些答案相反,我说您可以随心所欲地使用选项卡。Vim被设计为多功能和可定制的,而不是强迫您根据预定义的参数工作。我们都知道我们程序员喜欢把自己的“道德规范”强加给其他人,所以这个成就当然是一个主要特征。
<C-w>gf是相当于缓冲区gf命令的制表符。<C-PageUp>和<C-PageDown>将在制表符之间切换。(在Byobu中,这两个命令从来不适合我,但它们在Byobu/tmux之外工作。<C-w>T将当前窗口移动到一个新的标签页。
如果您希望vim尽可能使用现有的选项卡,而不是创建重复的选项卡,请在.vimrc文件中添加:set switchbuf=usetab。您可以将newtab添加到列表(:set switchbuf=usetab,newtab),以强制在单独的选项卡中打开显示编译错误的QuickFix命令。我更喜欢拆分,它会在拆分窗口中打开编译错误。
如果您启用了鼠标支持:set mouse=a,您可以通过单击选项卡与它们进行交互。默认情况下还有一个+按钮,它将创建一个新选项卡。
对于有关选项卡的文档,在正常模式下键入:help选项卡页。(在你这样做之后,你可以练习移动一个窗口到一个选项卡使用<C-w> t)有一个很长的命令列表。一些窗口命令与选项卡有关,因此您可能也想通过:help窗口查看相关文档。
补充:2013-12-19
要在vim中打开多个文件,每个文件都在单独的选项卡中,请使用vim -p file1 file2 ....如果您像我一样总是忘记添加-p,您可以在最后添加它,因为vim遵循正常的命令行选项解析规则。或者,您也可以添加一个bash别名,将vim映射到vim -p。
You can map commands that normally manipulate buffers to manipulate tabs, as I've done with gf in my .vimrc:
map gf :tabe <cfile><CR>
I'm sure you can do the same with [^
I don't think vim supports this for tabs (yet). I use gt and gT to move to the next and previous tabs, respectively. You can also use Ngt, where N is the tab number. One peeve I have is that, by default, the tab number is not displayed in the tab line. To fix this, I put a couple functions at the end of my .vimrc file (I didn't paste here because it's long and didn't format correctly).