vim中如何检测窗口的位置

发布于 2024-08-25 22:04:11 字数 519 浏览 7 评论 0原文

我正在尝试自定义 vimdiff 的映射并使它们类似于 winmerge

在垂直 2 路分割中,我想映射 alt-left 将当前 diff 移动到左侧, alt-right 将当前差异移至右侧。

对于合并,我可以使用 :diffg:diffp。但我需要知道我所在的分区,以便我可以在其中使用 :diffg/:diffp

有什么方法可以检测我所处的分区。 具体来说,有什么方法可以让我知道光标是在左分割还是右分割

相关问题 如何获取-当前在 vim 中进行差异化的文件列表

I am trying to customize the mappings for vimdiff and make them similar to winmerge

In a vertical 2 way split, I want to map alt-left <a-left> to move current diff to left side and alt-right <a-right> to move current diff to right side.

For merging i can use :diffg and :diffp. But I need to know which split i am in so that i can use :diffg/:diffp in that.

Is there any way by which i can detect which split i am in.
Specifically is there is any way by which i can know whether the cursor is in left split or right split

Related Question
how-to-get-list-of-files-which-are-currently-being-diffed-in-vim

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

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

发布评论

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

评论(2

梦巷 2024-09-01 22:04:11

假设只有两个窗口,winnr() 函数将为第一个窗口返回 1,为第二个窗口返回 2。您还可以使用 winnr('$') 来了解有多少个窗口::echo winnr('$')

您也可以只使用 dpdo,这样您就不需要在窗口之间跳转,而且比箭头键更容易到达。

Assuming there are only two windows, the winnr() function will return 1 for the first window and 2 for the second window. You can also use winnr('$') to find out how many windows there are: :echo winnr('$').

You can also just use dp and do, then you don't need to jump betweem windows as much, and it's easier to reach than the arrow keys.

残花月 2024-09-01 22:04:11

不是您具体问题的答案,但这里有一些不错的差异调整可能会有所帮助。

"" Diff options; ignore whitespace.
set diffopt+=iwhite

我不喜欢 :diffon :diffoff 因为它们会扰乱自动换行(退出 diff 时将其打开)。所以我只设置 diff、scrollbind、foldmarker 和 Foldcolumn。

"" Diff 'd' {{{
    nmap <silent> ,dd :set diff scb fdm=diff fdc=2<CR>
    nmap <silent> ,dD :windo :set diff scb fdm=diff fdc=2<CR>
    nmap <silent> ,do :set nodiff noscb fdm=manual fdc=0<CR>
    nmap <silent> ,dO :windo :set nodiff noscb fdm=manual fdc=0<CR>
    "nmap <silent> ,dd :diffthis<CR>
    "nmap <silent> ,dD :windo :diffthis<CR>
    "nmap <silent> ,do :diffoff<CR>
    "nmap <silent> ,dO :windo :diffoff<CR>
    nmap <silent> ,du :diffupdate<CR>
"" }}}

另外,如果您还没有的话,请检查 DirDiff 插件来比较目录树...

Not an answer to your specific question, but here are some nice diff tweaks that might help.

"" Diff options; ignore whitespace.
set diffopt+=iwhite

I don't like the :diffon :diffoff because they mess with word wrap (turns it on when exiting diff). So i only set diff, scrollbind, foldmarker and foldcolumn.

"" Diff 'd' {{{
    nmap <silent> ,dd :set diff scb fdm=diff fdc=2<CR>
    nmap <silent> ,dD :windo :set diff scb fdm=diff fdc=2<CR>
    nmap <silent> ,do :set nodiff noscb fdm=manual fdc=0<CR>
    nmap <silent> ,dO :windo :set nodiff noscb fdm=manual fdc=0<CR>
    "nmap <silent> ,dd :diffthis<CR>
    "nmap <silent> ,dD :windo :diffthis<CR>
    "nmap <silent> ,do :diffoff<CR>
    "nmap <silent> ,dO :windo :diffoff<CR>
    nmap <silent> ,du :diffupdate<CR>
"" }}}

Also, check out the DirDiff plugin for diffing directory trees if you haven't already...

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