Improved unsaved

This commit is contained in:
Talia 2018-01-30 16:38:39 +01:00
parent 20aa8c1916
commit 93b5927968

28
vimrc
View file

@ -289,18 +289,36 @@ function! s:hex(...)
endfunction endfunction
command! -nargs=* Hex call <sid>hex(<q-args>) command! -nargs=* Hex call <sid>hex(<q-args>)
function! s:unsaved() function! s:unsaved_new()
if &mod
let tmp_file = expand("%:p").".tmp" let tmp_file = expand("%:p").".tmp"
exec "w ".tmp_file exec "w ".tmp_file
exec "!gvim -d -R % ".tmp_file exec "!gvim -d -R % ".tmp_file
call delete(tmp_file) call delete(tmp_file)
endfun
function! s:unsaved_same()
diffthis
below new
set buftype=nofile
r #
diffthis
au BufUnload <buffer> diffoff!
exec "normal \<C-w>k"
endfun
function! s:unsaved(...)
if &mod
if a:0
call <sid>unsaved_new()
else
call <sid>unsaved_same()
end
else else
echom "No changes to show :)" echom "No changes to show :)"
end end
endfun endfun
command! Unsaved call <sid>unsaved() command! -nargs=? Unsaved call <sid>unsaved(<args>)
" === GENERAL KEY MAPPINGS === " === GENERAL KEY MAPPINGS ===
let mapleader = "\\" let mapleader = "\\"
@ -586,6 +604,7 @@ au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap <buffer> ; m'$a;<C-c>`'
au BufNewFile,BufRead *.rb :call <sid>init_ruby_file() au BufNewFile,BufRead *.rb :call <sid>init_ruby_file()
function! s:init_ruby_file() function! s:init_ruby_file()
set makeprg=ruby\ -wc\ %
setl number setl number
command! -buffer Defines lex MatchingLines("^\\s*def\\>\\s\\+\\zs.*$") | lopen command! -buffer Defines lex MatchingLines("^\\s*def\\>\\s\\+\\zs.*$") | lopen
command! -buffer Functions Defines " Alias command! -buffer Functions Defines " Alias
@ -598,7 +617,7 @@ function! s:init_ruby_file()
nnoremap <buffer> <leader>id odef <C-o>m'()<enter>end<esc>`'a nnoremap <buffer> <leader>id odef <C-o>m'()<enter>end<esc>`'a
nnoremap <buffer> <F5> :w<CR>:!ruby %<CR> nnoremap <buffer> <F5> :w<CR>:!ruby %<CR>
nnoremap <buffer> <F6> :w<CR>:!ruby -wc %<CR> nnoremap <buffer> <F6> :lmake<CR>:lopen<CR>
nnoremap <buffer> <leader>~ :call <SID>RubyComment(0)<CR> nnoremap <buffer> <leader>~ :call <SID>RubyComment(0)<CR>
nnoremap <buffer> <leader># :call <SID>RubyComment(1)<CR> nnoremap <buffer> <leader># :call <SID>RubyComment(1)<CR>
vnoremap <buffer> <leader>~ :call <SID>RubyComment(0)<CR> vnoremap <buffer> <leader>~ :call <SID>RubyComment(0)<CR>
@ -652,3 +671,4 @@ function! s:init_html_file()
inoremap <buffer> <C-space> <C-o>""ciw<<C-o>""p><C-o>m'</<C-o>""p><C-o>`'<C-o>l inoremap <buffer> <C-space> <C-o>""ciw<<C-o>""p><C-o>m'</<C-o>""p><C-o>`'<C-o>l
inoremap <buffer> <C-CR> <C-o>""diw<C-o>"_cc<<C-o>""p><C-o>o</<C-o>""p><C-o>O inoremap <buffer> <C-CR> <C-o>""diw<C-o>"_cc<<C-o>""p><C-o>o</<C-o>""p><C-o>O
endfunction endfunction