Skip to content

Instantly share code, notes, and snippets.

@igorgue
Last active August 31, 2020 04:28
Show Gist options
  • Save igorgue/2041982fef6d8af041f8fe2cb43193f0 to your computer and use it in GitHub Desktop.
Save igorgue/2041982fef6d8af041f8fe2cb43193f0 to your computer and use it in GitHub Desktop.
Configuration for nvim I also use nvim-gtk
call plug#begin('~/.config/nvim/plugged')
" Keep Plug commands between plug#begin/end.
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'itchyny/lightline.vim'
Plug 'chriskempson/vim-tomorrow-theme'
Plug 'preservim/nerdtree'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-speeddating'
Plug 'tpope/vim-git'
Plug 'michaeljsmith/vim-indent-object'
Plug 'mattn/gist-vim'
Plug 'altercation/vim-colors-solarized'
Plug 'scrooloose/syntastic'
Plug 'majutsushi/tagbar'
Plug 'preservim/nerdcommenter'
Plug 'tsaleh/vim-align'
Plug 'docunext/closetag.vim'
Plug 'vim-scripts/hexHighlight.vim'
Plug 'vim-python/python-syntax'
Plug 'chrisbra/Colorizer'
Plug 'vim-crystal/vim-crystal'
Plug 'sheerun/vim-polyglot'
"Plug 'OmniSharp/omnisharp-vim'
Plug 'sainnhe/edge'
Plug 'honza/vim-snippets'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'numirias/semshi', {'do': ':UpdateRemotePlugins'}
" Local plugs for development
Plug '~/Code/danger' " Also just 'igorgue/danger'
call plug#end()
colorscheme danger
set nocompatible " use nvim defaults
set number " show line numbers
set numberwidth=4 " line numbering takes up to 4 spaces
set ruler " show the cursor position all the time
" Set encoding
set encoding=utf-8
" Whitespace stuff
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
"set list " show list chars
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
set wildignorecase
" Completion
set wildmenu
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*,*.bak,*.exe,*.pyc,*.dll,*.pdb,*.DS_Store,*.db,env,*/debug/*,*/Debug/*,*/publish/*
let NERDTreeSortOrder=['^__\.py$', '\.pyc$', '__pycache__$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
let NERDTreeShowBookmarks=1
if has("autocmd")
" Remember last location in file
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
au BufRead,BufNewFile {*.local} set ft=vim
" Make Python follow PEP8 (http://www.python.org/dev/peps/pep-0008/)
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4
au FileType less set softtabstop=2 tabstop=2 shiftwidth=2
au FileType slim set softtabstop=2 tabstop=2 shiftwidth=2
au FileType sql set softtabstop=2 tabstop=2 shiftwidth=2
au FileType cs set softtabstop=4 tabstop=4 shiftwidth=4
" Code indentation and file detection
" Thorfile, Rakefile, Vagrantfile and Gemfile are Ruby
au BufRead,BufNewFile {Procfile.*,Gemfile,Rakefile,Capfile,Vagrantfile,Thorfile,*.ru,*.feature} set ft=ruby
au BufNewFile,BufRead *.feature setlocal tabstop=2 shiftwidth=2 softtabstop=2
" Code indentation
au FileType nim setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType yaml setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType crystal setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType coffee setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType json setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType javascript setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType vuejs setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType haskell setlocal ai
au FileType less setlocal ai
au FileType less setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType scala setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType html setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType xhtml setlocal tabstop=2 shiftwidth=2 softtabstop=2
au FileType xml setlocal tabstop=2 shiftwidth=2 softtabstop=2
endif
" Extra nerd commenter configs
let g:NERDCustomDelimiters = {
\ 'nim': { 'left': '# ', 'right': '' },
\ 'python': { 'left': '# ', 'right': '' },
\ 'ruby': { 'left': '# ', 'right': '' },
\ 'json': { 'left': '// ', 'right': '' }
\ }
" Add support for jsonc
autocmd FileType json syntax match Comment +\/\/.\+$+
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Use modeline overrides
set modeline
"set modelines=2
set shell=zsh
" Better mapleader
let mapleader = ","
" Default tab settings
set tabstop=4 " number of spaces for tab character
set shiftwidth=4 " number of spaces to (auto) indent
set softtabstop=4 " another tab change that I don't remember
set expandtab " tabs are converted to spaces
" Don't use Ex mode, use Q for formatting
"map Q gq
" Undofile vim 7.3 only
if has("undofile")
set undofile
endif
set viminfo='20,<50,s10,h
" Omni completion
"set omnifunc=syntaxcomplete#Complete
"let g:omnicomplete_fetch_full_documentation = 1
" Syntax for multiple tag files are
" Set tags=/my/dir1/tags, /my/dir2/tags
set tags=tags;$HOME/.config/nvim/tags/;$HOME/tmp/tags/ "recursively searches directory for 'tags' file
" Useful keyboard-shortcuts
if has("mac")
map <D-2> :NERDTreeToggle<CR>
map <D-3> :TagbarToggle<CR>
map <D-4> :noh<CR>
map <D-j> gj
map <D-k> gk
else
map <F2> :NERDTreeToggle<CR>
map <F3> :TagbarToggle<CR>
map <F4> :noh<CR>
map <F5> :noh<CR>
endif
" Window movement without the extra ctrl+w press only ctrl+(h,j,k,l)
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
" Fzf mappings, since I don't use ctrl+p, ctrl+n or ctrl+f to go up and down
nmap <C-p> :GFiles<CR>
nmap <C-n> :Files<CR>
nmap <C-f> :Rg<CR>
nmap <C-b> :Buffers<CR>
" Map ,e to open files in the same directory as the current file
map <leader>e :e <C-R>=expand("%:h")<cr>/
" Seriously, guys. It's not like :W is bound to anything anyway.
command! W :w
" Shortcut to rapidly toggle `set list`
nmap <leader>l :set list!<CR>
" Shortcut to map ; to :
nnoremap ; :
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
let g:menu_hidden = 0
function! ToggleMenu()
if g:menu_hidden
set guioptions+=m
let g:menu_hidden = 0
else
set guioptions-=m
let g:menu_hidden = 1
endif
endfunction
command! ToggleMenu call ToggleMenu()
nmap <F10> :ToggleMenu<CR>
" Hard mode!
function! HardMode()
map <up> iisuckatvi
map <down> iisuckatvi
map <left> iisuckatvi
map <right> iisuckatvi
imap <up> isuckatvi
imap <down> isuckatvi
imap <left> isuckatvi
imap <right> isuckatvi
endfunction
command! HardMode call HardMode()
HardMode
" Set tabs to the thing I say!!!
function! SetTabs(amount)
set tabstop=amount " number of spaces for tab character
set shiftwidth=amount " number of spaces to (auto) indent
set softtabstop=amount " another tab change that I don't remember
endfunction
command! -nargs=1 SetTabs call SetTabs(<f-args>)
" Show syntax highlighting groups for word under cursor
nmap <leader>x :call SynStack()<CR>
function! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
if has("cscope")
" Uncoment this and set if vim can't find it
set csto=0
set cst
set nocsverb
" Add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" Else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" Use ack to grep
set grepprg=rg
" All the small things(tm)
set mouse=a " enable mouse
set ls=2 " always show status line
set scrolloff=5 " keep 5 lines when scrolling
set showcmd " display incomplete commands
set showmode " display the current mode
set laststatus=2 " show last status?
set linebreak " linebreaks
set wrap " set wrap for lines
set title " show title in the console title bar
set sm " show matching braces
set ttyfast " smoother changes
set shortmess=atI " abbreviate messages
set nostartofline " don't jump to first character when paging
"set undolevels=200
set backupdir=/tmp
set showtabline=1
set hidden
set cursorline " Cursor line to see where my cursor is, smart.
set t_Co=256
set lazyredraw
let g:JSLintHighlightErrorLine = 0
set encoding=utf-8
let g:racer_experimental_completer = 1
let g:racer_insert_paren = 1
let g:rustfmt_autosave = 1
" Syntastic changes, prevent python and use right csharp checker
let g:syntastic_mode_map = { 'passive_filetypes': ['python'] }
let g:syntastic_cs_checkers = ['code_checker']
" Nim's JumpToDef
fun! JumpToDef()
if exists("*GotoDefinition_" . &filetype)
call GotoDefinition_{&filetype}()
else
exe "norm! \<C-]>"
endif
endf
" Jump to tag
nn <M-g> :call JumpToDef()<cr>
ino <M-g> <esc>:call JumpToDef()<cr>i
" Python polyglot highlight all
let g:python_highlight_all = 1
" Some changes if I ever need OmniSharp
"let g:OmniSharp_server_path = "/home/igor/.omnisharp/omnisharp-roslyn/OmniSharp.exe"
"let g:OmniSharp_selector_ui = 'fzf' " Use fzf.vim
"let g:OmniSharp_highlighting = 3
"let g:OmniSharp_server_use_mono = 1
"let g:OmniSharp_server_stdio = 0
"let g:OmniSharp_server_type = 'roslyn'
"let g:OmniSharp_prefer_global_sln = 1
"let g:OmniSharp_timeout = 60
"let g:OmniSharp_want_snippet = 1
" NVIMGtk functions
if exists('g:GtkGuiLoaded')
function Font10()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 10')
endfunction
command! Font10 call Font10()
function Font11()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 11')
endfunction
command! Font11 call Font11()
function Font12()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 12')
endfunction
command! Font12 call Font12()
function Font13()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 13')
endfunction
command! Font13 call Font13()
function Font14()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 14')
endfunction
command! Font14 call Font14()
function Font15()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 15')
endfunction
command! Font15 call Font15()
function Font16()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 16')
endfunction
command! Font16 call Font16()
function Font25()
call rpcnotify(1, 'Gui', 'Font', 'Iosevka 25')
endfunction
command! Font25 call Font25()
" Use GTK clipboard
let g:GuiInternalClipboard = 1
" Disable native popup an use nvim one instead
call rpcnotify(1, 'Gui', 'Option', 'Popupmenu', 0)
" Use Iosevka's font with C-Like features for
" operators and other characters
call rpcnotify(1, 'Gui', 'FontFeatures', 'CLIK')
Font13
endif
if has('nvim') && !exists('g:fzf_layout')
autocmd! FileType fzf
autocmd FileType fzf set laststatus=0 noshowmode noruler
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
endif
let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.5, 'border': 'sharp' } }
" Semchi
let g:semshi#simplify_markup=0
" Include coc configuration
if filereadable(expand("~/.vim.coc.local"))
source ~/.vim.coc.local
endif
" Include user's local nvim config and rewrites
if filereadable(expand("~/.nvimrc.local"))
source ~/.nvimrc.local
endif
" Colorscheme one more time
set background=dark
colorscheme danger
set nonumber
" Lightline
function! CocCurrentFunction()
return get(b:, 'coc_current_function', '')
endfunction
" let g:lightline = {
" \ 'active': {
" \ 'left': [
" \ [ 'mode', 'paste' ],
" \ [ 'gitbranch', 'filename', 'cocstatus', 'currentfunction', 'readonly', 'modified' ]
" \ ],
" \ 'right':[
" \ [ 'filetype', 'fileencoding', 'lineinfo', 'percent' ],
" \ [ 'blame' ]
" \ ],
" \ },
" \ 'component_function': {
" \ 'cocstatus': 'coc#status',
" \ 'currentfunction': 'CocCurrentFunction',
" \ 'gitbranch': 'FugitiveHead'
" \ },
" \ 'colorscheme': 'danger'
" \ }
let g:lightline = {
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'filename', 'readonly', 'modified' ]
\ ],
\ 'right':[
\ [ 'filetype', 'fileencoding', 'lineinfo', 'percent' ],
\ [ 'blame' ]
\ ],
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ 'colorscheme': 'danger'
\ }
" Use <leader><space> to run CocAction to show possible solutions to errors
" my leader key is `,` so `,<space>` then navigate via jk on the quickfix
" window
nmap <leader>a :CocAction<CR>
nmap <leader><space> :CocDiagnostics<CR>
" Configure snippets
" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)
" Use <C-j> for select text for visual placeholder of snippet.
vmap <C-j> <Plug>(coc-snippets-select)
" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<c-j>'
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<c-k>'
" Use <C-j> for both expand and jump (make expand higher priority.)
imap <C-j> <Plug>(coc-snippets-expand-jump)
" Extra quirks that I like to get rid of
set cmdheight=1
set updatetime=300
set signcolumn=auto
set noshowmode
" Set font to 14 works on my laptop on my monitor though I like 12 (:Font12)
if exists('g:GtkGuiLoaded')
Font13
set mouse=a
else
set mouse-=a
endif
exe 'hi pythonBuiltinFunc guifg=none ctermfg=none'
exe 'hi pythonBuiltinObj guifg=none ctermfg=none'
exe 'hi pythonBuiltinType guifg=none ctermfg=none'
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
if exists('*complete_info')
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment