简体   繁体   中英

How to fix buffer in a window in vim?

Can I fix a buffer so that the only way to remove it from vim window is closing it?

For instance, I'm using the NERDtree plugin, which displays the filesystem in a vim window. Sometimes I forget to change focus to other window before using the quickfix commands and the erroneus file ends up replacing the file tree. (Not to mention that NERDtree's window default width is only 31)

Edit:

What I'm trying to achieve with this question is to simulate Eclipse's notion of views and editors inside vim. In this terms, NERDTree (and other plugins destined to exclusively display information) would be a view while the other windows would be editors.

这不完全是一个答案,但如果你搞砸了, Ctrl-^ 会撤消缓冲区内容的更改。

I've written an autocommand that does this. Adding the following to vimrc will prevent NERDtree buffers from being overwritten:

autocmd BufEnter * if bufname("#") =~ "NERD_tree" && bufname("%") !~ "NERD_tree" | b# | endif

The autocommand runs every time a new buffer is opened -- if it detects that the previous buffer was NERDtree and the current buffer is not NERDtree, then it will go back to the NERDtree buffer, essentially 'locking' NERDtree in place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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