Skip to content

Instantly share code, notes, and snippets.

@Skinner927
Last active June 4, 2025 19:41
Show Gist options
  • Save Skinner927/6856b47863f0d476e90b43532e3a14c4 to your computer and use it in GitHub Desktop.
Save Skinner927/6856b47863f0d476e90b43532e3a14c4 to your computer and use it in GitHub Desktop.
" Get the defaults that most users want.
try
source $VIMRUNTIME/vimrc_example.vim
catch
source $VIMRUNTIME/defaults.vim
endtry
" Disable the pesky mouse
set mouse=
set ttymouse=
silent !mkdir ~/.vimtmp > /dev/null 2>&1
set backupdir=~/.vimtmp//,.
set directory=~/.vimtmp//,.
set undodir=~/.vimtmp//,.
" Save our last spot in the file
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file (restore to previous version)
if has('persistent_undo')
set undofile " keep an undo file (undo changes after closing)
endif
endif
" line numbers
set number
set guifont=Bitstream\ Vera\ Sans\ Mono:h10:w6
set tabstop=2
set autoindent
set smartindent
set shiftwidth=2
set expandtab
set paste
" Show tabs & trailing whitespace on screen
set list
"set listchars=tab:>·,trail:✖
set listchars=tab:►·,trail:¸
"let &colorcolumn="80,".join(range(100,999),",")
set colorcolumn=79,99
" Find colors with the following command:
" : so $VIMRUNTIME/syntax/colortest.vim
"highlight ColorColumn ctermbg=grey guibg=lightgrey
highlight ColorColumn ctermbg=0
" Commit messages
autocmd FileType gitcommit set textwidth=72
" Also color commit msg
autocmd Filetype gitcommit setlocal spell colorcolumn=72,79,99
autocmd FileType gitcommit set colorcolumn+=51
autocmd FileType gitcommit highlight ColorColumn ctermbg=red
autocmd Filetype gitcommit hi SpellBad ctermbg=0
syntax enable
set syntax=automatic
fixdel
set hlsearch
set clipboard=unnamed
set backspace=indent,eol,start
set laststatus=2
set statusline=%t " filename
set statusline+=\ -\ " spacing
set statusline+=%l " Current line
set statusline+=/ " Separator
set statusline+=%L " Total lines
set statusline+=\ (%P) " % of lines
set statusline+=\ -\ " spacing
set statusline+=%F " Full path
" excape will clear highlighting after search
" nnoremap <esc> :noh<return><esc>
" Make double-<Esc> clear search highlights
" This is a cool idea but adds goofy letters if there's no highlight
"nnoremap <silent> <Esc><Esc> <Esc>:nohlsearch<CR><Esc>
" Fix stupid EOL manipulation
" http://vim.wikia.com/wiki/Preserve_missing_end-of-line_at_end_of_text_files
" Preserve noeol (missing trailing eol) when saving file. In order
" to do this we need to temporarily 'set binary' for the duration of
" file writing, and for DOS line endings, add the CRs manually.
" For Mac line endings, also must join everything to one line since it doesn't
" use a LF character anywhere and 'binary' writes everything as if it were Unix.
" This works because 'eol' is set properly no matter what file format is used,
" even if it is only used when 'binary' is set.
augroup automatic_noeol
au!
au BufWritePre * call <SID>TempSetBinaryForNoeol()
au BufWritePost * call <SID>TempRestoreBinaryForNoeol()
augroup END
function! s:TempSetBinaryForNoeol()
let s:save_binary = &binary
if ! &eol && ! &binary
let s:save_view = winsaveview()
setlocal binary
if &ff == "dos" || &ff == "mac"
if line('$') > 1
undojoin | exec "silent 1,$-1normal! A\<C-V>\<C-M>"
endif
endif
if &ff == "mac"
undojoin | %join!
" mac format does not use a \n anywhere, so we don't add one when writing
" in binary (which uses unix format always). However, inside the outer
" if statement, we already know that 'noeol' is set, so no special logic
" is needed.
endif
endif
endfunction
function! s:TempRestoreBinaryForNoeol()
if ! &eol && ! s:save_binary
if &ff == "dos"
if line('$') > 1
" Sometimes undojoin gives errors here, even when it shouldn't.
" Suppress them for now...if you can figure out and fix them instead,
" please update http://vim.wikia.com/wiki/VimTip1369
silent! undojoin | silent 1,$-1s/\r$//e
endif
elseif &ff == "mac"
" Sometimes undojoin gives errors here, even when it shouldn't.
" Suppress them for now...if you can figure out and fix them instead,
" please update http://vim.wikia.com/wiki/VimTip1369
silent! undojoin | silent %s/\r/\r/ge
endif
setlocal nobinary
call winrestview(s:save_view)
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment