Skip to content

Instantly share code, notes, and snippets.

@joeesteves
Created August 12, 2022 17:02
Show Gist options
  • Save joeesteves/1d3fd312280b79f6cb1a5ed0e9356c79 to your computer and use it in GitHub Desktop.
Save joeesteves/1d3fd312280b79f6cb1a5ed0e9356c79 to your computer and use it in GitHub Desktop.
Vim Config
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set nu
set ignorecase
set autoread
set printoptions=number:y
set undofile
set undodir=$HOME/.vim_undo
set cursorcolumn
set cursorline
set gdefault
set guifont=Fira\ Mono\ NF
set foldmethod=syntax
set foldlevel=99
" Show the name when u have only one tab open
set showtabline=2
set laststatus=2
set splitright
set splitbelow
autocmd FocusGained,CursorHold * checktime
" Paths to ctags
set tags+=./tags;
call plug#begin('~/.vim/plugged')
" Theme
Plug 'rescript-lang/vim-rescript'
" Color Schemes
Plug 'jonathanfilip/vim-lucius'
Plug 'sonph/onehalf', { 'rtp': 'vim' }
Plug 'morhetz/gruvbox'
Plug 'altercation/vim-colors-solarized'
Plug 'phanviet/vim-monokai-pro'
Plug 'ap/vim-css-color'
Plug 'junegunn/limelight.vim'
Plug 'junegunn/goyo.vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npm install' }
Plug 'ferrine/md-img-paste.vim'
Plug 'mattn/emmet-vim'
Plug 'Yggdroot/indentLine'
Plug 'elzr/vim-json'
Plug 'michaeljsmith/vim-indent-object'
" NerdTree and Plugins
Plug 'preservim/nerdtree'
" Fuzzy Search
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'stsewd/fzf-checkout.vim'
Plug 'jesseleite/vim-agriculture', {'commit': 'eb4c0d34f84eec074e7da4a177067e62a9739e96'}
Plug 'romainl/vim-qf'
" Ruby
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-rails'
Plug 'rhysd/vim-textobj-ruby'
" add this line to your .vimrc file
Plug 'mattn/emmet-vim'
" Git helpers
Plug 'tpope/vim-fugitive'
Plug 'knsh14/vim-github-link'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-abolish'
Plug 'tmhedberg/matchit'
" PowerLine
Plug 'itchyny/lightline.vim'
" Elixir
Plug 'elixir-editors/vim-elixir', {'commit': '329964b7033f15e634945eb4695cf26492d647e3'}
Plug 'kana/vim-textobj-user'
Plug 'andyl/vim-textobj-elixir'
" Plug '~/myForks/vim-elixir'
Plug 'mhinz/vim-mix-format'
" Conquer of completion (Autocomplete + intellinsense + LS)
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'elixir-lsp/coc-elixir', {'do': 'yarn install && yarn prepack'}
" Toggle true/false with gs
Plug 'AndrewRadev/switch.vim'
" Vim snippets
Plug 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Plug 'honza/vim-snippets'
" Todo
" Vim Script
" Plug 'nvim-lua/plenary.nvim'
" Plug 'folke/todo-comments.nvim'
call plug#end()
" AutoFormat for each language
" https://github.com/mhinz/vim-mix-format
let g:mix_format_on_save = 1
let g:mix_format_silent_errors = 1
autocmd FileType eelixir map <C-K><C-I> :!mix prettier % &<CR><CR>
autocmd FileType ruby map <C-K><C-I> :call CocAction('format')<CR>
autocmd BufWritePre *.rb silent! call CocAction('format')
autocmd BufWritePre *.res call rescript#Format()
" TABS hotkeys
map <C-X> :tabc<CR>
map <C-T> :tabnew<CR>
" map ze :execute 'normal zR' \| %g/defp\?\s\(.*do$\)\@=/normal zc <CR>
map ze :execute 'normal zR' \| %g/\(case.*\)\@<!) do$/normal zc <CR>
" NERDTree Toggle
let g:NERDTreeWinSize=38
map <C-B> :call SmartNERDTree()<CR>
fun! SmartNERDTree()
if exists("g:NERDTree") && g:NERDTree.IsOpen()
exe ":NERDTreeClose"
elseif @% == ""
exe ":NERDTreeToggle"
else
exe ":NERDTreeFind"
endif
endfun
" Fuzzy fzf Search
map <C-H><C-P> :History<CR>
map <C-P> :Files<CR>
map <C-K><C-O> :BTags<CR>
map <C-K><C-L> :Files %:p:h<CR>
" Yank all file to clipboard
map <C-A> :%y+<CR>
" Copy relative path to registry (for specs)
map <C-K><C-F> :let @+ = expand("%") <CR>
" Elixir (indent was bad)
filetype plugin indent off
" En quickFix use dd to remove entry
command! Dd :Reject<CR>
" Trim WhiteSpaces
fun! StripTrailingWhitespace()
" Don't strip on these filetypes
if &ft =~ 'yaml'
return
endif
%s/\s\+$//e
endfun
autocmd BufWritePre * call StripTrailingWhitespace()
" Show git branches
map <C-K><C-B> :GBranches<CR>
" Look and Feel
set termguicolors
colorscheme gruvbox
" colorscheme onehalfdark
" colorscheme monokai_pro
" colorscheme lucius
let g:lightline = {
\ 'colorscheme': 'monokai_pro',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], ['workingspace'],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead',
\ 'filename': 'LightlineFilename',
\ 'workingspace': 'WorkingSpace'
\ },
\ }
fun! WorkingSpace()
return substitute(getcwd(), '^.*/', '', '')
endfun
function! LightlineFilename()
let root = fnamemodify(get(b:, 'git_dir'), ':h')
let path = expand('%')
if path[:len(root)-1] ==# root
return path[len(root)+1:]
endif
return expand('%')
endfunction
let g:coc_node_path = "/home/joe/.asdf/installs/nodejs/17.9.1/bin/node"
" coc-tweeks
" To make <cr> select the first completion item and confirm the completion when no item has been selected:
"
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <c-j>
\ coc#pum#visible() ? coc#pum#next(1):
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><c-k> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" 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)
" GitDiff Color Scheme
hi DiffAdd ctermfg=NONE ctermbg=DarkGreen
hi DiffChange ctermfg=NONE ctermbg=NONE
hi DiffDelete ctermfg=LightBlue ctermbg=Red
hi DiffText ctermfg=Yellow ctermbg=Red
let g:coc_config_home = '$HOME/.vim'
" Use fdfind for fzf, exclude images
let $FZF_DEFAULT_COMMAND = "fdfind --type f -E '*.{png,ico}'"
" Colors for fzf modals
let $FZF_DEFAULT_OPTS = "-m --keep-right --color=bg+:#073642,bg:#002b36,spinner:#719e07,hl:#586e75,fg:#839496,header:#586e75,info:#cb4b16,pointer:#719e07,marker:#719e07,fg+:#839496,prompt:#719e07,hl+:#719e07"
command! -bang -nargs=* -complete=dir Files
\ call fzf#vim#files(<q-args>, {'options': ['--delimiter', '/', '--with-nth', '-3..', '--preview', 'bat --style=numbers --color=always --line-range :500 {}']}, <bang>0)
" This is needed for neovim, to do :e $MYVIMRC
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --max-columns 60 --max-columns-preview --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
\ <bang>0)
let $MYVIMRC = "~/.vimrc"
command! -nargs=0 Prettier :CocCommand prettier.formatFile
vmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" Disable arrow key - extreme mode
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>
command! -nargs=* Rg RgRaw <args>
command! -nargs=* G Gtabedit : <args>
map <C-l> :%bd <CR>
map <C-K><C-S> :tabnew $MYVIMRC<CR>
au BufNewFile,BufRead *.es6 set filetype=javascript
au BufNewFile,BufRead *.es6.erb set filetype=javascript
au BufNewFile,BufRead *.js.erb set filetype=javascript
" au BufNewFile,BufRead *.html.eex, *.html.leex set filetype=html
" au BufNewFile,BufRead *.html.eex, *.html.leex set syntax=eelixir
set cursorline
" QuickList nav
":vimgrep /task/ % | :copen find in buffer to quicklist
autocmd FileType qf map <C-j> :cn<CR>
autocmd FileType qf map <C-k> :cp<CR>
" Track the engine.
Plug 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Plug 'honza/vim-snippets'
" Trigger configuration. You need to change this to something other than <tab> if you use one of the following:
" - https://github.com/Valloric/YouCompleteMe
" - https://github.com/nvim-lua/completion-nvim
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
" Show signature
map <leader>d :call CocAction('doHover') <CR>
syntax on
hi Comment cterm=italic gui=italic ctermfg=lightblue guifg=lightblue
nnoremap <nowait><expr> <C-PageDown> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-PageDown>"
nnoremap <nowait><expr> <C-PageUp> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-PageUp>"
" Move lines
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==gi
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv
" Markdown paste from clipboard
autocmd FileType markdown nmap <buffer><silent> <leader>p :call mdip#MarkdownClipboardImage()<CR>
" there are some defaults for image directory and image name, you can change them
let g:mdip_imgdir = 'images'
" let g:mdip_imgname = 'image'
command! Dm :Git difftool -y main % | execute 'windo set wrap'
command! DM :Git difftool -y main
command! Cc :tabclose
"
" En quickFix use dd to remove entry
command! Dd :Reject
map <leader>ct :tabclose <CR>
map <leader>to :tabonly <CR>
"
" emmet
let g:user_emmet_install_global = 0
autocmd FileType html,css,eelixir,elixir,eruby EmmetInstall
" Highlight a word without moving to next
nnoremap * *``
" https://stackoverflow.com/questions/21316727/automatic-closing-brackets-for-vim
" inoremap " ""<left>
" inoremap ' ''<left>
" inoremap ( ()<left>
" inoremap [ []<left>
" inoremap { {}<left>
" " inoremap \| \|\|<left>
" inoremap {<CR> {<CR>}<ESC>O
" inoremap {;<CR> {<CR>};<ESC>O
"
" for indent line to work properly on json on nvim
" https://github.com/Yggdroot/indentLine/issues/140#issuecomment-165950627
let g:vim_json_syntax_conceal = 0
nnoremap <M-,> :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%<' . line('.') . 'l\S', 'be')<CR>
nnoremap <M-.> :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%>' . line('.') . 'l\S', 'e')<CR>
" With these mappings, in normal mode, press Alt-, to find the previous line with the same indent as the current line, or press Alt-. to find the next such line. These mappings should work in gvim, but you may need to choose different keys if working with Vim in a terminal.
" Search and replace word under cursor using F4
nnoremap <F4> :%s/<c-r><c-w>/<c-r><c-w>/gc<c-f>$F/i
nnoremap to :tabonly <CR>
" Find conflicts
nmap <C-c> /<<<<<<<\\|=======\\|>>>>>>>/ <CR>
" Break a line in to multiple lines
nmap <C-A-j> :.s/,\s/,\r/ <CR>
function! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
map <C-]> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <leader><C-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
"
vnoremap <F2> d:execute 'normal i' . join(sort(split(getreg('"'))), ' ')<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment