Skip to content

Instantly share code, notes, and snippets.

@chongchonghe
Last active September 20, 2020 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chongchonghe/5ae253bdc4fecb3d0744856eb9e35b1a to your computer and use it in GitHub Desktop.
Save chongchonghe/5ae253bdc4fecb3d0744856eb9e35b1a to your computer and use it in GitHub Desktop.
A minimal vim configuration file
" A minimal .vimrc with no plugin manager required
" About: This file is a combination of Integralist/.vimrc on github and a bunch of
" scripts I found useful.
" Author: Chong-Chong He
" Email: che1234@umd.edu
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" The following script is downloaded from
" Integralist/.vimrc: https://gist.github.com/Integralist/b435e36cfb3fdea1579b8f342b72974e
" Now the link failed and here is Integralist's new .vimrc:
" https://github.com/Integralist/dotfiles/blob/master/.vimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use the system clipboard
set clipboard+=unnamed
" Switch syntax highlighting on
syntax on
" Don't worry about trying to support old school Vi features
set nocompatible
" No backup files
"set nobackup
" No write backup
set nowritebackup
" No swap file
"set noswapfile
" Command history
set history=100
" Always show cursor
set ruler
" Show incomplete commands
set showcmd
" Incremental searching (search as you type)
set incsearch
" Highlight search matches
set hlsearch
" Ignore case in search
set smartcase
" Make sure any searches /searchPhrase doesn't need the \c escape character
set ignorecase
" A buffer is marked as ‘hidden’ if it has unsaved changes, and it is not currently loaded in a window
" If you try and quit Vim while there are hidden buffers, you will raise an error:
" E162: No write since last change for buffer “a.txt”
set hidden
" Turn word wrap off
set nowrap
" Allow backspace to delete end of line, indent and start of line characters
set backspace=indent,eol,start
" Convert tabs to spaces
set expandtab
" Set tab size in spaces (this is for manual indenting)
set tabstop=2
" The number of spaces inserted for a tab (used for auto indenting)
set shiftwidth=2
" Turn on line numbers
set number
" Highlight tailing whitespace
"set list listchars=tab:\ \ ,trail:·
" Get rid of the delay when pressing O (for example)
" http://stackoverflow.com/questions/2158516/vim-delay-before-o-opens-a-new-line
set timeout timeoutlen=1000 ttimeoutlen=100
" Always show status bar
set laststatus=2
" Set the status line to something useful
set statusline=%f\ %m\ %=L:%l/%L\ C:%c\ (%p%%)
" UTF encoding
set encoding=utf-8
" Autoload files that have changed outside of vim
set autoread
" Better splits (new windows appear below and to the right)
set splitbelow
set splitright
" Highlight the current line
set cursorline
" Ensure Vim doesn't beep at you every time you make a mistype
"set visualbell
" Visual autocomplete for command menu (e.g. :e ~/path/to/file)
set wildmenu
" Redraw only when we need to (i.e. don't redraw when executing a macro)
set lazyredraw
" Highlight a matching [{()}] when cursor is placed on start/end character
set showmatch
" <C-x><C-k> for word autocomplete
set dictionary=/usr/share/dict/words
" Use Ag for :grep command (would use Sift but it doesn't work well)
set grepprg=ag\ --nogroup\ --nocolor
" vim-go
let g:go_fmt_command = "goimports"
let g:go_metalinter_autosave = 1
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
fun! StripTrailingWhitespace()
" Don't strip on these filetypes
if &ft =~ 'markdown'
return
endif
%s/\s\+$//e
endfun
autocmd BufWritePre * call StripTrailingWhitespace()
autocmd Filetype gitcommit setlocal spell textwidth=72
autocmd Filetype markdown setlocal wrap linebreak nolist textwidth=0 wrapmargin=0 " http://vim.wikia.com/wiki/Word_wrap_without_line_breaks
autocmd FileType sh,cucumber,ruby,yaml,zsh,vim setlocal shiftwidth=2 tabstop=2 expandtab
" Specify syntax highlighting for specific files
autocmd Bufread,BufNewFile *.spv set filetype=php
autocmd Bufread,BufNewFile *.md set filetype=markdown " Vim interprets .md as 'modula2' otherwise, see :set filetype?
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" End of Integralist/.vimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" different syntax highlight color scheme for vimdiff mode
highlight! link DiffText Todo
"" The following is not working
if &diff
syntax off
endif
""split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
"nmap <C-h> <C-w>h
"nmap <C-j> <C-w>j
"nmap <C-k> <C-w>k
"nmap <C-l> <C-w>l
" spell checking
autocmd BufRead,BufNewFile *.md setlocal spell spelllang=en_us
autocmd BufRead,BufNewFile *.tex setlocal spell spelllang=en_us
let $max_print_line=1024
"" Python PEP8 indentation
au BufNewFile,BufRead *.py
\ set tabstop=4 |
\ set softtabstop=4 |
\ set shiftwidth=4 |
\ set textwidth=79 |
\ set expandtab |
\ set autoindent |
\ set fileformat=unix
au BufNewFile,BufRead *.js, *.html, *.css
\ set tabstop=2 |
\ set softtabstop=2 |
\ set shiftwidth=2
" Flagging Unnecessary Whitespace
"au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
" OPTIONAL: This enables automatic indentation as you type.
filetype indent on
" ignores the case. set noic to disable
set ic
" Allow copy to system clipboard
" Ref: https://vi.stackexchange.com/questions/84/how-can-i-copy-text-to-the-system-clipboard-from-vim
noremap ,y "*y
noremap ,p "*p
noremap ,Y "+y
noremap ,P "+p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment