Vim关闭缓冲区但不拆分窗口 [英] Vim close buffer but not split window

查看:165
本文介绍了Vim关闭缓冲区但不拆分窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有2个水平/垂直拆分的缓冲区,想关闭其中一个,但是我不想关闭一个窗口。我要保持拆分窗口的位置与关闭缓冲区之前相同。



如果按:bd,则关闭缓冲区的窗口也将关闭。

p>

解决方案

就像@RusAlex我不喜欢插件。我还想知道我输入的实际上是什么代码。



nmap,d:b#< bar&b; bd#< CR>



简而言之,这会将密钥映射添加到vim的普通模式,等待密钥序列,d 。当执行该命令时,它将切换到以前打开的缓冲区,并尝试删除切换后的缓冲区。



删除屏幕外缓冲区将使屏幕保持原样。 / p>

命令由三个空格分隔的部分组成:




  • nmap -为正常模式添加/更改键映射

  • ,d -反应的键序列至;首先是(逗号),然后是 d

  • :b#< bar&b; bd#< CR> -要执行的键序列



被执行包括五个部分:




  • -将vim切换到模式命令-行

  • b#-将窗口切换到以前打开的缓冲区

  • < bar> -期待跟进命令;表示 | (竖线字符);用于链接命令

  • bd#-删除先前打开的缓冲区,即缓冲区刚刚从
  • $ b $切换开b
  • < CR> -执行命令;代表回车,基本上是键 Return Enter



该命令的格式与在〜/ .vimrc 之类的配置文件中使用的格式相同。如果要从vim中添加映射,请在(冒号)前加前缀-退出vim时,映射将丢失:



:nmap,d:b#< bar&b; bd#< CR>



打开vim,通常是在普通模式下,而不是模式插入(按 i <后在-INSERT-指示在屏幕底部/ code>),视觉效果等等。 nmap 中的 n 指定仅添加到普通模式的键映射。在此处


$ b中查找更多有关映射的信息。 $ b

重要说明:




  • b#如果它是唯一已知的缓冲区,则会切换到当前缓冲区。

  • b#可能会切换到隐藏/关闭缓冲区,例如您刚刚按下,d 关闭的那个。

  • bd#如果它是唯一已知的未拆分屏幕的缓冲区,则关闭当前缓冲区,使您留下一个空的缓冲区。

  • bd#将在以下情况下失败

  • bd#仍然会被拆分,如果切换另一个窗口后显示该缓冲区为关闭。



附加说明:




  • :windo b#将所有窗口切换到先前打开的缓冲区。不确定如何与 bd 结合使用。

  • < CR> 可以省去,在这种情况下,您必须手动按 Return 输入来执行。

  • :nmap,显示所有以开头的普通模式映射。

  • :ls 列出打开的缓冲区


If I have 2 buffers split horizontally/vertically and want to close one of them, but i don't want to close a window. I want to keep places of split windows are the same as before closing buffer.

If I press :bd , the window in which was closed buffer also became closed.

解决方案

Like @RusAlex I don't like plug-ins. I also like to know what code I enter actually does.

nmap ,d :b#<bar>bd#<CR>

In short this adds a key mapping to vim's normal mode waiting for key sequence ,d. When executed this switches to a previously open buffer and attempts to delete the buffer you switched away from.

Deleting an off-screen buffer keeps the screen split as it is.

The command consists of three space-separated parts:

  • nmap - add/change key mapping for mode normal
  • ,d - key sequence to react to; first , (comma), then d
  • :b#<bar>bd#<CR> - key sequence to execute

The command to be executed consists of five parts:

  • : - switch vim to mode command-line
  • b# - switch window to previously open buffer
  • <bar> - expect a follow-up command; represents | (pipe character); used for chaining commands
  • bd# - delete previously open buffer, i.e. the buffer just switched away from
  • <CR> - execute command(s); represents carriage return, basically the keys Return or Enter

The command is in the format it is used in a configuration file like ~/.vimrc. If you want to add the mapping from within vim you prepend : (colon) - the mapping then will be lost when exiting vim:

:nmap ,d :b#<bar>bd#<CR>

When you open vim it is usually in normal mode as opposed to modes insert (indicated on the bottom of the screen by -- INSERT -- after pressing i), visual and so on. The n in nmap specifies the key mapping to be added to normal mode only. Find more on mappings here

Important notes:

  • b# will switch to the current buffer if it is the only known buffer.
  • b# may switch to a hidden/closed buffer, e.g. the one you just closed by pressing ,d.
  • bd# will close the current buffer if it is the only known buffer unsplitting the screen leaving you with an empty buffer.
  • bd# will fail if the buffer switched away from is a hidden/closed buffer.
  • bd# will still unsplit if after switching another window shows the buffer to close.

Additional notes:

  • :windo b# will switch all windows to the previously open buffer. Not sure how to combine with bd.
  • <CR> can be left out in which case you have to manually press Return or Enter to execute.
  • :nmap , displays all normal mode mappings starting with ,.
  • :ls lists open buffers.

这篇关于Vim关闭缓冲区但不拆分窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆