Skip to content

Instantly share code, notes, and snippets.

@gusaiani
Last active March 10, 2024 23:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gusaiani/82efd3fab81e416c6830782a408b5514 to your computer and use it in GitHub Desktop.
Save gusaiani/82efd3fab81e416c6830782a408b5514 to your computer and use it in GitHub Desktop.
My .vimrc
call plug#begin('~/.vim/plugged')
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'jooize/vim-colemak'
Plug 'morhetz/gruvbox'
Plug 'elixir-lang/vim-elixir'
Plug 'pangloss/vim-javascript'
Plug 'mattn/emmet-vim'
Plug 'easymotion/vim-easymotion'
Plug 'mileszs/ack.vim'
Plug 'ggreer/the_silver_searcher'
Plug 'tpope/vim-commentary'
Plug 'jiangmiao/auto-pairs'
Plug 'Yggdroot/indentLine'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'Valloric/YouCompleteMe'
Plug 'ervandew/supertab'
Plug '907th/vim-auto-save'
Plug 'wting/gitsessions.vim'
Plug 'vim-scripts/Rename2'
Plug 'vim-scripts/copypath.vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'dense-analysis/ale'
Plug 'airblade/vim-gitgutter'
Plug 'vim-scripts/cmdalias.vim'
Plug 'vim-erlang/vim-erlang-runtime'
Plug 'elzr/vim-json'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" unix shell commands from inside vim, e.g. :Mkdir
Plug 'tpope/vim-eunuch'
Plug 'sgur/vim-editorconfig'
Plug 'mxw/vim-jsx'
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
Plug 'slashmili/alchemist.vim'
Plug 'tpope/vim-fugitive'
Plug 'wakatime/vim-wakatime'
Plug 'whiteinge/diffconflicts'
Plug 'tpope/vim-unimpaired'
Plug 'kristijanhusak/vim-carbon-now-sh'
" Typescript syntax
Plug 'HerringtonDarkholme/yats.vim'
Plug 'peitalin/vim-jsx-typescript'
Plug 'delphinus/vim-firestore'
Plug 'ruanyl/vim-gh-line'
Plug 'eliba2/vim-node-inspect'
Plug 'ludovicchabant/vim-gutentags'
Plug 'kristijanhusak/vim-js-file-import', {'do': 'npm install'}
Plug 'rust-lang/rust.vim'
Plug 'othree/jsdoc-syntax.vim'
Plug 'ruanyl/vim-fixmyjs'
Plug 'jparise/vim-graphql'
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
Plug 'udalov/kotlin-vim'
Plug 'Quramy/tsuquyomi'
Plug 'github/copilot.vim'
Plug 'https://github.com/adelarsq/vim-matchit'
call plug#end()
set encoding=utf-8
set rtp+=/usr/local/opt/fzf
" set the runtime path to include Vundle and initialize
" set rtp+=~/.vim/bundle/Vundle.vim
" call vundle#begin()
" Plugin 'Valloric/YouCompleteMe'
" All of your Plugins must be added before the following line
" call vundle#end() " required
filetype plugin indent on " required
" Directories for swp files
set nobackup
set nowritebackup
set noswapfile
" au BufRead,BufNewFile *.handlebars,*.hbs set ft=html syntax=handlebars
" sync iTerm number of colors with vim at 256
let &t_Co=256
" Have fzf ignore files in gitignore inside zsh
let $FZF_DEFAULT_COMMAND = 'ag --hidden -g ""'
colorscheme gruvbox
" auto-save: auto-save by default, except in Insert Mode
let g:auto_save = 1
let g:auto_save_in_insert_mode = 0
filetype plugin indent on
" show existing tab with 2 spaces width
set tabstop=2
" when indenting with '>', use 2 spaces width
set shiftwidth=2
" On pressing tab, insert 2 spaces
set expandtab
set number
" Highlight search results
set hlsearch
" Show incremental search
set incsearch
" Use C-style auto-indentation
set cindent
" Show quotes in json files
set conceallevel=0
map <silent> <C-\> :NERDTreeToggle<CR>
set runtimepath+=~/.vim/my-snippets/
autocmd BufWritePre * %s/\s\+$//e
" Treat zero-padded numbers as decimal rather than octal
set nrformats=
" Tab character colors
let g:indentLine_color_term = 239
let g:indentLine_char = '|'
" CtrlP fuzzy navigator
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|tmp|node_modules)$',
\ 'file': '\v\.(exe|so|dll|svg)$',
\ 'link': 'some_bad_symbolic_links',
\ }
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.svg,/build/*
set wildignore+=.DS_Store
" set wildignore+=*node_modules/**
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'
" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
" backspace over line breaks in Insert mode
set backspace=indent,eol,start
" Customize tabs for filetypes
autocmd Filetype elm setlocal ts=4 sts=4 sw=4
autocmd Filetype sass setlocal ts=2 sts=2 sw=2
autocmd Filetype html setlocal ts=2 sts=2 sw=2
" Make it easier to go to next line from middle of
" current one in Insert mode
imap <C-o> <esc>o
imap <C-S-o> <esc><S-o>
imap <Tab> <C-P>
" Copy yanks to system clipboard
set clipboard=unnamed,unnamedplus
" Emmet
let g:user_emmet_mode='a' "enable all function in all mode.
let g:user_emmet_leader_key='<C-Z>'
let g:user_emmet_settings = {'javascript.jsx': {'extends' : 'jsx'}}
let g:user_emmet_install_global = 0
autocmd FileType html,css,hbs EmmetInstall
" open Visual-Block mode with ctrl+v
nnoremap <c-a> <c-v>
" ZSH-style tab completion in Ex mode
set wildmenu
set wildmode=list:longest,full
set mouse=a
" Have up to 200 commands saved
set history=200
" Open vertical splits on the right
set splitright
" Open horizontal splits below
set splitbelow
let mapleader = " "
" Shortcuts for buffer navigation
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> ]B :blast<CR>
" Disable error sounds
set noerrorbells visualbell t_vb=
if has('autocmd')
autocmd GUIEnter * set visualbell t_vb=
endif
" Editor basics {{{
" Behave like Vim instead of Vi
set nocompatible
" Show a status line
set laststatus=2
" Show the current cursor position
set ruler
" Enable syntax highlighting
syn on
" Send more characters for redraws
set ttyfast
" Enable mouse use in all modes
set mouse=a
" Set this to the name of your terminal that supports mouse codes.
" Must be one of: xterm, xterm2, netterm, dec, jsbterm, pterm
set ttymouse=xterm2
" Expand to the path of the active buffer with :%%
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" Enable matchit plugin (% for jumping between open/close xml tags)
filetype plugin on
runtime macros/matchit.vim
" Set * and #, in Visual mode,
" to jump around selected substrings
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
" Use ag under the hood for Ack
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
" Esc to close quickfix window (Ack results)
" nnoremap <silent> <ESC> :ccl<CR>
" Don't jump to first result in Ack
" cnoreabbrev Ack Ack!
" nnoremap <Leader>a :Ack!<Space>
" Navigate splits quicker
nnoremap <C-J> <C-W><C-J>
nnoremap <C-E> <C-W><C-K>
nnoremap <C-I> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Go to tab
noremap <leader>u gt
noremap <leader>l gT
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<cr>
" Go to last active tab
au TabLeave * let g:lasttab = tabpagenr()
nnoremap <silent> <c-l> :exe "tabn ".g:lasttab<cr>
vnoremap <silent> <c-l> :exe "tabn ".g:lasttab<cr>
" Toggle Comment
noremap <leader>c gcc
" Quick new tabedit (empty)
noremap <leader><leader>t :tabedit<cr>
noremap <leader>a :-1tabedit<cr>
" Quick new tabclose (empty)
noremap <leader><leader>c :tabclose<cr>
" Quick :only
noremap <leader>o :only<cr>
" Comment
noremap <leader>c :Commentary<cr>
" Write
noremap <leader>w :write<cr>
" Quit
noremap <leader>q :quit<cr>
" Quit All
noremap <leader><leader>q :quitall<cr>
" Vertical Split
noremap <leader>v :vsp<cr>
" Horizontal Split
noremap <leader><leader>s :sp<cr>
" Open FZF
noremap <leader>f :FZF<cr>
" CopyPath (empty)
noremap <leader><leader>p :CopyPath<cr>
" Register relative file path of current buffer
" from project root to system clipboard
nnoremap <F10> :let @+ = expand("%")<CR>
noremap <leader>p :let @+ = expand("%")<CR>
" Remap ; to : to access commands more easily
nnoremap ; :
vnoremap ; :
" Use :a to trigger :Ack
autocmd VimEnter * Alias a Ack
" Show quotes in json files
let g:vim_json_syntax_conceal = 0
" Settings for Ale
let g:ale_lint_on_text_changed = 'normal'
let g:ale_sign_column_always = 1
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']
let g:ale_javascript_eslint_use_global = 1
let g:ale_javascript_eslint_executable = 'eslint_d'
let g:ale_sign_error = '❌'
let g:ale_sign_warning = '⚠️'
let g:ale_sign_column_always = 1
let js_fixers = ['prettier', 'eslint']
let g:ale_linters = {
\ 'javascript': js_fixers,
\'typescript': js_fixers,
\}
let g:ale_linter_aliases = {'jsx': ['css', 'javascript']}
let g:ale_fixers = {
\ 'javascript': js_fixers,
\ 'typescript': js_fixers,
\ 'javascript.jsx': js_fixers,
\ 'typescriptreact': js_fixers,
\}
" let g:ale_javascript_prettier_use_local_config = 1
let g:ale_fix_on_save = 1
" augroup AleGroup
" autocmd!
" autocmd User ALELint call TouchOpenFile()
" augroup END
" Go to definition
map <leader>gd :ALEGoToDefinition<cr>
map <leader>gt :ALEGoToDefinitionInVSplit<cr>
map <leader>gn :ALENextWrap<cr>
map <leader>gp :ALEPreviousWrap<cr>
" Show ALEDetail
noremap <leader><leader><leader>a :ALEDetail<cr>
" by running :Sb, if you scroll one split panel,
" the other to its side will scroll
" good for copying code, studying
command Sb windo set scrollbind
" Enable per-project Vim configuration files
set exrc
set secure
" Shift + Enter for line after commented line not to be commented
inoremap <S-CR> <CR><C-u>
" Trigger `autoread` when files changes on disk
" https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044
" https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
" Notification after file change
" https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread
autocmd FileChangedShellPost *
\ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None
" no more /arstqwfp to clean highlighted searches
nmap <silent> ./ :nohlsearch<CR>
" EasyMotion, use 1 leader and use better keys for Colemak
map <Leader> <Plug>(easymotion-prefix)
let g:EasyMotion_keys='tnseriaoplfuwyq;vmx,'
" Undo between sessions
set undofile
set undodir=~/.vim/undodir
" Fixes an issue where vim started up and show strange characters
" Source: https://www.reddit.com/r/vim/comments/9kppr9/weird_characters_inserted_by_vim_in_gnometerminal/
set t_u7=
set t_RV=
" Opens Nerd Tree in the current file's directory
map <leader>r :NERDTreeToggle<cr>
" Disable functions keys - Mac Touch Bar
:nmap <F1> <Nop>
:imap <F1> <Nop>
:nmap <F2> <Nop>
:imap <F2> <Nop>
:nmap <F3> <Nop>
:imap <F3> <Nop>
:nmap <F4> <Nop>
:imap <F4> <Nop>
:nmap <F5> <Nop>
:imap <F5> <Nop>
:nmap <F6> <Nop>
:imap <F6> <Nop>
" Don't copy what's deleted on deleting
nnoremap <leader>d "_d
noremap <leader>d "_d
xnoremap <leader>p "_dP
" vim-js-file-import
let g:js_file_import_use_fzf = 1
" gutentags
" set statusline+=%{gutentags#statusline()}
let g:gutentags_exclude_project_root = ['/Users/gustavosaiani/Documents/Gustavo Saiani/.j', '/Users/gustavosaiani/code/metabase/metabase']
" NERDTree, show dotfiles
let NERDTreeShowHidden=1
" Force color of Comments
highlight Comment ctermfg=252
let g:typescript_compiler_binary = 'tsc'
let g:typescript_compiler_options = ''
" Old regex engine to comply with yats plugin
set re=0
" YouCompleteMe, use Homebrew llvm's clangd, whatever that is
" https://github.com/ycm-core/YouCompleteMe#installation
" let g:ycm_clangd_binary_path='/opt/homebrew/opt/llvm/bin/clangd'
" Reload vim-colemak to remap any overridden keys
silent! source "$HOME/.vim/plugged/vim-colemak/plugin/colemak.vim"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment