Skip to content

Instantly share code, notes, and snippets.

@auxesis
Last active November 1, 2021 00:47
Show Gist options
  • Save auxesis/b07b85148b58ca22d723003559ddc8c2 to your computer and use it in GitHub Desktop.
Save auxesis/b07b85148b58ca22d723003559ddc8c2 to your computer and use it in GitHub Desktop.
" Much of this cribbed from https://github.com/JoshCheek/dotfiles/blob/908ad88eec6bbcc2bb64beba1b8b1a189dcb46a6/vimrc
"
" Load in plugins
execute pathogen#infect()
" ===== Smallest Viable Configuration =====
set nocompatible " Behave more usefully at the expense of backwards compatibility (this line comes first b/c it alters how the others work)
set encoding=utf-8 " Format of the text in our files (prob not necessary, but should prevent weird errors)
filetype plugin on " Load code that configures vim to work better with whatever we're editing
filetype indent on " Load code that lets vim know when to indent our cursor
syntax on " Turn on syntax highlighting
set autoindent " Apply the indentation of the current line to the next
set smartindent " Smart autoindenting when starting a new line
set expandtab " When I press tab, insert spaces instead
set shiftwidth=2 " Specifically, insert 2 spaces
set tabstop=2 " When displaying tabs already in the file, display them with a width of 2 spaces
set timeoutlen=250 " how long key sequences can take to complete
" ===== Instead of backing up files, just reload the buffer when it changes. =====
" The buffer is an in-memory representation of a file, it's what you edit
set autoread " Auto-reload buffers when file changed on disk
set nobackup " Don't use backup files
set nowritebackup " Don't backup the file while editing
set noswapfile " Don't create swapfiles for new buffers
set updatecount=0 " Don't try to write swapfiles after some number of updates
set backupskip=/tmp/*,/private/tmp/* " Let me edit crontab files
set directory=~/.vim/tmp " Where temporary files will go.
set viminfo='100,f1
" ===== Aesthetics =====
set t_Co=256 " Explicitly tell vim that the terminal supports 256 colors (iTerm2 does)
set background=dark " Tell vim to use colours that works with a dark terminal background (opposite is 'light')
colorscheme solarized " Use the solarized theme
set nowrap " Display long lines as truncated instead of wrapped onto the next line
set cursorline " Colour the line the cursor is on
hi CursorLine term=none cterm=none ctermbg=0
set number " Show line numbers
"set hlsearch " Highlight all search matches that are on the screen
set showcmd " Display info known about the command being edited (eg number of lines highlighted in visual mode)
set colorcolumn=80 " Add a column at the 80 char mark, for visual reference
set listchars=tab:>-,trail:. " Display unwanted whitespace
set list
" ===== Searching behaviour =====
set ignorecase " Ignore the case of normal letters (like //i at the end of end a regex)
set smartcase " Override the 'ignorecase' option if the search pattern contains upper case characters.
set incsearch " While typing a search command, show where the pattern matches.
" ===== Input =====
" Line wrapping – turn it off
set textwidth=0 " Maximum width of text that is being inserted (0 disables)
set wrapmargin=0 " Number of characters from the right window border where wrapping starts.
set backspace=indent,eol,start " make backspace work on macOS
" remap C-w so it works on homebrew vim
" needs to be on a line of its own
imap <C-w> <C-o>db
" ===== Status =====
"set guioptions+=T
set statusline=%F%m%r%h%w\ [POS=%04l,%04v]\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [LEN=%L]
set laststatus=2 " always show the statusline
let &titleold="bash"
let &titlestring = "vim(" . expand("%:t") . ")"
if &term == "screen"
set t_ts=k
set t_fs=\
endif
if &term == "screen" || &term == "xterm"
set title
endif
" ===== Output =====
" Remove trailing spaces - http://vim.wikia.com/wiki/Remove_unwanted_spaces
function TrimWhiteSpace()
%s/\s*$//
''
:endfunction
au FileWritePre * :call TrimWhiteSpace()
au FileAppendPre * :call TrimWhiteSpace()
au FilterWritePre * :call TrimWhiteSpace()
au BufWritePre * :call TrimWhiteSpace()
" Fix problem with git gutter and prettier, where the window gets corrupted
"au FileWritePost * :redraw!
"au FileAppendPost * :redraw!
"au FilterWritePost * :redraw!
"au BufWritePost * :redraw!
" ===== Filetype behaviours =====
au BufRead,BufNewFile *.pp set filetype=puppet
au BufRead,BufNewFile *.haml set filetype=haml
au BufRead,BufNewFile *.scala set filetype=scala
au BufRead,BufNewFile *.feature set filetype=cucumber
au BufRead,BufNewFile *.md set filetype=markdown
au BufRead,BufNewFile *.erb set filetype=eruby
au BufRead,BufNewFile *.thor set filetype=ruby
au BufRead,BufNewFile *.ru set filetype=ruby
au BufRead,BufNewFile *.markdown set filetype=markdown
au BufRead,BufNewFile COMMIT_EDITMSG set expandtab
au BufRead,BufNewFile *.rabl setf ruby
au BufRead,BufNewFile *.json set filetype=json
au BufRead,BufNewFile *.ejson set filetype=json
au BufRead,BufNewFile *.mdx set filetype=MARKDOWN.MDX
au BufRead,BufNewFile *.yml set filetype=yaml
au BufRead,BufNewFile *.hcl set filetype=terraform
au FileType python set ts=4 sw=4 tw=100 sts=4 expandtab
au FileType ruby set ts=2 sw=2 tw=100 sts=2 expandtab
au FileType javascript set ts=2 sw=2 tw=100 sts=2 expandtab
au FileType MARKDOWN.MDX set ts=2 sw=2 tw=100 sts=2 expandtab
au FileType html set ts=2 sw=2 tw=100 sts=2 expandtab
au FileType eruby set ts=2 sw=2 expandtab
au FileType haml set ts=2 sw=2 expandtab
au FileType css set expandtab
au FileType cucumber set ts=2 sw=2 expandtab
au FileType markdown set ai formatoptions=tcroqn2 comments=n:> expandtab
au FileType puppet set expandtab
au FileType perl set expandtab
au FileTYpe treetop set expandtab
au FileType php set ts=4 sw=4 tw=100 sts=2 expandtab
au FileType cfg set ts=2 sw=2 expandtab
au Filetype sh set expandtab
au Filetype coffee set expandtab
au Filetype go set ts=4 sw=4 sts=4 nolist noexpandtab
au Filetype c set ts=4 sw=4 nolist
au FileType json set ts=2 sw=2 expandtab
au FileType terraform set nolist
au FileType yaml set expandtab
" Writing mode shortcut
command! -nargs=* Writing set wrap linebreak nolist nu columns=80
" Align data
function IndentV()
Tabularize /^[^:]*\zs:/r1c0l0
Tabularize /^[^=>]*\zs=>/l1
endfunction
map <Leader>iv :call IndentV()<cr>
" golint
set rtp+=$GOPATH/src/github.com/golang/lint/misc/vim
autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
" gofumpt + gopls
"let g:go_fmt_command="gopls"
"let g:go_gopls_gofumpt=1
" Python black
autocmd BufWritePre *.py execute ':Black'
" JavaScript prettier
let g:prettier#quickfix_enabled = 1
let g:prettier#autoformat_config_present = 1 " only run if a config file is present
"autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css Prettier ",*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html,*.mdx Prettier
"autocmd TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css PrettierAsync " ,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html PrettierAsync
" vim-mix-format
let g:mix_format_on_save = 1
"autocmd BufWritePost,FileWritePost *.ex execute 'MixFormat' | cwindow
" ===== CSV =====
let g:csv_highlight_column = 'y'
" Enable rufo (RUby FOrmat)
let g:rufo_auto_formatting = 1
" ===== Terraform =====
let g:terraform_align=1 " align settings automatically with Tabularize
let g:terraform_fmt_on_save=1 " automatically format *.tf and *.tfvars files with terraform fmt
$ ls -1 .vim/bundle/
Dockerfile
black
rufo-vim
tabular
vim-ansible-yaml
vim-elixir
vim-gitgutter
vim-go
vim-javascript
vim-json
vim-jsx
vim-mdx-js
vim-mix-format
vim-prettier
vim-puppet
vim-rsi
vim-signature
vim-terraform
vim-toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment