특히 Fugitive의 경우 vim에서 vimdiff 모드를 어떻게 종료합니까?
나는 도망자 확장자 와 함께 vim을 사용하고 있습니다 . vimdiff 모드로 이동하는 : Gdiff 명령이 있지만 vimdiff 모드를 닫거나 종료하는 올바른 / 빠른 방법은 무엇입니까?
즉, Git 저장소에서 FooBar.txt 파일을 편집하고 있다고 가정 해 보겠습니다. 나는 : Gdiff를 실행하고 vimdiff의 변경 사항을 검토 한 다음 돌아가서 FooBar.txt 또는 다른 파일을 계속 편집하고 싶습니다. :)
UPDATE1 : 다음 작업 일에이 빠른 콤보를 시도해 보겠습니다. :)
"vimdiff current vs git head (fugitive extension)
nnoremap <Leader>gd :Gdiff<cr>
"switch back to current file and closes fugitive buffer
nnoremap <Leader>gD :diffoff!<cr><c-w>h:bd<cr>
UPDATE2 : 내 현재 매핑 (diff 창만 닫음!)
"vimdiff current vs git head (fugitive extension)
nnoremap <Leader>gd :Gdiff<cr>
"switch back to current file and closes fugitive buffer
nnoremap <Leader>gD <c-w>h<c-w>c
또한 다음이 anwser 여야하는지 결정하는 데 도움을주세요. https://stackoverflow.com/a/15975201/275980
windo set nodiff noscrollbind
두 번째 창을 실행 한 다음 닫을 수 있습니다 .
업데이트 : diffoff
명령이 있습니다. windo diffoff
이전 줄에서 작성한 내용이 아닌를 사용하십시오 .
에 따르면 : https://github.com/tpope/vim-fugitive/issues/36
다른 창을 닫습니다. 포커스를 이동하지 않은 경우이를 수행하는 가장 쉬운 방법
<C-W><C-O>
은 "이 창을 유일한 창으로"를 의미합니다.
나는 운이 좋지 diffoff
않았지만 :Gedit
, 당신이 검토하고 있던 일부 이전 버전과는 달리 인수가 없으면 파일의 작업 디렉토리 버전으로 돌아갈 것이라는 것을 방금 배웠습니다 .
그리고로 q
(에 대한 필요성 :q
은 diff 사이드를 닫습니다), 당신이 할 수있는 q
다음 :Gedit
사이드 바 제거하고 파일의 현재 버전으로 돌아 가야 얻을 수 있습니다.
이것은 여기에 기존 아이디어 중 일부를 결합하여 잘 작동합니다.
function! MyCloseDiff()
if (&diff == 0 || getbufvar('#', '&diff') == 0)
\ && (bufname('%') !~ '^fugitive:' && bufname('#') !~ '^fugitive:')
echom "Not in diff view."
return
endif
" close current buffer if alternate is not fugitive but current one is
if bufname('#') !~ '^fugitive:' && bufname('%') =~ '^fugitive:'
if bufwinnr("#") == -1
b #
bd #
else
bd
endif
else
bd #
endif
endfunction
nnoremap <Leader>gD :call MyCloseDiff()<cr>
이에 대한 간단한 해결책을 찾았습니다. 여기에서 확인할 수 있습니다 : https://gist.github.com/radmen/5048080
" Simple way to turn off Gdiff splitscreen
" works only when diff buffer is focused
if !exists(":Gdiffoff")
command Gdiffoff diffoff | q | Gedit
endif
위의 솔루션 중 어느 것도 나를 위해 일하지 않았습니다. 대신 다음을 수행했습니다.
nnoremap <Leader>D :Gedit<CR><C-w>h :q<CR><C-w>k
<C-W><C-O>
여러 창이있는 경우에 대한 대안 은 다른 diff 창으로 이동하고 <C-W>c
하나의 창만 닫는 do 입니다.
잘못된 diff 창을 닫으면 :Gedit
주의와 혼동하지 마십시오 <C-W>c
과<C-W><C-C>
이것은 내가 사용한 후 vimdiff 창을 떠나야하는 것입니다. : Gdiff
nnoremap gD :q!<CR> :Gedit!<CR>
noremap <leader>do :diffoff \| windo if &diff \| hide \| endif<cr>
꽤 diff 모드를 사용하고 다른 diff 창을 닫습니다. (참고 : 도망자는 숨겨진 버퍼를 자동으로 삭제합니다.)
내 기능은 diff 창과 파일 창에서 모두 작동합니다. 그러나 아마도 여러 diff가 열린 상태에서 스스로를 처리하지 못할 것입니다. 이를 fugitive#buffer(n).path()
위해서는 스캔하고 일치시키는 데 사용해야 합니다.
command! Gdiffoff call Gdiffoff()
function! Gdiffoff()
let diffbufnr = bufnr('^fugitive:')
if diffbufnr > -1 && &diff
diffoff | q
if bufnr('%') == diffbufnr | Gedit | endif
setlocal nocursorbind
else
echo 'Error: Not in diff or file'
endif
endfunction
키 바인딩을 추가합니다.
nnoremap <silent> <leader>gD :Gdiffoff<CR>
또 다른 방법. fugitive.vim에있는 것-먼저 diff가 시작될 때 일부 정보 (s : gitbufname)를 저장합니다.
function! s:Diff(vert,...) abort
call sy#toggle()
let s:startcol = winwidth(0)
let &columns=(winwidth(0) * 2 - 20)
...
if getwinvar('#', '&diff')
let s:gitbufname = bufname("%")
wincmd p
call feedkeys(winnr."\<C-W>w", 'n')
endif
...
endfunction
나중에 버퍼 전환 창을 저장된 버퍼로두고 복원 할 때 :
augroup fugitive_diff
autocmd!
autocmd BufWinLeave *
\ if s:can_diffoff(+expand('<abuf>')) && s:diff_window_count() == 2 |
\ if exists('s:gitbufname') && winnr() != bufwinnr(s:gitbufname) |
\ let nr = bufnr("%") | exe bufwinnr(s:gitbufname).'wincmd w' | exe 'buf'.nr |
\ endif |
\ call s:diffoff_all(getbufvar(+expand('<abuf>'), 'git_dir')) |
\ call sy#toggle() |
\ call airline#load_theme() | call airline#update_statusline() |
\ let &columns=s:startcol |
\ endif
...
이 페이지에서 와 여기 vimdiff
사이 의 전환을 확인 하십시오 .diffthis
diffoff
코드:
nnoremap <silent> <Leader>df :call DiffToggle()<CR>
function! DiffToggle()
if &diff
diffoff
else
diffthis
endif
:endfunction
방법 1 :
- 비교 열기 :
:windo diffthis
- 닫으세요 :
:windo diffoff
방법 2 :
가장 간단한 명령을 사용하는 것이 좋습니다. :q<CR>
신속하게 수행하려면 매핑을 추가하십시오.
" Set mapleader
let mapleader = ","
let g:mapleader = ","
과
" Quickly close the current window
nnoremap <leader>q :q<CR>
그것은 나를 위해 잘 작동합니다. ,q
일반적으로 커서가 이전 파일에 있으므로 vimdiff를 종료 하십시오.
https://stackoverflow.com/a/15113951/10999673을 기반으로 아래 코드를 사용했습니다 .
if !exists(":Gdiffoff")
command Gdiffoff bw! fugitive://*
endif
but it gave me an error "E93: more than one match for ..." in a 3 way diff, so i instead used the answer from https://stackoverflow.com/a/4867969/10999673 and finally have this:
function! GetBufferList()
return filter(range(1,bufnr('$')), 'buflisted(v:val)')
endfunction
function! GetMatchingBuffers(pattern)
return filter(GetBufferList(), 'bufname(v:val) =~ a:pattern')
endfunction
function! WipeMatchingBuffers(pattern)
let l:matchList = GetMatchingBuffers(a:pattern)
let l:count = len(l:matchList)
if l:count < 1
echo 'No buffers found matching pattern ' . a:pattern
return
endif
if l:count == 1
let l:suffix = ''
else
let l:suffix = 's'
endif
exec 'bw ' . join(l:matchList, ' ')
echo 'Wiped ' . l:count . ' buffer' . l:suffix . '.'
endfunction
command! -nargs=1 Gdiffoff call WipeMatchingBuffers('fugitive://')
I just tweaked, copied and pasted the code into my .vimrc
Running :Gwrite
after merging to your satisfaction will close the other two diff panes in addition to updating the git cache to mark the file as merged.
'IT TIP' 카테고리의 다른 글
디버그 에이전트 없이는 NullPointerException 스택 추적을 사용할 수 없습니다. (0) | 2020.12.11 |
---|---|
무료 DTD에서 XSD 로의 변환 유틸리티? (0) | 2020.12.11 |
프로그램 내부에서 gdb를 호출하여 스택 추적을 인쇄하는 가장 좋은 방법은 무엇입니까? (0) | 2020.12.11 |
Node.js 프로젝트 문서화 (0) | 2020.12.11 |
2 개의 "float"를 사용하여 "double"을 에뮬레이션 (0) | 2020.12.11 |