Last active
July 7, 2019 12:14
-
-
Save carlosvillu/67be4ec97977b19b99bf2fdc80e9af04 to your computer and use it in GitHub Desktop.
NVIM config
This file contains 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
" PLUGINS | |
" ****************************************************************************** | |
call plug#begin() | |
Plug 'fugalh/desert.vim' " ColorSchema | |
Plug 'airblade/vim-gitgutter' " display git changes on left column | |
Plug 'itchyny/vim-gitbranch' " Git | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " Fuzzy Search | |
Plug 'junegunn/fzf.vim' " Fuzzy Search | |
Plug 'Quramy/tsuquyomi' " TypeScript Support | |
Plug 'mxw/vim-jsx' " JSX Support | |
Plug 'pangloss/vim-javascript' " JS Support | |
Plug 'scrooloose/nerdtree' " Folder Navegation | |
Plug 'xuyuanp/nerdtree-git-plugin' " Add Git info to nerdtree | |
Plug 'tmhedberg/matchit' " Extend % matching | |
Plug 'tpope/vim-repeat' " Need for vim-surround | |
Plug 'tpope/vim-surround' " fancy surround editing | |
Plug 'meain/vim-package-info', { 'do': 'npm install' } " show package info inline | |
Plug 'mg979/vim-visual-multi', {'branch': 'test'} " Multiple coursor | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} " LSP, completion, linting | |
Plug 'ryanoasis/vim-devicons' " Icons for VIM (https://github.com/ryanoasis/vim-devicons/issues/198#issuecomment-338775729) | |
call plug#end() | |
" BASE CONFIG | |
" ****************************************************************************** | |
set nowrap " No wrap long lines | |
set expandtab " spaces not tabs // :reatb to fix | |
set tabstop=2 " size of a tab | |
set shiftwidth=2 " size for auto/smartindent | |
set softtabstop=2 " a tab is this size | |
set smartindent " indents for you | |
set autoindent " always set autoindenting on | |
set smarttab " tabs at start of lines | |
set list | |
set listchars=tab:-- " alert if I use tabs!! : retab to fix | |
set number " display line numbers | |
set showmatch " show matching bracket | |
set norelativenumber " row numbers relatives to coursor // remove with :set norelativenumber | |
set noswapfile | |
set ignorecase " Use case insensitive search, except when using capital letters | |
set smartcase | |
set wildignorecase " Use case insensitive search for filenames | |
set mouse=a | |
set path+=** " Search files into subfolders | |
set hlsearch " highlight search word | |
" Make `jj` and `jk` throw you into normal mode | |
inoremap jj <esc> | |
inoremap jk <esc> | |
inoremap º <esc> | |
" Alternative using Tabs | |
nnoremap H gT | |
nnoremap L gt | |
" Simulated TextMate text select | |
:nnoremap <S-Left> v<Left> | |
:nnoremap <S-Right> v<Right> | |
:vnoremap <S-Left> <Left> | |
:vnoremap <S-Right> <Right> | |
" Setup python path | |
let g:python_host_prog = '/Users/carlos.villuendas/.pyenv/versions/neovim2/bin/python' | |
" ignore folders for :find | |
set wildignore+=*/min/*,*/vendor/*,*/node_modules/*,*/bower_components/* | |
" ckeck for external changes with buffer gains focus | |
au FocusGained,BufEnter * :silent! checktime " automatic reload changed files | |
set autoread | |
" Spell | |
let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell' | |
autocmd FileType markdown setlocal spell | |
setlocal spell spelllang=en_us | |
" remove preview buffer | |
autocmd BufEnter * set completeopt-=preview | |
" remove trailing white spaces on phyton and js files | |
autocmd BufWritePre *.py,*.js :call <SID>StripTrailingWhitespaces() | |
" VISUAL | |
" ****************************************************************************** | |
set termguicolors | |
set background=dark | |
colorscheme desert | |
set guifont=Monaco:h13 | |
hi CocErrorHighlight guibg=NONE guifg=NONE gui=undercurl | |
hi CocErrorSign guifg=red | |
hi CocWarningSign guifg=yellow | |
hi CocInfoSign guifg=magenta | |
hi CocHintSign guifg=cyan | |
" Status Line | |
set statusline =\ [\%{gitbranch#name()}%*\]\ %f\ %m | |
set statusline +=\ %*%=\ %*%{coc#status()}\ %* | |
" vertical divider | |
set fillchars+=vert:\ | |
" COLORS | |
" *************** | |
" Status Line | |
hi StatusLineNC guifg=fg guibg=#c2bfa6 | |
hi User2 guifg=fg guibg=#c2bfa6 | |
" Tabs color | |
hi TabLine gui=reverse guifg=fg guibg=bg | |
hi TabLineFill gui=reverse guifg=fg guibg=bg | |
hi TabLineSel gui=bold guifg=fg guibg=bg | |
" MAPINGS | |
" ******************************************************************************++ | |
" Map leader to , | |
let mapleader = ',' | |
let maplocalleader = ',' | |
" copy and paste | |
noremap y "*y | |
noremap yy <S-V>"*y<esc> | |
" imap <C-V> <esc>"*p<esc>A | |
imap <C-V> <C-r>* | |
" Paste not replace the copy | |
xnoremap p pgvy | |
" Git | |
noremap <Leader>ga :Gwrite<CR> | |
noremap <Leader>gc :Gcommit<CR> | |
noremap <Leader>gsh :Gpush<CR> | |
noremap <Leader>gll :Gpull<CR> | |
noremap <Leader>gs :Gstatus<CR> | |
noremap <Leader>gb :Gblame<CR> | |
noremap <Leader>gd :Gvdiff<CR> | |
noremap <Leader>gr :Gremove<CR> | |
"NERDTree | |
nnoremap †ƒ :NERDTreeFind<CR> | |
noremap †† :NERDTreeToggle<CR> | |
" Move lines up & down | |
nnoremap <C-j> :m .+1<CR>== | |
nnoremap <C-k> :m .-2<CR>== | |
inoremap <C-j> <Esc>:m .+1<CR>==gi | |
inoremap <C-k> <Esc>:m .-2<CR>==gi | |
vnoremap <C-j> :m '>+1<CR>gv=gv | |
vnoremap <C-k> :m '<-2<CR>gv=gv | |
" Tabs & splits | |
nnoremap <tab> <C-w><C-w> | |
nnoremap <S-tab> <C-w>h | |
noremap <Leader>h :<C-u>split<CR> | |
noremap <Leader>v :<C-u>vsplit<CR> | |
" noremap <C-w><Left> <C-w>10< | |
" noremap <C-w><Right> <C-w>10> | |
" noremap <C-w><Up> <C-w>10+ | |
" noremap <C-w><Down> <C-w>10-<Paste> | |
" remove search on esc | |
nnoremap <esc> :noh<return><esc> | |
" search current selection | |
xnoremap * :<C-u>call <SID>VSetSearch('/')<CR>/<C-R>=@/<CR><CR> | |
xnoremap # :<C-u>call <SID>VSetSearch('?')<CR>?<C-R>=@/<CR><CR> | |
function! s:VSetSearch(cmdtype) | |
let temp = @s | |
norm! gv"sy | |
let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g') | |
let @s = temp | |
endfunction | |
" Vmap for maintain Visual Mode after shifting > and < | |
vmap < <gv | |
vmap > >gv | |
" replace word under cursor, globally, with confirmation | |
nnoremap <Leader>k :%s/\<<C-r><C-w>\>//gc<Left><Left><Left> | |
vnoremap <Leader>k y :%s/<C-r>"//gc<Left><Left><Left> | |
" Open current line on GitHub | |
nnoremap <Leader>o :.Gbrowse<CR> | |
"FZF | |
nnoremap <C-b> :Buffers<CR> | |
nnoremap ∫ :Lines<CR> | |
nnoremap <C-p> :call FzfOmniFiles()<CR> | |
nnoremap π :Ag<CR> | |
nnoremap <leader><leader> :Commands<CR> | |
" PLUGINS CONFIG | |
" ******************************************************************************+ | |
" NERDTree configuration | |
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite | |
" vim-package-info | |
let g:vim_package_info_virutaltext_prefix = ' ¤ ' | |
hi VimPackageInfoPatch guifg=#8BC34A | |
hi VimPackageInfoMinor guifg=#00BCD4 | |
hi VimPackageInfoMajor guifg=#F44336 | |
" jsx | |
let g:jsx_ext_required = 0 | |
" VIM Visual Multi | |
let g:VM_leader = '..' | |
let g:VM_default_mappings = 1 | |
" COC | |
" 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) | |
nnoremap <silent> K :call <SID>show_documentation()<CR> | |
" Use <c-space> to trigger completion. | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" CocDetail similar to AleDetail | |
command! -nargs=0 CocDetail :call CocAction('diagnosticInfo') | |
nmap <silent> <leader>l <Plug>(coc-diagnostic-info) | |
nmap <silent> [l <Plug>(coc-diagnostic-prev) | |
nmap <silent> ]l <Plug>(coc-diagnostic-next) | |
" Use tab for trigger completion with characters ahead and navigate. | |
inoremap <silent><expr> <TAB> | |
\ pumvisible() ? "\<C-n>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" | |
" 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>" | |
" COC documentation | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
else | |
call CocAction('doHover') | |
endif | |
endfunction | |
" COC Use tab for trigger completion | |
function! s:check_back_space() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~# '\s' | |
endfunction | |
" FZF | |
" *********** | |
" Search with grep and preview | |
command! -bang -nargs=* GGrep | |
\ call fzf#vim#grep( | |
\ 'git grep --line-number '.shellescape(<q-args>), 1, | |
\ <bang>0 ? fzf#vim#with_preview('up:60%') | |
\ : fzf#vim#with_preview('right:40%'), | |
\ <bang>0) | |
"call fzf#run({'sink': 'e', 'window': 'rightbelow new'}) | |
" Ag search only on file contents | |
let s:ag_options = ' --ignore package-lock.json ' | |
command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, s:ag_options, <bang>0) | |
" FUNCTIONS | |
" ****************************************************************************** | |
" remove trailing white spaces | |
function! <SID>StripTrailingWhitespaces() | |
" Preparation: save last search, and cursor position. | |
let _s=@/ | |
let l = line(".") | |
let c = col(".") | |
" Do the business: | |
%s/\s\+$//e | |
" Clean up: restore previous search history, and cursor position | |
let @/=_s | |
call cursor(l, c) | |
endfunction | |
"FZF decide what file find to use | |
fun! FzfOmniFiles() | |
let is_git = system('git status') | |
if v:shell_error | |
:Files | |
else | |
:GitFiles | |
endif | |
endfun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment