Skip to content

Instantly share code, notes, and snippets.

@DanBennettUK
Last active December 2, 2016 14:53
Show Gist options
  • Save DanBennettUK/6b0b9437588d490d924a71129f4b1673 to your computer and use it in GitHub Desktop.
Save DanBennettUK/6b0b9437588d490d924a71129f4b1673 to your computer and use it in GitHub Desktop.
.vimrc changes for GVIM Windows
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
if empty(&shellxquote)
let l:shxq_sav = ''
set shellxquote&
endif
let cmd = '"' . $VIMRUNTIME . '\diff"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
if exists('l:shxq_sav')
let &shellxquote=l:shxq_sav
endif
endfunction
"Personal Settings.
"More to be added soon.
execute pathogen#infect()
filetype plugin indent on
if has("gui_running")
function! ScreenFilename()
if has('amiga')
return "s:.vimsize"
elseif has('win32')
return $HOME.'\_vimsize'
else
return $HOME.'/.vimsize'
endif
endfunction
function! ScreenRestore()
" Restore window size (columns and lines) and position
" from values stored in vimsize file.
" Must set font first so columns and lines are based on font size.
let f = ScreenFilename()
if has("gui_running") && g:screen_size_restore_pos && filereadable(f)
let vim_instance = (g:screen_size_by_vim_instance==1?(v:servername):'GVIM')
for line in readfile(f)
let sizepos = split(line)
if len(sizepos) == 5 && sizepos[0] == vim_instance
silent! execute "set columns=".sizepos[1]." lines=".sizepos[2]
silent! execute "winpos ".sizepos[3]." ".sizepos[4]
return
endif
endfor
endif
endfunction
function! ScreenSave()
" Save window size and position.
if has("gui_running") && g:screen_size_restore_pos
let vim_instance = (g:screen_size_by_vim_instance==1?(v:servername):'GVIM')
let data = vim_instance . ' ' . &columns . ' ' . &lines . ' ' .
\ (getwinposx()<0?0:getwinposx()) . ' ' .
\ (getwinposy()<0?0:getwinposy())
let f = ScreenFilename()
if filereadable(f)
let lines = readfile(f)
call filter(lines, "v:val !~ '^" . vim_instance . "\\>'")
call add(lines, data)
else
let lines = [data]
endif
call writefile(lines, f)
endif
endfunction
if !exists('g:screen_size_restore_pos')
let g:screen_size_restore_pos = 1
endif
if !exists('g:screen_size_by_vim_instance')
let g:screen_size_by_vim_instance = 1
endif
autocmd VimEnter * if g:screen_size_restore_pos == 1 | call ScreenRestore() | endif
autocmd VimLeavePre * if g:screen_size_restore_pos == 1 | call ScreenSave() | endif
endif
" Automatically delete swapfiles older than the actual file.
" Look at this travesty. vim already has this information but doesn't expose
" it, so I have to reparse the swap file. Ugh.
function! s:SwapDecide()
python << endpython
import os
import struct
import vim
# Format borrowed from:
# https://github.com/nyarly/Vimrc/blob/master/swapfile_parse.rb
SWAPFILE_HEADER = "=BB10sLLLL40s40s898scc"
size = struct.calcsize(SWAPFILE_HEADER)
with open(vim.eval('v:swapname'), 'rb') as f:
buf = f.read(size)
(
id0, id1, vim_version, pagesize, writetime,
inode, pid, uid, host, filename, flags, dirty
) = struct.unpack(SWAPFILE_HEADER, buf)
try:
# Test whether the pid still exists. Could get fancy and check its name
# or owning uid but :effort:
os.kill(pid, 0)
except OSError:
# NUL means clean, \x55 (U) means dirty. Yeah I don't know either.
if dirty == b'\x00':
# Appears to be from a crash, so just nuke it
vim.command('let v:swapchoice = "d"')
endpython
endfunction
if has("python")
augroup gvim_swapfile
autocmd!
autocmd SwapExists * call s:SwapDecide()
augroup END
endif
" whitespace
set autoindent " keep indenting on <CR>
set shiftwidth=4 " one tab = four spaces (autoindent)
set softtabstop=4 " one tab = four spaces (tab key)
set expandtab " never use hard tabs
set shiftround " only indent to multiples of shiftwidth
set smarttab " DTRT when shiftwidth/softtabstop diverge
set fileformats=unix,dos " unix linebreaks in new files please
set tabstop=4
set sessionoptions-=options
syntax enable
set background=dark
colorscheme papercolor
set guifont=Lucida_Console:h10
set wrap
set linebreak
set nolist
set encoding=UTF-8
set hlsearch
set spell spelllang=en_gb
set completefunc=emoji#complete
" Uncomment below to prevent 'tilde backup files' (eg. myfile.txt~) from being created
set nobackup
" Uncomment below to cause 'tilde backup files' to be created in a different dir so as not to clutter up the current file's directory (probably a better idea than disabling them altogether)
set backupdir=C:\Windows\Temp
" Uncomment below to disable 'swap files' (eg. .myfile.txt.swp) from being created
set noswapfile
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_frontmatter = 1
let g:auto_save = 0
nmap <F3> i<C-R>=strftime("#### %H:%M")<CR><Esc>
imap <F3> <C-R>=strftime("#### %H:%M")<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment