No edit summary |
(First clean up) |
||
Line 9: | Line 9: | ||
|rating=61/22 |
|rating=61/22 |
||
|text= |
|text= |
||
− | + | Here is a function/command to see a diff between the currently edited file and its unmodified version in the filesystem. Just put this in your .vimrc or in the plugins directory, open a file, make some modifications without saving them and do :DiffWithSaved (or choose a better name if you like) |
|
− | |||
− | |||
+ | <pre> |
||
function! s:DiffWithSaved() |
function! s:DiffWithSaved() |
||
⚫ | |||
− | |||
− | + | diffthis |
|
⚫ | |||
− | |||
− | + | vnew | r # | normal 1Gdd |
|
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
− | |||
− | setlocal bt=nofile bh=wipe nobl noswf ro |
||
− | |||
endfunction |
endfunction |
||
− | |||
com! Diff call s:DiffWithSaved() |
com! Diff call s:DiffWithSaved() |
||
+ | </pre> |
||
⚫ | |||
− | |||
− | |||
⚫ | |||
− | |||
}} |
}} |
||
== Comments == |
== Comments == |
||
− | nice tip... |
||
− | you can also use this to split vertically: |
||
− | |||
− | vnew | 0r # |
||
− | |||
− | |||
− | |||
− | sertac |
||
− | , October 27, 2005 10:35 |
||
− | ---- |
||
− | Helpful tip indeed.. |
||
− | |||
− | If you change the function to, |
||
− | function! s:DiffWithSaved() |
||
⚫ | |||
− | diffthis |
||
⚫ | |||
− | vnew | r # | normal 1Gdd |
||
− | diffthis |
||
⚫ | |||
− | endfunction |
||
− | com! Diff call s:DiffWithSaved() |
||
− | |||
− | then the filetype is also set (for syntax highlighting) |
||
− | |||
− | - Karthick |
||
− | |||
− | '''Anonymous''' |
||
− | , October 27, 2005 21:02 |
||
− | ---- |
||
− | Very nice tip |
||
− | |||
− | |||
− | shankarpdy--AT--yahoo.com |
||
− | , October 27, 2005 21:17 |
||
− | ---- |
||
− | many thanks to Anonymous |
||
− | his additions make this command even more useful :) |
||
− | |||
− | RichiH |
||
− | , October 28, 2005 4:30 |
||
− | ---- |
||
I'm bored of typing all the time ciwyes<esc> and ciwno<esc> when editing config files. So I define: |
I'm bored of typing all the time ciwyes<esc> and ciwno<esc> when editing config files. So I define: |
||
+ | <pre> |
||
− | |||
function s:ToggleYesNo() |
function s:ToggleYesNo() |
||
− | + | let w=expand("<cword>") |
|
− | + | if w == "yes" |
|
− | + | let w="no" |
|
− | + | elseif w == "no" |
|
− | + | let w="yes" |
|
− | + | else |
|
− | + | let w="" |
|
− | + | endif |
|
− | + | if w!="" |
|
− | + | exec "normal! \"_ciw\<C-R>=w\<cr>" |
|
− | + | endif |
|
endfunc |
endfunc |
||
nnoremap gy :call <SID>ToggleYesNo()<cr> |
nnoremap gy :call <SID>ToggleYesNo()<cr> |
||
+ | </pre> |
||
− | |||
− | |||
− | vim at bertram dash scharpf dot de |
||
− | , October 30, 2005 11:08 |
||
---- |
---- |
||
− | Nice tip! |
||
− | |||
I made a similar function, adapted to mimic the 'cvs diff' command (cvs must be in the path): |
I made a similar function, adapted to mimic the 'cvs diff' command (cvs must be in the path): |
||
+ | <pre> |
||
function! s:DiffWithCheckedOut() |
function! s:DiffWithCheckedOut() |
||
− | + | let filetype=&ft |
|
− | + | diffthis |
|
− | + | " new | r # | normal 1Gdd - for horizontal split |
|
− | + | vnew | r !cvs up -pr BASE # |
|
− | + | normal 1Gd6d |
|
− | + | diffthis |
|
− | + | exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype |
|
endfunction |
endfunction |
||
com! DiffCVS call s:DiffWithCheckedOut() |
com! DiffCVS call s:DiffWithCheckedOut() |
||
+ | </pre> |
||
− | |||
− | -- |
||
− | Ipkiss |
||
− | |||
− | ipkiss _at_ via _dot_ ecp _dot_ fr |
||
− | , November 4, 2005 10:51 |
||
− | ---- |
||
<!-- parsed by vimtips.py in 0.732250 seconds--> |
<!-- parsed by vimtips.py in 0.732250 seconds--> |
Revision as of 18:12, 21 July 2007
Tip: #1030 - Diff current buffer and the original file
Created: October 27, 2005 10:15 Complexity: intermediate Author: Thomas Arendsen Hein - thomas--AT--intevation.de Version: 6.0 Karma: 61/22 Imported from: Tip#1030
Here is a function/command to see a diff between the currently edited file and its unmodified version in the filesystem. Just put this in your .vimrc or in the plugins directory, open a file, make some modifications without saving them and do :DiffWithSaved (or choose a better name if you like)
function! s:DiffWithSaved() let filetype=&ft diffthis " new | r # | normal 1Gdd >-- Uncomment this for horizontal split vnew | r # | normal 1Gdd diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! Diff call s:DiffWithSaved()
To get out off diff view you can use the :diffoff command on vim7 or the nodiff.vim script from script#1198.
Comments
I'm bored of typing all the time ciwyes<esc> and ciwno<esc> when editing config files. So I define:
function s:ToggleYesNo() let w=expand("<cword>") if w == "yes" let w="no" elseif w == "no" let w="yes" else let w="" endif if w!="" exec "normal! \"_ciw\<C-R>=w\<cr>" endif endfunc nnoremap gy :call <SID>ToggleYesNo()<cr>
I made a similar function, adapted to mimic the 'cvs diff' command (cvs must be in the path):
function! s:DiffWithCheckedOut() let filetype=&ft diffthis " new | r # | normal 1Gdd - for horizontal split vnew | r !cvs up -pr BASE # normal 1Gd6d diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! DiffCVS call s:DiffWithCheckedOut()