开发者

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 in开发者_开发技巧formation) would be a view while the other windows would be editors.


This isn't exactly an answer, but if you screw up, Ctrl-^ undoes a change in a buffer's content.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜