Skip to content

Instantly share code, notes, and snippets.

@keiththomps
Created October 31, 2017 14:04
Show Gist options
  • Save keiththomps/40c691c686951e7ff7dfa72037637f63 to your computer and use it in GitHub Desktop.
Save keiththomps/40c691c686951e7ff7dfa72037637f63 to your computer and use it in GitHub Desktop.
Stripped down vim config
set nocompatible
filetype off
filetype plugin indent on
set ttyfast
set laststatus=2
set encoding=utf-8 " Set default encoding to UTF-8
set autoread " Automatically reread changed files without asking me anything
set autoindent
set backspace=indent,eol,start " Makes backspace key more powerful.
set incsearch " Shows the match while typing
set hlsearch
" Basic vim settings
set hidden
set visualbell
set number
set nobackup
set noswapfile
set noshowmode
" Set the terminal's title
set title
" Global tab width.
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
" Set to show invisibles (tabs & trailing spaces) & their highlight color
set list listchars=tab:»\ ,trail:·
" Configure spell checking
nmap <silent> <leader>p :set spell!<CR>
set spelllang=en_us
" Set leader to comma
let mapleader = ","
" Send all vim registers to the mac clipboard
set clipboard=unnamed
" Default to magic mode when using substitution
cnoremap %s/ %s/\v
cnoremap \>s/ \>s/\v
" Capture current file path into clipboard
function! CaptureFile()
let @+ = expand('%')
endfunction
map <leader>f :call CaptureFile()<cr>
" Rename current file
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'))
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
" Strip whitespace on save
fun! <SID>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfun
command -nargs=0 Stripwhitespace :call <SID>StripTrailingWhitespaces()
" Fix indentation in file
map <leader>i mmgg=G`m<CR>
" Toggle highlighting of search results
nnoremap <leader><space> :nohlsearch<cr>
" Unsmart Quotes
nnoremap guq :%s/\v[“”]/"/g<cr>
if has("autocmd")
" StripTrailingWhitespaces
autocmd BufWritePre * Stripwhitespace
" To spell check all git commit messages
au BufNewFile,BufRead COMMIT_EDITMSG set spell nonumber nolist wrap linebreak
" Set filetype tab settings
autocmd FileType ruby,json,haml,eruby,yaml,html,javascript,coffee,sass,cucumber,stylus,css,xml,htmldjango set ai ts=2 sw=2 sts=2 et
autocmd FileType python,doctest set ai ts=4 sw=4 sts=4 et
" Enable auto-completion
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
" Set Syntax Highlighting for odd file types
augroup filetypedetect
au BufNewFile,BufRead .gitconfig,.git/* set noet
au BufNewFile,BufRead Dockerfile* setf dockerfile
au BufNewFile,BufRead *.fizz setf fizz
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx
augroup END
" Set Ruby specific settings
au FileType ruby nmap <leader>bp orequire "pry"; binding.pry<esc>^
" Set Elixir specific settings
au FileType elixir nmap <leader>bp orequire IEx; IEx.pry<esc>^
" Set Go specific mappings
au FileType go set ai ts=2 sw=2 sts=2 noet nolist autowrite
au FileType fizz set ai ts=2 sw=2 sts=2 noet nolist autowrite
" Set ERB specific settings
au FileType eruby nmap <leader>bp o<% require "pry"; binding.pry %><esc>^
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment