Skip to content

Instantly share code, notes, and snippets.

@bjacobowski
Created November 29, 2017 15:42
Show Gist options
  • Save bjacobowski/4d07178f47b021c60af24edb3b166620 to your computer and use it in GitHub Desktop.
Save bjacobowski/4d07178f47b021c60af24edb3b166620 to your computer and use it in GitHub Desktop.
Vim settings (Vundle and plugin settings sourced at ~/.vimrc_plugins)
"******************************************************************************
" ~/.vimrc
" [email protected]
"******************************************************************************
set nocompatible " be iMproved
"------------------------------------------------------------------------------
" General
"------------------------------------------------------------------------------
" Disable automatic comment insertion
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
set autochdir " automatically change working directory when files opened
set autoindent " copy indent from current line when starting a new line
set autowrite " automatically write content of file if :make called
set backspace=eol,start,indent " make backspace work how you expect
set whichwrap+=<,>,h,l " cont.
"set clipboard=unnamedplus " alias unnamed register to the '+' register
set directory=~/.vim/swap " swap directory
set lazyredraw " don't redraw while executing macros
set magic " for regex
set ttyfast " fast terminal mode
" Tabs
set expandtab " use spaces instead of tab
set tabstop=4 " number of spaces that equals a tab
"set shiftwidth=4 "
"set softtabstop=4 "
" Searching
set hlsearch " highlight search results
set ignorecase " ignore case when searching
set incsearch " make search act like browser search
set smartcase " try to be smart about cases when searching
" Splits
set splitbelow " new horizontal split positioned below current pane
set splitright " new vertical split positioned to right of current pane
" Beep and flash
set noerrorbells novisualbell " Disable beep and flash
set t_vb= tm=500 " cont.
set mat=2 " how many tenths of a second to show matching brackets
" Formatting
set colorcolumn=100 " vertical line at column
set cursorline " highlight cursor position
set number " show line numbers
set relativenumber " show relative line numbers
set laststatus=2 " always display status line
set showtabline=2 " always display tabline
set noshowmode " do not show mode on last line
set ruler " show current position
set showcmd " show command in last line of screen
set showmatch " match brackets
" Strings to use in list mode
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
" Command-line completion menu
set wildmenu " turn on
set wildignore=*.o,*~,*.pyc " ignore compiled files
set wildchar=<Tab> " char to start wildcard expansion on command-line
set wildmode=full " next full match
"------------------------------------------------------------------------------
" Colors and Fonts
"------------------------------------------------------------------------------
syntax enable
" set extra options when running in GUI mode
if has("gui_running")
set guioptions-=T
set guioptions+=e
set t_Co=256
set guitablabel=%\ % t
endif
set background=dark
highlight CursorLine term=NONE
highlight clear CursorLineNR
set encoding=utf8
set ffs=unix,dos,mac
augroup BgHighlight
autocmd!
autocmd WinEnter * set relativenumber
autocmd WinLeave * set norelativenumber | set number
augroup END
if &term =~ "^xterm\\|rxvt\\|screen"
let &t_SI="\e[3 q"
let &t_EI="\e[0 q"
"autocmd VimLeave * silent !echo -ne "\003]12;gray\007"
endif
if exists("$TMUX")
let &t_SI="\<Esc>Ptmux;\<Esc>\e[3 q\<Esc>\\"
let &t_EI="\<Esc>Ptmux;\<Esc>\e[0 q\<Esc>\\"
endif
"------------------------------------------------------------------------------
" Files, backups, and undo
"------------------------------------------------------------------------------
set nobackup
set nowb
"set noswapfile
"------------------------------------------------------------------------------
" Text, tab, and indent
"------------------------------------------------------------------------------
set expandtab " use spaces instead of tabs
set smarttab "
set shiftwidth=4 " 1 tab == 4 spaces
set tabstop=4 " cont.
set lbr " linebreak at 500 characters
set tw=500 " cont.
set ai " Auto indent
set si " Smart indent
set wrap " Wrap lines
"------------------------------------------------------------------------------
" Visual mode
"------------------------------------------------------------------------------
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
"------------------------------------------------------------------------------
" Movements
"------------------------------------------------------------------------------
"map j gj
"map k gk
map <space> /
map <c-space> ?
" Move between windows with C-[hjkl]
map <C-h> <C-W>h
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-l> <C-W>l
map <leader>bd :Bclose<cr>
map <leader>ba :1,1000 bd!<cr>
" Mappings for tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove<cr>
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/ " open new tab with the current buffer's path
map <leader>cd :cd %:p:h<cr>:pwd<cr> " switch cwd to directory of open buffer
" specify the behavior when switching beween buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" return to last edit position when opening files
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" remember info about open buffers on close
set viminfo^=%
"------------------------------------------------------------------------------
" Key Mappings
"------------------------------------------------------------------------------
" Open/Reload .vimrc
map <F6> :source $MYVIMRC<CR>
map <F9> :vsplit $MYVIMRC<CR>
" Open config files
map <leader>zrc :e ~/.config/zsh/.zshrc<CR>
map <leader>za :e ~/.config/zsh/zsh.d/aliases.zsh<CR>
map <leader>xrc :e ~/.xmonad/xmonad.hs<CR>
"map <S-Space> <PageUp> " unfortunately terminal doesn't recognize <S-Space>
" Center screen on searches
nmap n nzz
nmap N Nzz
" play macro recorded to q
nnoremap <leader>q @q|
map Q gql
" Toggles
nmap <leader>l :set list!<CR>
nnoremap <silent><leader>n :set relativenumber!<CR>
nmap <leader>w :set wrap!<CR>
" toggle search highlights
map <leader>f :set hls!<CR>
imap <leader>f <Esc>:set hls!<CR>a
vmap <leader>f <Esc>:set hls!<CR>gv
" show messages
nmap <leader>m :messages<CR>
" jk to exit insert mode
map! jk <Esc>
" <F1> for help on word under cursor
nnoremap <F1> :help <C-r><C-w><CR>
" <C-U> deletes a lot in insert-mode. Use <C-G>u to first break undo so that
" you can undo <C-U> after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
"------------------------------------------------------------------------------
" Functions
"------------------------------------------------------------------------------
" Allow sudo write
cmap w!! w !sudo tee > /dev/null %
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ wincmd p | diffthis
endif
function! Dos2unix()
update
e ++ff=dos
setlocal ff=unix
w
endfunction
command! -nargs=0 D2u :call Dos2unix()
function! Unix2dos()
update
e ++ff=dos
w
endfunction
command! -nargs=0 U2d :call Unix2dos()
set nohlsearch
"------------------------------------------------------------------------------
" Plugins
"------------------------------------------------------------------------------
try
source ~/.vimrc_plugins
catch
" No such file? No problem, ignore it.
endtry
"******************************************************************************
" ~/.vimrc_plugins
" [email protected]
"******************************************************************************
"------------------------------------------------------------------------------
" Vundle Plugin Manager
"------------------------------------------------------------------------------
set nocompatible " be iMproved, required (vundle)
filetype off " required (vundle)
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle (required)
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/syntastic'
Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}
Plugin 'racer-rust/vim-racer'
"Plugin 'jiangmiao/auto-pairs'
Plugin 'dag/vim2hs'
Plugin 'lukerandall/haskellmode-vim'
Plugin 'bitc/vim-hdevtools'
"Plugin 'Rip-Rip/clang_complete'
Plugin 'fatih/vim-go'
Plugin 'AndrewRadev/splitjoin.vim'
Plugin 'ctrlpvim/ctrlp.vim'
" All plugins must be added before the following line
call vundle#end() " required (vundle)
filetype plugin on " required (vundle)
"------------------------------------------------------------------------------
" NERDTree
"------------------------------------------------------------------------------
map <F2> :NERDTreeToggle<CR>
let g:NERDTreeShowHidden=1
"------------------------------------------------------------------------------
" YouCompleteMe
"------------------------------------------------------------------------------
let g:ycm_global_ycm_extra_conf = '/usr/share/vim/vimfiles/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf = 0
let g:ycm_server_python_interpreter = '/usr/bin/python2'
"------------------------------------------------------------------------------
" Syntastic
"------------------------------------------------------------------------------
set statusline+=%#warningsmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
"------------------------------------------------------------------------------
" Go
"------------------------------------------------------------------------------
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>
nnoremap <leader>a :cclose<CR>
"autocmd FileType go nmap <leader>b <Plug>(go-build)
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
autocmd FileType go nmap <Leader>i <Plug>(go-info)
let g:go_auto_type_info = 1
let g:go_auto_sameids = 1
let g:go_metalinter_autosave = 1
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
let g:go_test_timeout = '10s'
let g:go_fmt_command = "goimports"
"------------------------------------------------------------------------------
" Haskell
"------------------------------------------------------------------------------
" Haskellmode-Vim
au BufEnter *.hs compiler ghc
let g:ghc="/usr/bin/ghc"
let g:haddock_browser="/usr/bin/midori"
let g:haddock_browser_nosilent = 1
" vim-hdevtools
au FileType haskell nnoremap <buffer> <F1> :HdevtoolsType<CR>
au FileType haskell nnoremap <buffer> <silent> <F2> :HdevtoolsClear<CR>
"------------------------------------------------------------------------------
" auto-pairs
"------------------------------------------------------------------------------
"let g:AutoPairsMapCR = 0
"imap <silent><CR> <CR><Plug>AutoPairsReturn
"------------------------------------------------------------------------------
" clang_complete
"------------------------------------------------------------------------------
"let g:clang_library_path='/usr/lib'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment