Skip to content

Instantly share code, notes, and snippets.

@martimatix
Last active May 6, 2020 14:43
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 martimatix/fb93e8dc9c63a48ce5aadb04f27e3076 to your computer and use it in GitHub Desktop.
Save martimatix/fb93e8dc9c63a48ce5aadb04f27e3076 to your computer and use it in GitHub Desktop.
.vimrc
syntax on
set hidden
set noerrorbells
set tabstop=2 softtabstop=2
set shiftwidth=2
set expandtab
set smartindent
set nu
set nowrap
set smartcase
set noswapfile
set nobackup
set undodir=~/.vim/undodir
set undofile
set incsearch
"
" 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=50
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
set colorcolumn=80
highlight ColorColumn ctermbg=0 guibg=lightgrey
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'morhetz/gruvbox'
Plug 'scrooloose/nerdtree'
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'w0rp/ale'
Plug 'jiangmiao/auto-pairs'
Plug 'airblade/vim-gitgutter'
call plug#end()
colorscheme gruvbox
set background=dark
let mapleader = " "
nnoremap <leader>h :wincmd h<CR>
nnoremap <leader>j :wincmd j<CR>
nnoremap <leader>k :wincmd k<CR>
nnoremap <leader>l :wincmd l<CR>
nnoremap <leader>rr :so ~/.vimrc<CR>
nnoremap <silent> <Leader>+ :vertical resize +5<CR>
nnoremap <silent> <Leader>- :vertical resize -5<CR>
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" select all copy to clipboard
nnoremap <leader>ca :%y+<CR>
" pick squash shortcut
nnoremap <leader>ps :2,$s/pick/squash/g<CR>
" Case sensitive search
:set ignorecase
:set smartcase
" copy current file name (relative) to system clipboard (Mac version)
" See :help let :help expand :help registers for details
if has("mac")
nnoremap <leader>fn :let @*=expand("%")<CR>
endif
" fzf
nnoremap <c-p> :GFiles<cr>
""""""""""""""""""""""""""""""""""""""""
" ALE linters
""""""""""""""""""""""""""""""""""""""""
let g:ale_linters = {
\ 'sh': ['shellcheck'],
\ 'ruby': ['rubocop', 'rufo', 'standardrb'],
\}
let g:ale_pattern_options = {
\ '.*\.erb$': {'ale_enabled': 0},
\}
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'javascript': ['eslint', 'prettier'],
\ 'typescript': ['eslint', 'prettier'],
\ 'sh': ['shfmt'],
\ 'ruby': ['rufo', 'standardrb', 'rubocop'],
\}
let g:ale_completion_enabled = 1
let g:ale_completion_tsserver_autoimport = 1
let g:ale_echo_msg_format = '[%linter%] %s'
let g:ale_fix_on_save = 1
let g:ale_keep_list_window_open = 0 " do not keep list if there is no error/warning
let g:ale_lint_on_enter = 0 " don't want linters to run on opening a file
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_open_list = 'on_save'
let g:ale_set_highlights = 1
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
let g:ale_sh_shfmt_options = '-i 2 -ci'
let g:ale_sign_error = '⤫'
let g:ale_sign_warning = '⚠'
nmap <silent> <leader>al :ALEToggle<CR>
nmap <silent> <leader>af :ALEFix<CR>
"" Close the loclist/quickfix window automatically when the buffer is closed
augroup CloseLocQuickFixlistWindowGroup
autocmd!
autocmd QuitPre * if empty(&buftype) | lclose | cclose | endif
augroup END
nnoremap <leader>tn :ALEGoToDefinition<CR>
nnoremap <leader>tr :ALEFindReferences<CR>
nnoremap <leader>tm :ALERename<CR>
" NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
nnoremap <leader>nn :NERDTreeToggle<CR>
nnoremap <leader>nf :NERDTreeFind<CR>
" Gitgutter disable mappings
let g:gitgutter_map_keys = 0
" Lightline git status
let g:lightline = {
\ 'colorscheme': 'powerline',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ }

If you want search for js files but not test files use

:Rg foo -t js -g '!*.test.js'

and if you only want to search for stuff in the src directory

:Rg foo -t js -g '!*.test.js' -g 'src/client/**/*'

using :History: might be handy for searching through previous commands. But how do you load a command without executing it?

You can resrtict it to filenames by passing the -l flag to ripgrep.

Project wide search and replace

Things to find out

Why does <leader> gd sometimes not work? Remapping to jd seems to help.

TODO

Install vim multiple cursors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment