Skip to content

Instantly share code, notes, and snippets.

@diegommarino
Last active December 1, 2020 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegommarino/90360ab66d97e01309f2e6fc38be85cb to your computer and use it in GitHub Desktop.
Save diegommarino/90360ab66d97e01309f2e6fc38be85cb to your computer and use it in GitHub Desktop.
My vim rc
" Presets
" PLUGINS
call plug#begin('~/.vim/plugged')
" On Mac OS, to copy a whole file to clipboard use '%w !pbcopy'
" Fuzzy Finder
" Needs fzf installed
" 'brew install fzf'
" 'brew install the_silver_searcher'
Plug '/usr/local/opt/fzf'
" Search plugin
Plug 'junegunn/fzf.vim'
" Additional surrounding comands
Plug 'tpope/vim-surround'
" Thos allows '.' to repeat plugins commands
Plug 'tpope/vim-repeat'
" Coffescript
Plug 'kchmck/vim-coffee-script'
" Show content of registers before paste
Plug 'junegunn/vim-peekaboo'
" Create custom textobjs
Plug 'kana/vim-textobj-user'
" Ruby textobj
Plug 'nelstrom/vim-textobj-rubyblock'
" Git
Plug 'airblade/vim-gitgutter'
" git tools
Plug 'tpope/vim-fugitive'
" File tree
Plug 'scrooloose/nerdtree'
" To execute test for Rails project. Dont know if still necessary after add
" vim-rails.
Plug 'janko/vim-test'
" Complete parentesis, brackets, etc
Plug 'jiangmiao/auto-pairs'
" Comment lines using 'gcc' command or 'gc'
Plug 'tpope/vim-commentary'
" Navigate through MVC and run tests. Check the docs for commands.
Plug 'tpope/vim-rails'
" Add ruby methods autocomplete
Plug 'tpope/vim-endwise'
" Linting Plugin
" Needs 'rubocop' and 'standard' gems installed
Plug 'dense-analysis/ale'
" Autocomplete plugin
" Needs also pyvim 'pip3 install --user pynvim'
" Config is bellow
" if has('nvim')
" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" else
" Plug 'Shougo/deoplete.nvim'
" Plug 'roxma/nvim-yarp'
" Plug 'roxma/vim-hug-neovim-rpc'
" endif
" Autocomplete plugin
" Needs 'gem install solargraph' to run the rails server
" Run 👇
" :CocInstall coc-solargraph
" to install Ruby on Rails outocomplete
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" VueJS Linter
" Need to try thos too, 'https://github.com/dense-analysis/ale/issues/927#issuecomment-375175550'
Plug 'posva/vim-vue'
" Airline to draw the info line at the botton of the screen
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Language server
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh',
\ }
call plug#end()
" Below config is for using nelstrom/vim-textobj-rubyblock
" Enable Matchit plugin
runtime macros/matchit.vim
" Enable filetype Plugin and disable vi compatibility mode
set nocompatible
if has("autocmd")
filetype indent plugin on
endif
" Personal config
" Use :options to see all options
" Set lines number
set number
" Set relative line number
set relativenumber
" Incremental search that shows partial matches
set is
" Highlight search
set hlsearch
" Shift and tabstop size
set shiftwidth=2
set tabstop=2
" Turn tab into space
set expandtab
" Commands history size
set history=1000
set ruler
set showcmd
set wildmenu
set scrolloff=8 " when using z+enter
" Auto ident
set ai
" Smart ident
set si
" dark background for when vim have no style set
set bg=dark
" Buffer config to load in memory by default
set hidden
" color scheme
color desert
" Update faster to show git diff
set updatetime=300
" Line highlight
set cursorline
" Column highlight
" set cursorcolumn
" Set a ruler with grey color
set colorcolumn=120
highlight ColorColumn ctermbg=lightgrey guibg=lightgrey
" Set spell check
set spelllang=en
set spell
" Set fold type
" Use zc to fold and zo to unfold. zR will open all folds
set foldmethod=indent
" Using this the file will not open folded
set foldlevelstart=20
" Invisible chars symbols
set listchars=trail:·,tab:»·,space:·
" Change invisible chars color to DarkGrey
hi Whitespace ctermfg=DarkGray
match Whitespace /\s/
" NERDTree show hiddn files
let NERDTreeShowHidden=1
" Map leader to ,
let mapleader=','
" Activate fzf history. User C-P or C-N to navigate the history when using fzf
" or Ag
let g:fzf_history_dir = '~/.fzf-history'
" Gitgutter sign priority
if has('nvim')
let g:gitgutter_sign_allow_clobber = 1
else
let g:gitgutter_sign_priority = 100
endif
" Bash language server
let g:LanguageClient_serverCommands = {
\ 'sh': ['bash-language-server', 'start']
\ }
" Key mappings
noremap <F2> :NERDTreeToggle<CR>
noremap <F3> :NERDTreeFind<CR>
" Add byebug break point
noremap <F4> Orequire 'pry-byebug'; byebug<ESC>:w<CR>
" Add Capybara break point
noremap <F5> O$stdin.gets<ESC>:w<CR>
noremap <leader>f :Files<CR>
noremap <silent> <leader>F :Ag <C-R><C-W><CR>
noremap <leader>e :!<SPACE>
noremap <leader>r :! rubocop -a %<CR>
noremap <leader>c :bd<CR>
noremap <leader>x :bn<CR>
noremap <leader>z :bp<CR>
noremap <leader>s :w<CR>
noremap <leader>S :mks!<CR>
" Comment line
nmap <leader>/ gcc
noremap <leader>t :TestNearest<CR>
" Change between buffers
noremap <TAB> <C-^>
" Rulder ident line
noremap <leader>l 121\|Bhxi<CR><ESC>
command! ReloadBuffers bufdo source ~/.vimrc
command! CloseBuffers %bd|e#|bd#
command! GitSyncMaster !git checkout master && git pull && git checkout - && git rebase master
command! GitSyncDev !git checkout develop && git pull && git checkout - && git rebase develop
" Toggle Vim Fugitive status screen
function! ToggleGStatus()
if buflisted(bufname('.git/index'))
bd .git/index
else
Gstatus
endif
endfunction
command ToggleGStatus :call ToggleGStatus()
nmap <F6> :ToggleGStatus<CR>
" pbcopy for OSX copy/paste
vmap <C-c> :'<,'> w !pbcopy<CR><CR>
" Search selection with fzf Files
vmap <silent> <leader>f y:<C-U>Files<CR><C-R>"
" Search selection with Ag
vmap <silent> <leader>F y:<C-U>Ag <C-R>"<CR>
" Enable a better undo when you use C-u or C-w in insert mode
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
" Resize vim split panes
nnoremap <silent> <Leader>+ :exe "vertical resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "vertical resize " . (winheight(0) * 2/3)<CR>
" Automatically save the session when leaving Vim
autocmd! VimLeave * mks!
" Cursor styling
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
" Rails fix on save config using ALE
let g:ale_fixers = {
\ 'ruby': ['standardrb'],
\}
let g:ale_fix_on_save = 0
let g:ale_sign_warning = '!'
let g:ale_sign_error = 'E'
" " Autocomplete
" let g:deoplete#enable_at_startup = 1
" ########### COC autocomplete ###########
" if hidden is not set, TextEdit might fail.
set hidden
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages
set cmdheight=2
" 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
" 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>"
" Search selection from visual mode
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" 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)
" vim-airline
let g:airline_theme = 'powerlineish'
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#ale#enabled = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tagbar#enabled = 1
let g:airline_skip_empty_sections = 1
" Ale config
highlight ALEError ctermbg=none cterm=underline
highlight ALEWarning ctermbg=none cterm=underline
" :Rag <query> <path>
" Command to make Ag search by path
command! -bang -nargs=+ -complete=dir Rag call fzf#vim#ag_raw(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)
" Find and replace word
command! -nargs=+ Sub :%s/<args>/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment