2

我打开了一个文件并修改了它——现在我想做:Explore拆分。

它分裂 - 因为我有一个未保存的缓冲区。默认情况下这很好,因为 Vim 通常不允许切换文件,直到您对修改后的缓冲区执行某些操作(保存或丢弃更改)。

但我已经设置hidden选项,所以我可以从一个缓冲区跳到另一个缓冲区,切换文件和所有东西——当我想保存或不保存时。Netrw 似乎没有遵循此政策。我该如何帮助它?

我知道的一种方法是将 netrw 映射exploresave & explore,但我不确定自动写入是否是一种很好的做事方式......我现在实际上正在使用其他自动写入设置,但我只是在重新考虑可能摆脱它们。

4

4 回答 4

3

所以这是一个功能,它就是这样做的:

function! ExploreWithHidden()
    let s:cw = getcwd()
    lcd %:p:h
    enew
    Explore
    cd `=s:cw`
endfunction

似乎按预期工作。

于 2013-07-03T10:56:20.180 回答
1

你可以:Texplore改用。这与探索相同,除了在新选项卡中(并且不会拆分)。

:h Texplore


您可以做的另一件事是:lcd %:p:h将当前工作目录更改为文件目录。然后使用:enew创建另一个缓冲区然后打开探索。(如果缓冲区被修改,请确保隐藏已打开)

:command! BExplore :lcd %:p:h | enew | Explore

要运行命令,请使用:BExplore.

旧缓冲区将位于后台,并且探索窗口指向文件所在的目录。

于 2013-07-02T17:05:45.740 回答
1

你可以升级你的netrw——在http://www.drchip.org/astronaut/vim/index.html#NETRW上升级到v153s,如果修改后的缓冲区被隐藏,它确实可以避免拆分。

于 2014-11-29T01:13:21.837 回答
0

tpope's vim-vinegar operates like this. It maps - to Explore the current file's directory. (That's the same key netrw uses to go up one directory.) It uses the current window instead of splitting.

When the current file is modified:

  • If you have 'hidden' set, it will not split and Explore from the current window.
  • If you do not have 'hidden' set, it will issue an error and do nothing.
于 2014-11-27T19:12:43.040 回答