Skip to content

Instantly share code, notes, and snippets.

@andreyuhai
Last active October 20, 2022 06:27
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 andreyuhai/48687219d2a3153e441bf1a634fe7576 to your computer and use it in GitHub Desktop.
Save andreyuhai/48687219d2a3153e441bf1a634fe7576 to your computer and use it in GitHub Desktop.
Vimrc
source $VIMRUNTIME/defaults.vim
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Tpope
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-endwise'
Plugin 'tpope/vim-fugitive'
Plugin 'vim-airline/vim-airline'
" Auto pairs for '"({})"'
Plugin 'jiangmiao/auto-pairs'
" Strip white space or show white space
Plugin 'ntpeters/vim-better-whitespace'
" Theme
Plugin 'morhetz/gruvbox'
" NerdTree
Plugin 'preservim/nerdtree'
" JSX - Javascript
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
" Typescript
Plugin 'jason0x43/vim-js-indent'
" Emmet for HTML
Plugin 'mattn/emmet-vim'
" Elixir
Plugin 'elixir-editors/vim-elixir'
" For tests
Plugin 'vim-test/vim-test'
" Polyglot
Plugin 'sheerun/vim-polyglot'
" FZF Vim
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
" Mix format
Plugin 'mhinz/vim-mix-format'
" Indentation
Plugin 'Yggdroot/indentLine'
" Targets
Plugin 'wellle/targets.vim'
" LSP
Plugin 'prabirshrestha/vim-lsp'
Plugin 'mattn/vim-lsp-settings'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" ---------------------
" .............................................................................
" General vim settings
" .............................................................................
set nu
set rnu
set shiftwidth=2
set cursorline
set ignorecase
set smartcase
set encoding=UTF-8
set splitbelow
set splitright
" .............................................................................
" General mappings
" .............................................................................
" Yanks the line starting from the cursor instead of the whole line
nnoremap Y yg_
" Keep the line centered
nnoremap n nzzzv
nnoremap N Nzzzv
" Keep the cursor in place
nnoremap J mzJ`z
" Undo break points
inoremap , ,<c-g>u
inoremap . .<c-g>u
inoremap ! !<c-g>u
inoremap ? ?<c-g>u
inoremap : :<c-g>u
" Moving text
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
inoremap <C-j> <esc>:m .+1<CR>==gi
inoremap <C-k> <esc>:m .-2<CR>==gi
nnoremap <leader>j :m .+1<CR>==
nnoremap <leader>k :m .-2<CR>==
" Navigating quicklist
nnoremap <C-j> :cn<esc>zz
nnoremap <C-k> :cp<esc>zz
" .............................................................................
" NERDTree mappings
" .............................................................................
nmap <F6> :NERDTreeToggle<CR>
nmap <F7> :NERDTreeFind<CR>
" .............................................................................
" Elixir related mappings
" .............................................................................
" Easy debug line paste
map ,p orequire IEx; IEx.pry()<ESC>
map ,P Orequire IEx; IEx.pry()<ESC>
" Clear console and run the whole elixir file
map <leader>e :!clear & elixir %<CR>
" vim-elixir
syntax on
" .............................................................................
" vim-test settings
" .............................................................................
nmap <silent> t<C-n> :TestNearest<CR>
nmap <silent> t<C-f> :TestFile<CR>
nmap <silent> t<C-s> :TestSuite<CR>
nmap <silent> t<C-l> :TestLast<CR>
nmap <silent> t<C-g> :TestVisit<CR>
" .............................................................................
" Search highlight toggle - requires gruvbox
" .............................................................................
nnoremap <silent> <Leader><Space> :call gruvbox#hls_toggle()<CR>
inoremap <silent> <Leader><Space> <ESC>:call gruvbox#hls_toggle()<CR>a
vnoremap <silent> <Leader><Space> <ESC>:call gruvbox#hls_toggle()<CR>gv
nnoremap <silent> <CR> :call gruvbox#hls_hide()<CR><CR>
nnoremap * :let @/ = ""<CR>:call gruvbox#hls_show()<CR>*
nnoremap / :let @/ = ""<CR>:call gruvbox#hls_show()<CR>/
nnoremap ? :let @/ = ""<CR>:call gruvbox#hls_show()<CR>?
" .............................................................................
" Replace map
" .............................................................................
" Substitute selected text by <S-8> (* - asterisk)
nnoremap <Leader>r :%s///g<Left><Left>
nnoremap <Leader>rc :%s///gc<Left><Left><Left>
" First select a word by <S-8> (* - asterisk) and then select
" a block in visual mode so that the substitution only
" applies to those words within the selected block
xnoremap <Leader>r :s///g<Left><Left>
xnoremap <Leader>rc :s///gc<Left><Left><Left>
" .............................................................................
" FZF
" .............................................................................
" All files, ignores by default
command! -nargs=? -complete=dir AF
\ call fzf#run(fzf#wrap({
\ 'source': 'fd --type f --hidden --follow --exclude .git . '.expand(<q-args>)
\ }))
nnoremap <C-p> :AF<CR>
nnoremap <leader>b :Buffers<CR>
nnoremap <leader>l :Lines<CR>
nnoremap <leader>m :Marks<CR>
" Allow passing optional flags into the Rg command.
" Example: :Rg myterm -g '*.md'
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case " .
\ <q-args>, 1, fzf#vim#with_preview(), <bang>0)
function! RipgrepFzf(query, fullscreen)
echo a:query
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, shellescape('{q}'))
echo reload_command
let options = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
let options = fzf#vim#with_preview(options, 'right', 'ctrl-/')
call fzf#vim#grep(initial_command, 1, options, a:fullscreen)
endfunction
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
" .............................................................................
" Auto commands
" .............................................................................
autocmd vimenter * ++nested colorscheme gruvbox
" .............................................................................
" vim-mix-format settings
" .............................................................................
let g:mix_format_on_save = 1
" .............................................................................
" LSP
" .............................................................................
if executable('elixir-ls')
au User lsp_setup call lsp#register_server({
\ 'name': 'ElixirLS',
\ 'cmd': {server_info->['elixir-ls']},
\ 'allowlist': ['elixir', 'eelixir'],
\ })
endif
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gs <plug>(lsp-document-symbol-search)
nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
nnoremap <buffer> <expr><c-d> lsp#scroll(-4)
let g:lsp_format_sync_timeout = 1000
autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
" refer to doc to add more commands
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
let g:lsp_diagnostics_echo_cursor = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment