How to detect the position of window in vim

倾然丶 夕夏残阳落幕 提交于 2019-12-23 04:05:22

问题


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


回答1:


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.




回答2:


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...



来源:https://stackoverflow.com/questions/2473678/how-to-detect-the-position-of-window-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!