在指定的分割中打开 .netrw 文件

发布于 2024-12-19 14:44:20 字数 234 浏览 0 评论 0原文

这与超级用户的问题相同,但我觉得在这里有更好的机会得到回答,所以...

在 Vim 中,我有四个分割 - 两两 - 并且在左上角有一个 netrw 是打开的。有没有办法从右下分割、左下分割等位置的 netrw 打开文件?

This is the same question as on SuperUser, but I feel it has a better chance of being answered here, so ...

In Vim, I have four splits - two by two - and in the upper left one netrw is open. Is there a way to open a file from netrw in the lower right split, lower left, etc.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

回忆凄美了谁 2024-12-26 14:44:20

这里有一些提示 https://superuser。 com/questions/377501/keep-cursor-in-netrw-window-when-browsing-files-in-vim

将其放入您的 .vimrc 中,

let g:netrw_preview = 1

要配置垂直预览分割,然后当光标位于所需文件上方时,键入 p 打开预览窗口。要关闭窗口,请键入 CtrlWz

vim 中用于表示在光标未移动到时打开的窗口的术语是“预览窗口”。要了解有关此内容的更多信息,请参阅

:help netrw-preview
:help CTRL-W_z

或仅

:help netrw

浏览目录以了解其他浏览命令和其他 netrw 功能。

there're some hints here https://superuser.com/questions/377501/keep-cursor-in-netrw-window-when-browsing-files-in-vim

Put this in your .vimrc,

let g:netrw_preview = 1

to configure vertical preview splits, then when the cursor is over the desired file, type p to open a preview window. To close the window, type CtrlWz.

The term used in vim for a window that's opened without the cursor moving to it is a "preview window". To find out more about this, see

:help netrw-preview
:help CTRL-W_z

or just

:help netrw

and browse the table of contents for other browsing commands and other netrw features.

半城柳色半声笛 2024-12-26 14:44:20

您可以设置g:netrw_chgwin变量以使netrw在特定窗口中打开文件。请参阅:

:h netrw-C

因此,要使当前窗口成为 netrw 的目标,请在该窗口中键入以下内容:

:let g:netrw_chgwin = winnr()

另一种方法是在目标窗口中启动 netrw (:E),点击 C< /code> 选择它进行编辑并使用 关闭 netrw。

You can set the g:netrw_chgwin variable to make netrw open the files in a specific window. See:

:h netrw-C

So to make the current window the target of netrw type this while you're in that window:

:let g:netrw_chgwin = winnr()

Another way is to launch netrw in the target window (:E), hit C to select it for editing and close netrw with <c-o>.

放手` 2024-12-26 14:44:20

为了将上述答案结合起来一些灵感:我将以下窗口配置与 netrw 一起使用(与 :let g:netrw_liststyle = 2 一起使用):

    -------------------------------- ...
    Netrw-split: topleft spilt
    -------------------------------- ...
             |          |          |
    working  | working  | working  |
    window 1 | window 2 | window 3 | ...
             |          |          |

因此我可以从每个其他窗口直接转到 Netrw-split。然后我将其放入 .vimrc:

    augroup netrw
        autocmd!
        autocmd WinLeave * if &ft !=# "netrw" | let g:netrw_chgwin = winnr() | endif
        autocmd filetype netrw call Netrw_mappings()
    augroup END

WinLeave 命令将全局 g:netrw_chgwin 变量设置为刚刚离开的窗口(除非我们位于 netrw-window 中)。因此,netrw 将在我访问它的窗口中打开任何文件,并且由于窗口布局,我可以从任何其他窗口访问 netrw。

autocmd“filetype”还用于在我访问 netrw 的窗口中创建一个新文件。对于这个 netrw 的 '%' 命令必须被覆盖:

    function! Netrw_mappings()
        noremap <buffer>% :call CreateInLastWindow()<cr>
    endfunction

使用在窗口 g:netrw_chgwin 中创建新文件的函数:

    function! CreateInLastWindow()
        let l:filename = input("new file's name: ")
        let l:netrwdir = b:netrw_curdir
        execute g:netrw_chgwin . "wincmd w"
        execute 'edit ' . l:netrwdir.'/'.l:filename
    endfunction

To bring above answers together some inspirations: I use the following window configuration together with netrw (together with :let g:netrw_liststyle = 2):

    -------------------------------- ...
    Netrw-split: topleft spilt
    -------------------------------- ...
             |          |          |
    working  | working  | working  |
    window 1 | window 2 | window 3 | ...
             |          |          |

Thus I can go directly to Netrw-split from every other window. Then I put to my .vimrc:

    augroup netrw
        autocmd!
        autocmd WinLeave * if &ft !=# "netrw" | let g:netrw_chgwin = winnr() | endif
        autocmd filetype netrw call Netrw_mappings()
    augroup END

The WinLeave command sets the global g:netrw_chgwin variable to the window just left (except if we are in the netrw-window). Thus netrw will open any file in the window from which I accessed it and due to the window layout I can access netrw from any other window.

The autocmd 'filetype' is used to also create a new file in the window from which I accessed netrw. For this netrw's '%' command has to be overwritten:

    function! Netrw_mappings()
        noremap <buffer>% :call CreateInLastWindow()<cr>
    endfunction

With a function creating the new file in window g:netrw_chgwin:

    function! CreateInLastWindow()
        let l:filename = input("new file's name: ")
        let l:netrwdir = b:netrw_curdir
        execute g:netrw_chgwin . "wincmd w"
        execute 'edit ' . l:netrwdir.'/'.l:filename
    endfunction

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文