我使用:e和:w命令来编辑和写入文件。我不确定是否有“close”命令关闭当前文件而不离开Vim?
我知道:q命令可以用来关闭一个文件,但如果它是最后一个文件,Vim也会被关闭;实际上在Mac OS上MacVim退出了。只有Vim窗口是关闭的,我可以使用Control-N再次打开一个空白的Vim窗口。我希望Vim保持空白屏幕的打开状态。
我使用:e和:w命令来编辑和写入文件。我不确定是否有“close”命令关闭当前文件而不离开Vim?
我知道:q命令可以用来关闭一个文件,但如果它是最后一个文件,Vim也会被关闭;实际上在Mac OS上MacVim退出了。只有Vim窗口是关闭的,我可以使用Control-N再次打开一个空白的Vim窗口。我希望Vim保持空白屏幕的打开状态。
当前回答
在.vimrc文件中插入以下内容,按下F4,将关闭当前文件。
:map <F4> :bd<CR>
其他回答
bufkill。vim插件添加了BD等,在不关闭任何分割的情况下删除缓冲区(就像BD一样)。
如果你的Vim窗口中有多个分割窗口,那么:bd关闭当前文件的分割窗口,所以我喜欢使用一些更高级的东西:
map fc <Esc>:call CleanClose(1)
map fq <Esc>:call CleanClose(0)
function! CleanClose(tosave)
if (a:tosave == 1)
w!
endif
let todelbufNr = bufnr("%")
let newbufNr = bufnr("#")
if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
exe "b".newbufNr
else
bnext
endif
if (bufnr("%") == todelbufNr)
new
endif
exe "bd".todelbufNr
endfunction
:[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516* :bd[elete][!] [N] Unload buffer [N] (default: current buffer) and delete it from the buffer list. If the buffer was changed, this fails, unless when [!] is specified, in which case changes are lost. The file remains unaffected. Any windows for this buffer are closed. If buffer [N] is the current buffer, another buffer will be displayed instead. This is the most recent entry in the jump list that points into a loaded buffer. Actually, the buffer isn't completely deleted, it is removed from the buffer list |unlisted-buffer| and option values, variables and mappings/abbreviations for the buffer are cleared.
如前所述,你正在寻找:bd,然而这并没有完全删除缓冲区,它仍然是可访问的:
:e foo
:e bar
:buffers
1 #h "foo" line 1
2 %a "bar" line 1
Press ENTER or type command to continue
:bd 2
:buffers
1 %a "foo" line 1
Press ENTER or type command to continue
:b 2
2 bar
相反,您可能需要:bw,这将完全删除它。
:bw 2
:b 2
E86: Buffer 2 does not exist
不知道:bw困扰了我一段时间。
:bd可以被映射。我把它映射到F4, Shift-F4如果我需要强制关闭因为一些我不想要的改变。