Skip to content

Instantly share code, notes, and snippets.

@devx
Created January 10, 2017 20:16
Show Gist options
  • Save devx/4899f6b1324f10afe2f50dfa12c66d10 to your computer and use it in GitHub Desktop.
Save devx/4899f6b1324f10afe2f50dfa12c66d10 to your computer and use it in GitHub Desktop.
call plug#begin('~/.config/nvim/plugged')
Plug 'AndrewRadev/splitjoin.vim'
Plug 'ConradIrwin/vim-bracketed-paste'
Plug 'Raimondi/delimitMate'
Plug 'SirVer/ultisnips'
Plug 'itchyny/lightline.vim'
Plug 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'}
Plug 'elzr/vim-json', {'for' : 'json'}
Plug 'fatih/vim-go'
Plug 'tomasr/molokai'
Plug 'scrooloose/nerdtree'
Plug 'tmux-plugins/vim-tmux', {'for': 'tmux'}
Plug 'unblevable/quick-scope'
Plug 'PotatoesMaster/i3-vim-syntax'
" Plug 'tpope/vim-commentary'
" Plug 'tpope/vim-eunuch'
" Plug 'tpope/vim-fugitive'
" Plug 'tpope/vim-repeat'
" Plug 'tpope/vim-scriptease'
" Plug 't9md/vim-choosewin'
" Plug 'chriskempson/base16-vim'
" Plug 'hashivim/vim-hashicorp-tools'
" Plug 'corylanou/vim-present', {'for' : 'present'}
" Plug 'ctrlpvim/ctrlp.vim'
" Plug 'fatih/vim-hclfmt'
" Plug 'fatih/vim-nginx' , {'for' : 'nginx'}
" Plug 'w0ng/vim-hybrid'
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'zchee/deoplete-go', { 'do': 'make'}
endif
" beta usage. These are plugins I try for a while and if I like them enough
" I'll move them up
" Plug 'maralla/completor.vim'
call plug#end()
"=====================================================
"===================== SETTINGS ======================
" I'm still using Vim from time to time. These needs to enabled so we can make
" Vim usable again (these are default on NeoVim)
if !has('nvim')
set nocompatible
filetype off
filetype plugin indent on
set ttyfast
set ttymouse=xterm2
set ttyscroll=3
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 " Highlight found searches
set mouse=a
endif
set noerrorbells " No beeps
set number " Show line numbers
set showcmd " Show me what I'm typing
set noswapfile " Don't use swapfile
set nobackup " Don't create annoying backup files
set splitright " Split vertical windows right to the current windows
set splitbelow " Split horizontal windows below to the current windows
set autowrite " Automatically save before :next, :make etc.
set hidden
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
set noshowmatch " Do not show matching brackets by flickering
set noshowmode " We show the mode with airline or lightline
set ignorecase " Search case insensitive...
set smartcase " ... but not it begins with upper case
set completeopt=menu,menuone
set nocursorcolumn " speed up syntax highlighting
set nocursorline
set updatetime=400
set pumheight=10 " Completion window max size
"http://stackoverflow.com/questions/20186975/vim-mac-how-to-copy-to-clipboard-without-pbcopy
set clipboard^=unnamed
set clipboard^=unnamedplus
set viminfo='200
set lazyredraw " Wait to redraw
if has('persistent_undo')
set undofile
set undodir=~/.config/nvim/tmp/undo//
endif
if has("gui_macvim")
" No toolbars, menu or scrollbars in the GUI
set guifont=Source\ Code\ Pro:h13
set clipboard+=unnamed
set vb t_vb=
set guioptions-=m "no menu
set guioptions-=T "no toolbar
set guioptions-=l
set guioptions-=L
set guioptions-=r "no scrollbar
set guioptions-=R
let macvim_skip_colorscheme=1
colorscheme molokai
" Open goto symbol on current buffer
nmap <D-r> :MyCtrlPTag<cr>
imap <D-r> <esc>:MyCtrlPTag<cr>
" Open goto symbol on all buffers
nmap <D-R> :CtrlPBufTagAll<cr>
imap <D-R> <esc>:CtrlPBufTagAll<cr>
" Open goto file
nmap <D-t> :CtrlP<cr>
imap <D-t> <esc>:CtrlP<cr>
" Indent lines with cmd+[ and cmd+]
nmap <D-]> >>
nmap <D-[> <<
vmap <D-[> <gv
vmap <D-]> >gv
" This mapping makes Ctrl-Tab switch between tabs.
" Ctrl-Shift-Tab goes the other way.
noremap <C-Tab> :tabnext<CR>
noremap <C-S-Tab> :tabprev<CR>
" switch between tabs with cmd+1, cmd+2,..."
map <D-1> 1gt
map <D-2> 2gt
map <D-3> 3gt
map <D-4> 4gt
map <D-5> 5gt
map <D-6> 6gt
map <D-7> 7gt
map <D-8> 8gt
map <D-9> 9gt
" until we have default MacVim shortcuts this is the only way to use it in
" insert mode
imap <D-1> <esc>1gt
imap <D-2> <esc>2gt
imap <D-3> <esc>3gt
imap <D-4> <esc>4gt
imap <D-5> <esc>5gt
imap <D-6> <esc>6gt
imap <D-7> <esc>7gt
imap <D-8> <esc>8gt
imap <D-9> <esc>9gt
else
if has('!nvim')
syntax enable
set t_Co=256
set term=ansi
endif
let g:rehash256 = 1
" set background=dark
"let g:molokai_original = 1
" colorscheme base16-solar-flare
colorscheme molokai
endif
" open help vertically
command! -nargs=* -complete=help Help vertical belowright help <args>
autocmd FileType help wincmd L
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
autocmd BufNewFile,BufRead *.ino setlocal noet ts=4 sw=4 sts=4
autocmd BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4
autocmd BufNewFile,BufRead *.md setlocal noet ts=4 sw=4
autocmd BufNewFile,BufRead *.vim setlocal expandtab shiftwidth=2 tabstop=2
autocmd BufNewFile,BufRead *.hcl setlocal expandtab shiftwidth=2 tabstop=2
autocmd FileType json setlocal expandtab shiftwidth=2 tabstop=2
autocmd FileType ruby setlocal expandtab shiftwidth=2 tabstop=2
augroup filetypedetect
autocmd BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
autocmd BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx
autocmd BufNewFile,BufRead *.hcl setf conf
augroup END
"=====================================================
"===================== STATUSLINE ====================
" let s:modes = {
" \ 'n': 'NORMAL',
" \ 'i': 'INSERT',
" \ 'R': 'REPLACE',
" \ 'v': 'VISUAL',
" \ 'V': 'V-LINE',
" \ "\<C-v>": 'V-BLOCK',
" \ 'c': 'COMMAND',
" \ 's': 'SELECT',
" \ 'S': 'S-LINE',
" \ "\<C-s>": 'S-BLOCK',
" \ 't': 'TERMINAL'
" \}
" let s:prev_mode = ""
" function! StatusLineMode()
" let cur_mode = get(s:modes, mode(), '')
" " do not update higlight if the mode is the same
" if cur_mode == s:prev_mode
" return cur_mode
" endif
" if cur_mode == "NORMAL"
" exe 'hi! StatusLine ctermfg=236'
" exe 'hi! myModeColor cterm=bold ctermbg=148 ctermfg=22'
" elseif cur_mode == "INSERT"
" exe 'hi! myModeColor cterm=bold ctermbg=23 ctermfg=231'
" elseif cur_mode == "VISUAL" || cur_mode == "V-LINE" || cur_mode == "V_BLOCK"
" exe 'hi! StatusLine ctermfg=236'
" exe 'hi! myModeColor cterm=bold ctermbg=208 ctermfg=88'
" endif
" let s:prev_mode = cur_mode
" return cur_mode
" endfunction
" function! StatusLineFiletype()
" return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype : 'no ft') : ''
" endfunction
" function! StatusLinePercent()
" return (100 * line('.') / line('$')) . '%'
" endfunction
" function! StatusLineLeftInfo()
" let branch = fugitive#head()
" let filename = '' != expand('%:t') ? expand('%:t') : '[No Name]'
" if branch !=# ''
" return printf("%s | %s", branch, filename)
" endif
" return filename
" endfunction
" exe 'hi! myInfoColor ctermbg=240 ctermfg=252'
" " start building our statusline
" set statusline=
" " mode with custom colors
" set statusline+=%#myModeColor#
" set statusline+=%{StatusLineMode()}
" set statusline+=%*
" " left information bar (after mode)
" set statusline+=%#myInfoColor#
" set statusline+=\ %{StatusLineLeftInfo()}
" set statusline+=\ %*
" " go command status (requires vim-go)
" set statusline+=%#goStatuslineColor#
" set statusline+=%{go#statusline#Show()}
" set statusline+=%*
" " right section seperator
" set statusline+=%=
" " filetype, percentage, line number and column number
" set statusline+=%#myInfoColor#
" set statusline+=\ %{StatusLineFiletype()}\ %{StatusLinePercent()}\ %l:%v
" set statusline+=\ %*
"=====================================================
"===================== MAPPINGS ======================
" This comes first, because we have mappings that depend on leader
" With a map leader it's possible to do extra key combinations
" i.e: <leader>w saves the current file
let mapleader = ","
" Some useful quickfix shortcuts for quickfix
map <C-n> :cn<CR>
map <C-m> :cp<CR>
nnoremap <leader>a :cclose<CR>
" put quickfix window always to the bottom
autocmd FileType qf wincmd J
" Fast saving
nnoremap <leader>w :w!<cr>
nnoremap <silent> <leader>q :q!<CR>
" Center the screen
nnoremap <space> zz
" Remove search highlight
nnoremap <leader><space> :nohlsearch<CR>
" Source the current Vim file
nnoremap <leader>pr :Runtime<CR>
" Close all but the current one
nnoremap <leader>o :only<CR>
" Better split switching
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Print full path
map <C-f> :echo expand("%:p")<cr>
" Visual linewise up and down by default (and use gj gk to go quicker)
noremap <Up> gk
noremap <Down> gj
noremap j gj
noremap k gk
" Exit on jk
imap jk <Esc>
" Source (reload configuration)
nnoremap <silent> <F5> :source $MYNVIMRC<CR>
nnoremap <F6> :setlocal spell! spell?<CR>
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
" Same when moving up and down
noremap <C-d> <C-d>zz
noremap <C-u> <C-u>zz
" Remap H and L (top, bottom of screen to left and right end of line)
nnoremap H ^
nnoremap L $
vnoremap H ^
vnoremap L g_
" Act like D and C
nnoremap Y y$
" Enter automatically into the files directory
autocmd BufEnter * silent! lcd %:p:h
" Do not show stupid q: window
map q: :q
" Don't move on * I'd use a function for this but Vim clobbers the last search
" when you're in a function so fuck it, practicality beats purity.
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
if !has('gui_running')
set notimeout
set ttimeout
set ttimeoutlen=10
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
endif
" Visual Mode */# from Scrooloose {{{
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
" create a go doc comment based on the word under the cursor
function! s:create_go_doc_comment()
norm "zyiw
execute ":put! z"
execute ":norm I// \<Esc>$"
endfunction
nnoremap <leader>ui :<C-u>call <SID>create_go_doc_comment()<CR>
"
"===================== PLUGINS ======================
"
" ==================== Fugitive ====================
vnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gb :Gblame<CR>
" ==================== vim-go ====================
let g:go_fmt_fail_silently = 1
let g:go_fmt_command = "goimports"
let g:go_autodetect_gopath = 1
let g:go_list_type = "quickfix"
let g:go_auto_type_info = 0
let g:go_echo_command_info= 0
let g:go_highlight_space_tab_error = 0
let g:go_highlight_array_whitespace_error = 0
let g:go_highlight_trailing_whitespace_error = 0
let g:go_highlight_extra_types = 0
let g:go_highlight_build_constraints = 1
nmap <C-g> :GoDecls<cr>
imap <C-g> <esc>:<C-u>GoDecls<cr>
" 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#cmd#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
augroup go
autocmd!
autocmd FileType go nmap <silent> <Leader>v <Plug>(go-def-vertical)
autocmd FileType go nmap <silent> <Leader>s <Plug>(go-def-split)
autocmd FileType go nmap <silent> <Leader>i <Plug>(go-info)
autocmd FileType go nmap <silent> <Leader>l <Plug>(go-metalinter)
autocmd FileType go nmap <silent> <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <silent> <leader>t <Plug>(go-test)
autocmd FileType go nmap <silent> <leader>r <Plug>(go-run)
autocmd FileType go nmap <silent> <leader>e <Plug>(go-install)
autocmd FileType go nmap <silent> <Leader>d <Plug>(go-doc)
autocmd FileType go nmap <silent> <Leader>c <Plug>(go-coverage-toggle)
" I like these more!
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')
augroup END
" ==================== FZF ====================
" nnoremap <C-p> :call fzf#run({
" \ 'source': filter(copy(v:oldfiles), 'v:val !~ "NERD_tree"'),
" \ 'sink': 'e',
" \ 'options': '-m -x +s',
" \ 'down': '40%'})<CR>
" ==================== Completor ====================
" let g:completor_go_omni_trigger = '(?:\b[^\W\d]\w*|[\]\)])\.(?:[^\W\d]\w*)?'
" let g:completor_min_chars = 2
" let g:completor_disable_filename = 1
" let g:completor_disable_buffer = 1
" let g:completor_disable_ultisnips = 1
" ==================== CtrlP ====================
let g:ctrlp_cmd = 'CtrlPMRU'
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_switch_buffer = 'et' " jump to a file if it's open already
let g:ctrlp_mruf_max=450 " number of recently opened files
let g:ctrlp_max_files=0 " do not limit the number of searchable files
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_cache_dir = $HOME.'/.cache/ctrlp'
let g:ctrlp_match_window = 'bottom,order:btt,max:10,results:10'
let g:ctrlp_buftag_types = {'go' : '--language-force=go --golang-types=ftv'}
func! MyCtrlPTag()
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("t")': ['<c-t>'],
\ }
CtrlPBufTag
endfunc
command! MyCtrlPTag call MyCtrlPTag()
nmap <C-b> :CtrlPCurWD<cr>
imap <C-b> <esc>:CtrlPCurWD<cr>
" ==================== delimitMate ====================
let g:delimitMate_expand_cr = 1
let g:delimitMate_expand_space = 1
let g:delimitMate_smart_quotes = 1
let g:delimitMate_expand_inside_quotes = 0
let g:delimitMate_smart_matchpairs = '^\%(\w\|\$\)'
imap <expr> <CR> pumvisible() ? "\<c-y>" : "<Plug>delimitMateCR"
" ==================== Lightline ====================
"
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste'],
\ [ 'fugitive', 'filename', 'modified', 'ctrlpmark', 'go'] ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ] ]
\ },
\ 'component': {
\ 'go': '%#goStatuslineColor#%{LightLineGo()}',
\ },
\ 'component_visible_condition': {
\ 'go': '(exists("*go#statusline#Show") && ""!=go#statusline#Show())'
\ },
\ 'component_function': {
\ 'lineinfo': 'LightLineInfo',
\ 'percent': 'LightLinePercent',
\ 'modified': 'LightLineModified',
\ 'filename': 'LightLineFilename',
\ 'fileformat': 'LightLineFileformat',
\ 'filetype': 'LightLineFiletype',
\ 'fileencoding': 'LightLineFileencoding',
\ 'mode': 'LightLineMode',
\ 'fugitive': 'LightLineFugitive',
\ 'ctrlpmark': 'CtrlPMark',
\ },
\ }
function! LightLineModified()
if &filetype == "help"
return ""
elseif &modified
return "+"
elseif &modifiable
return ""
else
return ""
endif
endfunction
function! LightLineFileformat()
return winwidth(0) > 70 ? &fileformat : ''
endfunction
function! LightLineFiletype()
return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype : 'no ft') : ''
endfunction
function! LightLineFileencoding()
return winwidth(0) > 70 ? (strlen(&fenc) ? &fenc : &enc) : ''
endfunction
function! LightLineInfo()
return winwidth(0) > 60 ? printf("%3d:%-2d", line('.'), col('.')) : ''
endfunction
function! LightLinePercent()
return &ft =~? 'vimfiler' ? '' : (100 * line('.') / line('$')) . '%'
endfunction
function! LightLineFugitive()
return exists('*fugitive#head') ? fugitive#head() : ''
endfunction
function! LightLineGo()
return exists('*go#statusline#Show') ? go#statusline#Show() : ''
endfunction
function! LightLineMode()
let fname = expand('%:t')
return fname == 'ControlP' ? 'CtrlP' :
\ &ft == 'vimfiler' ? 'VimFiler' :
\ winwidth(0) > 60 ? lightline#mode() : ''
endfunction
function! LightLineFilename()
let fname = expand('%:t')
if mode() == 't'
return ''
endif
return fname == 'ControlP' ? g:lightline.ctrlp_item :
\ &ft == 'vimfiler' ? vimfiler#get_status_string() :
\ ('' != LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
\ ('' != fname ? fname : '[No Name]')
endfunction
function! LightLineReadonly()
return &ft !~? 'help' && &readonly ? 'RO' : ''
endfunction
function! CtrlPMark()
if expand('%:t') =~ 'ControlP'
call lightline#link('iR'[g:lightline.ctrlp_regex])
return lightline#concatenate([g:lightline.ctrlp_prev, g:lightline.ctrlp_item
\ , g:lightline.ctrlp_next], 0)
else
return ''
endif
endfunction
let g:ctrlp_status_func = {
\ 'main': 'CtrlPStatusFunc_1',
\ 'prog': 'CtrlPStatusFunc_2',
\ }
function! CtrlPStatusFunc_1(focus, byfname, regex, prev, item, next, marked)
let g:lightline.ctrlp_regex = a:regex
let g:lightline.ctrlp_prev = a:prev
let g:lightline.ctrlp_item = a:item
let g:lightline.ctrlp_next = a:next
return lightline#statusline(0)
endfunction
function! CtrlPStatusFunc_2(str)
return lightline#statusline(0)
endfunction
" ==================== NerdTree ====================
" For toggling
noremap <Leader>n :NERDTreeToggle<cr>
noremap <Leader>f :NERDTreeFind<cr>
let NERDTreeShowHidden=1
" ==================== vim-json ====================
let g:vim_json_syntax_conceal = 0
" ==================== Completion =========================
" I use deoplete for Neovim and neocomplete for Vim.
if has('nvim')
let g:deoplete#enable_at_startup = 1
let g:deoplete#ignore_sources = {}
let g:deoplete#ignore_sources._ = ['buffer', 'member', 'tag', 'file', 'neosnippet']
let g:deoplete#sources#go#sort_class = ['func', 'type', 'var', 'const']
let g:deoplete#sources#go#align_class = 1
" Use partial fuzzy matches like YouCompleteMe
call deoplete#custom#set('_', 'matchers', ['matcher_fuzzy'])
call deoplete#custom#set('_', 'converters', ['converter_remove_paren'])
call deoplete#custom#set('_', 'disabled_syntaxes', ['Comment', 'String'])
endif
" ==================== UltiSnips ====================
function! g:UltiSnips_Complete()
call UltiSnips#ExpandSnippet()
if g:ulti_expand_res == 0
if pumvisible()
return "\<C-n>"
else
call UltiSnips#JumpForwards()
if g:ulti_jump_forwards_res == 0
return "\<TAB>"
endif
endif
endif
return ""
endfunction
function! g:UltiSnips_Reverse()
call UltiSnips#JumpBackwards()
if g:ulti_jump_backwards_res == 0
return "\<C-P>"
endif
return ""
endfunction
if !exists("g:UltiSnipsJumpForwardTrigger")
let g:UltiSnipsJumpForwardTrigger = "<tab>"
endif
if !exists("g:UltiSnipsJumpBackwardTrigger")
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
endif
au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=g:UltiSnips_Reverse()<cr>"
" ==================== Various other plugin settings ====================
nmap - <Plug>(choosewin)
" Trigger a highlight in the appropriate direction when pressing these keys:
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" vim: sw=2 sw=2 et
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment