Created
February 21, 2020 12:37
-
-
Save alduro/81574d4dd9d7156aaf4bf3a38107dc91 to your computer and use it in GitHub Desktop.
~/.config/nvim/init.vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if has('vim_starting') | |
set runtimepath+=~/.config/nvim/ | |
endif | |
" Coc setup | |
set hidden | |
set nobackup | |
set nowritebackup | |
" Better display for messages | |
set cmdheight=1 | |
" You will have bad experience for diagnostic messages when it's default 4000. | |
set updatetime=300 | |
" don't give |ins-completion-menu| messages. | |
set shortmess+=c | |
" always show signcolumns | |
set signcolumn=yes | |
" End of sets for Coc setup | |
filetype plugin indent on | |
let mapleader = ',' | |
set wildmenu | |
set autoread | |
set nocompatible | |
" folding | |
set foldmethod=indent | |
set foldnestmax=10 | |
set nofoldenable | |
set foldlevel=2 | |
set encoding=utf8 | |
set fillchars="" | |
set laststatus=2 | |
set showtabline=2 | |
set undofile | |
set undodir="$HOME/.VIM_UNDO_FILES" | |
set noshowmode | |
set clipboard=unnamed | |
" Remember cursor position between vim sessions | |
autocmd BufReadPost * | |
\ if line("'\"") > 0 && line ("'\"") <= line("$") | | |
\ exe "normal! g'\"" | | |
\ endif | |
" center buffer around cursor when opening files | |
autocmd BufRead * normal zz | |
set guifont=Menlo\ Regular:h16 | |
call plug#begin('~/.config/nvim/plugged') | |
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } | |
Plug 'tpope/vim-surround' | |
Plug 'flazz/vim-colorschemes' | |
Plug 'slashmili/alchemist.vim' | |
Plug 'elixir-editors/vim-elixir' | |
Plug 'mhinz/vim-mix-format' | |
Plug 'othree/yajs.vim' | |
Plug 'epilande/vim-es2015-snippets' | |
Plug 'epilande/vim-react-snippets' | |
Plug 'mhartington/oceanic-next' | |
Plug 'mxw/vim-jsx' | |
Plug 'terryma/vim-multiple-cursors' | |
Plug 'ryanoasis/vim-devicons' | |
Plug 'szw/vim-tags' | |
Plug 'jremmen/vim-ripgrep' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'tpope/vim-fugitive' | |
Plug 'honza/vim-snippets' | |
Plug 'othree/jspc.vim', { 'for': ['javascript', 'javascript.jsx'] } | |
Plug 'tyrannicaltoucan/vim-quantum' | |
Plug 'othree/html5.vim' | |
Plug 'Shougo/neosnippet' | |
Plug 'Shougo/neosnippet-snippets' | |
Plug 'reasonml-editor/vim-reason-plus' | |
Plug 'raimondi/delimitMate' | |
Plug 'cakebaker/scss-syntax.vim' | |
Plug 'ap/vim-css-color' | |
Plug 'mattn/emmet-vim' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'rakr/vim-one' | |
Plug 'thoughtbot/vim-rspec' | |
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
Plug 'guns/vim-sexp' | |
Plug 'tpope/vim-fireplace' | |
Plug 'tpope/vim-sexp-mappings-for-regular-people' | |
Plug 'luochen1990/rainbow' | |
Plug 'tpope/vim-sensible' | |
Plug 'lifepillar/vim-solarized8' | |
Plug 'joshdick/onedark.vim' | |
Plug 'tpope/vim-salve' | |
Plug 'liuchengxu/vim-clap', { 'do': function('clap#helper#build_all') } | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
Plug 'ngmy/vim-rubocop' | |
Plug 'w0rp/ale' | |
Plug 'haishanh/night-owl.vim' | |
Plug 'evanleck/vim-svelte' | |
Plug 'kchmck/vim-coffee-script' | |
Plug 'mustache/vim-mustache-handlebars' | |
call plug#end() | |
" Themes | |
" set background=dark | |
" let g:oceanic_next_terminal_bold = 1 | |
" let g:oceanic_next_terminal_italic = 1 | |
" set Vim-specific sequences for RGB colors | |
" set termguicolors | |
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum" | |
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" | |
set t_Co=256 | |
set termguicolors | |
syntax on | |
set background=dark | |
colorscheme night-owl | |
" Default mapping | |
let g:multi_cursor_next_key='<C-n>' | |
let g:multi_cursor_prev_key='<C-p>' | |
let g:multi_cursor_skip_key='<C-x>' | |
let g:multi_cursor_quit_key='<Esc>' | |
"default tab settitgs | |
set sw=2 | |
set softtabstop=2 | |
set expandtab | |
set cursorline | |
set number | |
"set relativenumber | |
set showmatch | |
set shiftwidth=2 | |
set smartindent | |
" If installed using git | |
set rtp+=~/.fzf | |
function! s:buflist() | |
redir => ls | |
silent ls | |
redir END | |
return split(ls, '\n') | |
endfunction | |
function! s:bufopen(e) | |
execute 'buffer' matchstr(a:e, '^[ 0-9]*') | |
endfunction | |
"\ 'down': len(<sid>buflist()) + 2 | |
nnoremap <silent> <Leader><Enter> :call fzf#run({ | |
\ 'source': reverse(<sid>buflist()), | |
\ 'sink': function('<sid>bufopen'), | |
\ 'options': '+m', | |
\ 'down': '40%' | |
\ })<CR> | |
function! s:tags_sink(line) | |
let parts = split(a:line, '\t\zs') | |
let excmd = matchstr(parts[2:], '^.*\ze;"\t') | |
execute 'silent e' parts[1][:-2] | |
let [magic, &magic] = [&magic, 0] | |
execute excmd | |
let &magic = magic | |
endfunction | |
function! s:tags() | |
if empty(tagfiles()) | |
echohl WarningMsg | |
echom 'Preparing tags' | |
echohl None | |
call system('ctags -R') | |
endif | |
call fzf#run({ | |
\ 'source': 'cat '.join(map(tagfiles(), 'fnamemodify(v:val, ":S")')). | |
\ '| grep -v ^!', | |
\ 'options': '+m -d "\t" --with-nth 1,4.. -n 1 --tiebreak=index', | |
\ 'down': '40%', | |
\ 'sink': function('s:tags_sink')}) | |
endfunction | |
command! Tags call s:tags() | |
" | |
" Replace the default dictionary completion with fzf-based fuzzy completion | |
inoremap <expr> <c-x><c-k> fzf#complete('cat /usr/share/dict/words') | |
imap <c-x><c-l> <plug>(fzf-complete-line) | |
" | |
" This is the default extra key bindings | |
let g:fzf_action = { | |
\ 'ctrl-t': 'tab split', | |
\ 'ctrl-x': 'split', | |
\ 'ctrl-v': 'vsplit' } | |
" Default fzf layout | |
" - down / up / left / right | |
let g:fzf_layout = { 'down': '~40%' } | |
" Customize fzf colors to match your color scheme | |
let g:fzf_colors = | |
\ { 'fg': ['fg', 'Normal'], | |
\ 'bg': ['bg', 'Normal'], | |
\ 'hl': ['fg', 'Comment'], | |
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], | |
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], | |
\ 'hl+': ['fg', 'Statement'], | |
\ 'info': ['fg', 'PreProc'], | |
\ 'prompt': ['fg', 'Conditional'], | |
\ 'pointer': ['fg', 'Exception'], | |
\ 'marker': ['fg', 'Keyword'], | |
\ 'spinner': ['fg', 'Label'], | |
\ 'header': ['fg', 'Comment'] } | |
" | |
" Enable per-command history. | |
" CTRL-N and CTRL-P will be automatically | |
" bound to next-history and | |
" " previous-history instead of down and up. If | |
" you don't like the change, | |
" " explicitly bind the keys to down and up in | |
" your $FZF_DEFAULT_OPTS. | |
let g:fzf_history_dir = '~/.fzf-history' | |
" [Files] Extra options for fzf | |
" e.g. File preview using CodeRay (http://coderay.rubychan.de/) | |
let g:fzf_files_options = | |
\ '--preview "(coderay {} || cat {}) 2> /dev/null | head -'.&lines.'"' | |
" [Buffers] Jump to the existing window if possible | |
let g:fzf_buffers_jump = 1 | |
" [[B]Commits] Customize the options used by 'git log': | |
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"' | |
" [Tags] Command to generate tags file | |
let g:fzf_tags_command = 'ctags -R' | |
" [Commands] --expect expression for directly executing the command | |
let g:fzf_commands_expect = 'alt-enter,ctrl-x' | |
let local_eslint = finddir('node_modules', '.;') . '/.bin/eslint' | |
if matchstr(local_eslint, "^\/\\w") == '' | |
let local_eslint = getcwd() . "/" . local_eslint | |
endif | |
if executable(local_eslint) | |
let g:syntastic_javascript_eslint_exec = local_eslint | |
endif | |
let g:airline_powerline_fonts = 1 | |
let g:airline_theme='oceanicnext' | |
let g:airline#extensions#branch#enabled = 1 | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#left_sep = ' ' | |
let g:airline#extensions#tabline#left_alt_sep = '|' | |
" NerdTree | |
map <silent> - :NERDTreeToggle<CR> | |
let g:NERDTreeDirArrowExpandable = '►' | |
let g:NERDTreeDirArrowCollapsible = '▼' | |
let NERDTreeQuitOnOpen = 1 | |
let NERDTreeAutoDeleteBuffer = 1 | |
let NERDTreeMinimalUI = 1 | |
let NERDTreeDirArrows = 1 | |
fun! <SID>StripTrailingWhitespaces() | |
let l = line(".") | |
let c = col(".") | |
%s/\s\+$//e | |
call cursor(l, c) | |
endfun | |
autocmd FileType ruby,elixir,css,javascript,elm autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces() | |
command! -bang -nargs=* Rg | |
\ call fzf#vim#grep( | |
\ 'rg --column --line-number --hidden --ignore-case --no-heading --color=always '.shellescape(expand('<cword>')), 1, | |
\ <bang>0 ? fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%') | |
\ : fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'right:50%:hidden', '?'), | |
\ <bang>0) | |
"command! -bang -nargs=* Find | |
" \ call fzf#vim#grep( | |
" \ 'rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --color "always" '.shellescape(<q-args>).'| tr -d "\017"', 1, <bang>0) | |
function! RipgrepFzf(query, fullscreen) | |
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true' | |
let initial_command = printf(command_fmt, shellescape(a:query)) | |
let reload_command = printf(command_fmt, '{q}') | |
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]} | |
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen) | |
endfunction | |
" Reverse the layout to make the FZF list top-down | |
let $FZF_DEFAULT_OPTS='--layout=reverse' | |
" Using the custom window creation function | |
let g:fzf_layout = { 'window': 'call FloatingFZF()' } | |
" Function to create the custom floating window | |
function! FloatingFZF() | |
" creates a scratch, unlisted, new, empty, unnamed buffer | |
" to be used in the floating window | |
let buf = nvim_create_buf(v:false, v:true) | |
" 90% of the height | |
let height = float2nr(&lines * 0.5) | |
" 60% of the height | |
let width = float2nr(&columns * 0.6) | |
" horizontal position (centralized) | |
let horizontal = float2nr((&columns - width) / 2) | |
" vertical position (one line down of the top) | |
let vertical = 1 | |
let opts = { | |
\ 'relative': 'editor', | |
\ 'row': vertical, | |
\ 'col': horizontal, | |
\ 'width': width, | |
\ 'height': height | |
\ } | |
" open the new window, floating, and enter to it | |
call nvim_open_win(buf, v:true, opts) | |
endfunction | |
command! -nargs=* -bang Find call RipgrepFzf(<q-args>, <bang>0) | |
nnoremap <C-f> :Files<Cr> | |
nnoremap <C-d> :Find<Cr> | |
nnoremap <C-s> :Rg<Cr> | |
nnoremap <leader><Cr> :Buffers<Cr> | |
let g:python_host_prog = '/usr/bin/python2' | |
let g:python3_host_prog = '/Users/aldo/.pyenv/shims/python3' | |
let g:node_host_prog = '/Users/aldo/.asdf/installs/nodejs/12.6.0/.npm/bin/neovim-node-host' | |
" set completeopt=longest,menuone,preview | |
set completeopt=noinsert,menuone,noselect | |
autocmd FileType javascript let g:SuperTabDefaultCompletionType = "<c-x><c-o>" | |
let g:UltiSnipsExpandTrigger="<C-j>" | |
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" | |
" Make JSX syntax work on *.js | |
let g:jsx_ext_required = 0 | |
let g:ale_linters = { | |
\ 'javascript': ['eslint'], | |
\ 'ruby': ['rubocop'], | |
\} | |
" Only run linters named in ale_linters settings. | |
let g:ale_linters_explicit = 1 | |
let g:ale_sign_error = '>>' | |
let g:ale_sign_warning = '--' | |
" Set this. Airline will handle the rest. | |
let g:airline#extensions#ale#enabled = 1 | |
let g:ale_echo_msg_error_str = 'E' | |
let g:ale_echo_msg_warning_str = 'W' | |
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]' | |
let g:ale_sign_column_always = 1 | |
" Disable ALE auto highlights | |
let g:ale_set_highlights = 0 | |
let g:mix_format_on_save = 1 | |
let g:mix_format_options = '--check-equivalent' | |
let g:mix_format_silent_errors = 1 | |
let g:ale_fixers = { | |
\ 'javascript': ['prettier', 'eslint'], | |
\ 'jsx': ['prettier', 'eslint'], | |
\ 'flow': ['prettier'], | |
\ 'typescript': ['prettier'], | |
\ 'css': ['prettier'], | |
\ 'less': ['prettier'], | |
\ 'scss': ['prettier'], | |
\ 'json': ['prettier'], | |
\ 'graphql': ['prettier'], | |
\ 'markdown': ['prettier'], | |
\ } | |
let g:ale_javascript_prettier_options = '--single-quote --trailing-comma es5' | |
let g:ale_fix_on_save = 1 | |
" RSpec.vim mappings | |
" map <C-T> :call RunCurrentSpecFile()<CR> | |
" map <Leader>s :call RunNearestSpec()<CR> | |
" map <Leader>l :call RunLastSpec()<CR> | |
" map <Leader>a :call RunAllSpecs()<CR> | |
let g:rainbow_active = 1 | |
" Use deoplete. | |
let g:deoplete#enable_at_startup = 1 | |
" Coc Setup | |
" Use tab for trigger completion with characters ahead and navigate. | |
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin. | |
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. | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position. | |
" Coc only does snippet and additional edit on confirm. | |
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
" Or use `complete_info` if your vim support it, like: | |
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" | |
" Use `[g` and `]g` to navigate diagnostics | |
nmap <silent> [g <Plug>(coc-diagnostic-prev) | |
nmap <silent> ]g <Plug>(coc-diagnostic-next) | |
" Remap keys for gotos | |
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 symbol under cursor on CursorHold | |
autocmd CursorHold * silent call CocActionAsync('highlight') | |
" Remap for rename current word | |
nmap <leader>rn <Plug>(coc-rename) | |
" Remap for format selected region | |
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 | |
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph | |
xmap <leader>a <Plug>(coc-codeaction-selected) | |
nmap <leader>a <Plug>(coc-codeaction-selected) | |
" Remap for do codeAction of current line | |
nmap <leader>ac <Plug>(coc-codeaction) | |
" Fix autofix problem of current line | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Create mappings for function text object, requires document symbols feature of languageserver. | |
xmap if <Plug>(coc-funcobj-i) | |
xmap af <Plug>(coc-funcobj-a) | |
omap if <Plug>(coc-funcobj-i) | |
omap af <Plug>(coc-funcobj-a) | |
" Use <TAB> for select selections ranges, needs server support, like: coc-tsserver, coc-python | |
nmap <silent> <TAB> <Plug>(coc-range-select) | |
xmap <silent> <TAB> <Plug>(coc-range-select) | |
" Use `:Format` to format current buffer | |
command! -nargs=0 Format :call CocAction('format') | |
" Use `:Fold` to fold current buffer | |
command! -nargs=? Fold :call CocAction('fold', <f-args>) | |
" use `:OR` for organize import of current buffer | |
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') | |
" Add status line support, for integration with other plugin, checkout `:h coc-status` | |
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} | |
" === Coc.nvim === " | |
" use <tab> for trigger completion and navigate to next complete item | |
function! s:check_back_space() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~ '\s' | |
endfunction | |
inoremap <silent><expr> <TAB> | |
\ pumvisible() ? "\<C-n>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
"Close preview window when completion is done. | |
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif | |
let g:lightline = { 'colorscheme': 'nightowl' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment