Vim에 파일을 저장하기 전에 변경 사항을 볼 수 있습니까?
Vim을 사용합니다. 파일을 엽니 다. 편집 한 후 저장하기 전에 편집 한 내용을보고 싶습니다.
Vim에서 어떻게해야합니까?
http://vim.wikia.com/wiki/Diff_current_buffer_and_the_original_file
다음은 현재 편집 된 파일과 파일 시스템에서 수정되지 않은 버전 사이의 차이점을 보는 기능 및 명령입니다. 이것을 vimrc 또는 플러그인 디렉토리에 넣고 파일을 열고 저장하지 않고 수정하고 수행하십시오
:DiffSaved
.function! s:DiffWithSaved() let filetype=&ft diffthis vnew | r # | normal! 1Gdd diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! DiffSaved call s:DiffWithSaved()
diff보기에서 벗어나려면
:diffoff
명령을 사용할 수 있습니다 .아래는
'cvs diff'
명령 을 모방하기 위해 유사한 기능입니다 ...
:w !diff % -
어떤 사람들은 명령에 대한 설명을 요구했기 때문에
:w !diff % -
더 자세한 답변을 작성하려는 시도는 다음과 같습니다.
나는 당신이 설치되어 cat
있고 echo
설치된 시스템 (예를 들어, 거의 모든 GNU / Linux, Mac OS, BSD 및 기타 유닉스 계열 시스템)에서 작업하고 있다고 가정합니다 .
위의 명령은 다음과 같이 작동합니다.
vim에 파일을 저장하는 구문은 다음과 같습니다.
:w <filename>
vim에서 쉘 명령을 실행하는 구문은 다음과 같습니다.
:!<command>
vim이 발행 한 셸 환경
%
에서 현재 파일 이름을 가리 킵니다. 다음을 실행하여이를 확인할 수 있습니다.:!echo %
이것은 파일 이름을 출력해야합니다 (또는 vim이 파일 이름없이 실행 된 경우 오류).
cat을 사용하여 파일의 내용을 출력 할 수도 있습니다.
:!cat %
파일 내용을 마지막 저장 상태로 저장하거나 저장하지 않은 경우 오류를 반환해야합니다.
프로그램 diff는 표준 입력 (stdin)에서 읽을 수 있습니다. 해당 매뉴얼 페이지에는 다음이 명시되어 있습니다.
[...] 파일이 '-'인 경우 표준 입력을 읽습니다. [...]
파일 이름없이 쉘 명령 대신 save 명령을 실행하면 vim은 파일 내용을 실제 파일에 저장하는 대신 쉘의 stdin에 기록합니다. 당신은 이것을 실행하여 이것을 확인할 수 있습니다
:w !cat
항상 파일에 현재 내용을 인쇄해야합니다 (대신 파일에 기록되었을 것임).
파일 정리 (또는 tl; dr) : 파일이 stdin에 "저장"되고, diff는 파일 이름과 stdin을 입력으로 실행됩니다.
이것을 아는 것은 vimdiff와 파일을 다음과 같이 비교할 수도 있습니다-이것은 당신이 이것을하고 싶지 않은 아이디어 일뿐입니다.
:w !cat > /tmp/tempFile && vimdiff /tmp/tempFile % && rm /tmp/tempFile
(판독 전용이어서 개폐 vimdiff 사용하여 :qall
)
나는 항상 diffchanges를 좋아했습니다. 훌륭하고 간단합니다.
vimrc_example.vim에서 :
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
다음을 소싱하고 : DIFF 명령을 사용하십시오.
function! s:diff()
let tmpa = tempname()
let tmpb = tempname()
earlier 100h
exec 'w '.tmpa
later 100h
exec 'w '.tmpb
update
exec 'tabnew '.tmpa
diffthis
vert split
exec 'edit '.tmpb
diffthis
endfunction
command! -nargs=0 DIFF call <SID>diff()
Not exactly what you're looking for but SCMDiff.vim is really cool. One keypress, and it diff-highlights your current file with the head revision in a source control repo. It's meant to work with many SCMS. I use it with perforce.
There is a plugin, based on different answers here: https://github.com/gangleri/vim-diffsaved
It provides the :w !diff % -
method and the more involved diffthis
one.
Apart from that undotree allows this as well, but also much more (diffs between different undo checkpoints). Similar to Gundo.
I can recommend the histwin plugin.
While it doesn't diff to the current saved version of the file (like the other answers), it can vimdiff changes since you started edting, and even replay your changes in order. The difference shows if you save intermediately.
Additionally, it displays a list of all undo history branches and allows you to switch or diff between them.
PS: While the plugin doesn't automatically track moments in the edit history since every file change, you can explicitly "tag" the moment when you save the file such that you can later vimdiff with it, if you want that. Maybe this could be automated?
If you want to use vim for comparison like in vimdiff, you could do something like this:
Edit your .vimrc and add:
nmap <F8> :w !vim -M -R - -c ":vnew % \| windo diffthis"<CR><CR>
From there on you will see your changes and can quit the diff view using qall
like in vimdiff by pressing F8 in command mode. Replace F8 with any key you like.
Edit: Added -M to disallow any modification, because it is not save.
Follow the above suggests I use git diff that I like much:
:w !git diff % -
참고URL : https://stackoverflow.com/questions/749297/can-i-see-changes-before-i-save-my-file-in-vim
'Programing' 카테고리의 다른 글
`m_` 변수 접두사는 무엇을 의미합니까? (0) | 2020.07.05 |
---|---|
"권한이있는 SSL / TLS 보안 채널에 대한 신뢰 관계를 설정할 수 없음"해결 방법 (0) | 2020.07.04 |
Dictionary <>에 항목을 안전하게 추가하는 더 우아한 방법이 있습니까? (0) | 2020.07.04 |
HTML 형식의 이메일을 보내는 방법은 무엇입니까? (0) | 2020.07.04 |
MSBuild를 실행하면 SDKToolsPath를 읽을 수 없습니다. (0) | 2020.07.04 |