在 Vim 中撤消关闭选项卡

发布于 2024-07-13 22:05:46 字数 71 浏览 7 评论 0原文

我关闭了 vim 中的一个选项卡,然后立即意识到我需要重新打开它以进行某些操作。 Vim 7.2 中有没有办法撤消关闭选项卡?

I close a tab in vim and immediately realize I need to re-open it again for something. Is there a way to undo close tab in Vim 7.2?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

伏妖词 2024-07-20 22:05:46

您的文件可能仍在缓冲区中打开:

:ls " get the buffer number
:tabnew +Nbuf " where N is the buffer number

要重新打开缓冲区 18,例如:

:tabnew +18buf

Your file is probably still open in a buffer:

:ls " get the buffer number
:tabnew +Nbuf " where N is the buffer number

To reopen buffer 18, for example:

:tabnew +18buf
慵挽 2024-07-20 22:05:46
:tabnew#

在新选项卡中重新打开最近关闭的文件


编辑:请使用 greyfade 的答案。 我不喜欢我的答案,但我将其保留在这里以供参考和有用的评论信息。

:tabnew#

Reopens recently closed file in new tab


Edit: Please use greyfade's answer. I don't like my answer, but I'm keeping it here for references and useful comment info.

趴在窗边数星星i 2024-07-20 22:05:46

我正在使用 MRU(最近使用的文件)插件。 这样我就可以编辑刚刚编辑的最后 30 个文件

以下是 MRU 插件元数据:

File: mru.vim
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
Version: 3.2   Last Modified:
September 22, 2008

使用

要列出并编辑 MRU 列表中的文件,可以使用“:MRU”命令。
":MRU" 命令在临时 Vim 窗口中显示 MRU 文件列表。 如果
MRU窗口已经打开,然后窗口中显示MRU列表
被刷新了。

I'm using an MRU (most recently used files) plugin. So I can edit the last 30 files I've just edited

Here are the MRU plugin metadata:

File: mru.vim
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
Version: 3.2   Last Modified:
September 22, 2008

Usage

To list and edit files from the MRU list, you can use the ":MRU" command.
The ":MRU" command displays the MRU file list in a temporary Vim window. If
the MRU window is already opened, then the MRU list displayed in the window
is refreshed.

聽兲甴掵 2024-07-20 22:05:46

简单的答案是否定的,没有任何内置的东西。

但一个可行的解决方案是使用像优秀的 BufExplorer。 由于它默认首先列出最近使用的缓冲区,因此重新打开关闭的选项卡就像按 \bet 一样简单

Simple answer is no, there is nothing built-in.

But a workable solution would be to use a plug-in like the excellent BufExplorer. Since it defaults to listing the most recently used buffers first, reopening a closed tab would be as simple as pressing \bet

吹泡泡o 2024-07-20 22:05:46

使用 Ben 建议的插件: BufExplorer Github Mirror

在他的回答中,必须按t。 添加一点快捷方式:

map <silent><leader>t <leader>be<Down>t

这样只需 t 即可完成工作。

Use the plug-in Ben Suggested: BufExplorer Github Mirror

In his answer one would have to press <Leader>be<Down>t. Adding a bit shortcut:

map <silent><leader>t <leader>be<Down>t

So that simply <leader>t would do the work.

是你 2024-07-20 22:05:46

如果有一个 BufferClose 事件,这会很容易...... 但似乎它不可能,因为不可能创建窗口

但对于选项卡,我们可以通过保存选项卡计数并计算 TabLeaveTabEnter 之间的差异来检测选项卡是否已关闭。

用法: tr 在新选项卡上重新打开最后关闭的选项卡(假设该选项卡只有一个缓冲区):

let g:reopenbuf = expand('%:p')
function! ReopenLastTabLeave()
  let g:lastbuf = expand('%:p')
  let g:lasttabcount = tabpagenr('
)
endfunction
function! ReopenLastTabEnter()
  if tabpagenr('
) < g:lasttabcount
    let g:reopenbuf = g:lastbuf
  endif
endfunction
function! ReopenLastTab()
  tabnew
  execute 'buffer' . g:reopenbuf
endfunction
augroup ReopenLastTab
  autocmd!
  autocmd TabLeave * call ReopenLastTabLeave()
  autocmd TabEnter * call ReopenLastTabEnter()
augroup END
" Tab Restore
nnoremap <leader>tr :call ReopenLastTab()<CR>

If there were a BufferClose event this would be easy... but it seems that it is not possible since it is not possible for window creation.

But in the case of tabs we can detect if a tab was closed by keeping a tab count and counting the difference between TabLeave and TabEnter.

Usage: <leader>tr reopens the last closed tab on a new tab (supposing the tab had only a single buffer):

let g:reopenbuf = expand('%:p')
function! ReopenLastTabLeave()
  let g:lastbuf = expand('%:p')
  let g:lasttabcount = tabpagenr('
)
endfunction
function! ReopenLastTabEnter()
  if tabpagenr('
) < g:lasttabcount
    let g:reopenbuf = g:lastbuf
  endif
endfunction
function! ReopenLastTab()
  tabnew
  execute 'buffer' . g:reopenbuf
endfunction
augroup ReopenLastTab
  autocmd!
  autocmd TabLeave * call ReopenLastTabLeave()
  autocmd TabEnter * call ReopenLastTabEnter()
augroup END
" Tab Restore
nnoremap <leader>tr :call ReopenLastTab()<CR>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文