Skip to content

Instantly share code, notes, and snippets.

@AeonFr
Last active December 15, 2021 15:55
Show Gist options
  • Save AeonFr/a4fa31f24a2abb536e921694c9581f1b to your computer and use it in GitHub Desktop.
Save AeonFr/a4fa31f24a2abb536e921694c9581f1b to your computer and use it in GitHub Desktop.
Vim config (using Vundle)
set nocompatible
filetype off
" PLUGINS:
" -----------------------------
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" Sensible general purpoise config
" Adds mapping: Use <C-L> to clear the hightlighting (:nohl)
Plugin 'tpope/vim-sensible'
" Camel case motion
Plugin 'chaoren/vim-wordmotion'
" Comment stuff out
" Use gcc to comment out a line, gc<motion>, in visual mode: gc to comment selection
Plugin 'tpope/vim-commentary'
" Detect indent by file
Plugin 'ciaranm/detectindent'
if !exists('g:vscode')
" NerdTree
Plugin 'preservim/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'
" Git gutter
" Plugin 'airblade/vim-gitgutter'
" Airline
Plugin 'vim-airline/vim-airline'
" Better tabline
Plugin 'webdevel/tabulous'
" Themes
Plugin 'morhetz/gruvbox'
Plugin 'connorholyday/vim-snazzy'
Plugin 'jacoborus/tender.vim'
" Buffer delete UI
" Use :Bdelete hidden or :Bdelete select to delete all hidden (not in window)
" buffers or to close buffers interactively
Plugin 'Asheq/close-buffers.vim'
" Fast fuzzy file search
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
" Filetype support
Plugin 'jxnblk/vim-mdx-js'
Plugin 'jparise/vim-graphql'
Plugin 'jwalton512/vim-blade'
Plugin 'posva/vim-vue'
Plugin 'HerringtonDarkholme/yats.vim'
Plugin 'maxmellon/vim-jsx-pretty'
Plugin 'cakebaker/scss-syntax.vim'
" LSPs
Plugin 'neoclide/coc.nvim'
" Prettier
Plugin 'prettier/vim-prettier'
" CS Fixer
Plugin 'stephpy/vim-php-cs-fixer'
endif
call vundle#end()
filetype plugin indent on
" GENERAL:
" -----------------------------
" Line numbers
set cursorline
set number
" Finding files recursively with :find
" set path+=**
" Among other thigs, display all matching files when we tab complete
set wildmenu
" Always show the gutter, instead of waiting for plugins (linters, git-gutter)
" to show it for us
set signcolumn=yes
" Set to auto read when a file is changed from the outside
set autoread
au FocusGained,BufEnter * checktime
" Height of the command bar
" set cmdheight=1
" A buffer becomes hidden when it is abandoned
" set hid
" Hightlight search results
set hlsearch
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 2 spaces
set shiftwidth=2
set tabstop=2
" Linebreak on 500 characters
" set lbr
" set tw=500
set smartindent
set wrap
" fix issues with webpack
" https://github.com/webpack/webpack/issues/781
set backupcopy=yes
" fixes issues with webpack but also makes working with git easier
set noswapfile
" fold based on indentation
au BufReadPre * setlocal foldmethod=indent
set foldnestmax=10
set foldignore=""
set foldlevel=2
set nofoldenable
if !exists('g:vscode')
" Return to last edit position when opening files (You want this!)
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Enable omnicompletion
set omnifunc=syntaxcomplete#Complete
endif
" KEYMAPPINGS:
" -----------------------------
" Visual mode pressing * searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>"
function! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", "\\/.*'$^~[]")
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'gv'
call CmdLine("Ack '" . l:pattern . "' " )
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" Move between buffers
map <leader>bn :bnext<cr>
map <leader>bp :bprevious<cr>
" Close the current buffer
map <leader>bd :bdelete<cr>
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
" Shortcuts using <leader>
" sn/sp next/prev misspelled word
" sa add word
" s? show suggestions
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
" open a new tab
map <leader>t :tabnew<cr>
" SEARCH AND REPLACE:
" -----------------------------
" This topic deserves a whole article to cover. Here's one:
" https://dev.to/iggredible/how-to-search-faster-in-vim-with-fzf-vim-36ko
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
nnoremap <silent> <Leader>cn :cnext<CR>
nnoremap <silent> <Leader>cp :cprevious<CR>
nnoremap <silent> <Leader>cw :cw<CR>
nnoremap <silent> <Leader>cd :ccl<CR>
" now we can:
" - use :grep "search" to search faster through all files in folder
" (thanks to fzf, we can also populate quickfix from fzf using <C-Q> on the
" selected results (results are selected with tab or shift+tab, or <C-A> to
" select all))
" - use \cn, \cp, \cw to iterate through results or open them in quickfix
" - use :cfdo %s/find/replace/ge | update (to perform an update)
" - use :cfdo <command> to perform any command on the quickfix results
" - use \cd to close the quickfix window
" sort quickfix results automatically
function! s:CompareQuickfixEntries(i1, i2)
if bufname(a:i1.bufnr) == bufname(a:i2.bufnr)
return a:i1.lnum == a:i2.lnum ? 0 : (a:i1.lnum < a:i2.lnum ? -1 : 1)
else
return bufname(a:i1.bufnr) < bufname(a:i2.bufnr) ? -1 : 1
endif
endfunction
function! s:SortUniqQFList()
let sortedList = sort(getqflist(), 's:CompareQuickfixEntries')
let uniqedList = []
let last = ''
for item in sortedList
let this = bufname(item.bufnr) . "\t" . item.lnum
if this !=# last
call add(uniqedList, item)
let last = this
endif
endfor
call setqflist(uniqedList)
endfunction
autocmd! QuickfixCmdPost * call s:SortUniqQFList()
" NERDTREE:
" -----------------------------
if !exists('g:vscode')
nmap <C-B> :NERDTreeToggle<CR>
nmap <leader>b :NERDTreeFind<CR>
let g:NERDTreeChDirMode = 2 " This is required to (later) make Ctrl+P Nerd-tree-aware
" git-aware NERDTree
let g:NERDTreeGitStatusShowIgnored = 1
let g:NERDTreeGitStatusShowClean = 1
let NERDTreeShowHidden=1
let NERDTreeWinSize = 35
endif
" TABULOUS:
if !exists('g:vscode')
let tabulousLabelModifiedStr = '● '
let tabulousLabelNameOptions = ':t'
endif
" UI:
if !exists('g:vscode')
set guifont=JetBrains\ Mono:h14
endif
" THEMES:
" -----------------------------
if !exists('g:vscode')
let g:gruvbox_contrast_dark='medium' " soft, medium and hard
set termguicolors
set background=dark
colorscheme gruvbox " snazzy
endif
" FUZZY SEARCH:
" -----------------------------
" Ignore .gitignore by default
let $FZF_DEFAULT_COMMAND = 'fd --type f --hidden --follow --exclude .git '
" Use <C-A> to select all results in a command
let $FZF_DEFAULT_OPTS = '--bind ctrl-a:select-all'
" Use <C-Q> to send all results to the quickfix list
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
" Dont search filenames withg :Ag and :Rg
command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)
command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'}, <bang>0)
" fix neovim issue (fzf.vim#449)
" open down
let g:fzf_layout = { 'down': '~40%' }
if !exists('g:vscode')
" Search files with preview
nnoremap <silent> <C-f> :Files<CR>
" Search buffers
nnoremap <silent> <Leader>bf :Buffers<CR>
" Search commit in buffers
nnoremap <silent> <Leader>bg :BCommits<CR>
" Search file's contents (super useful)
nnoremap <silent> <Leader>f :Rg<CR>
" Search lines in the current buffer
nnoremap <silent> <Leader>/ :BLines<CR>
" Marks (don't know what this is!)
" nnoremap <silent> <Leader>' :Marks<CR>
" It's like running glola, but in the editor
nnoremap <silent> <Leader>g :Commits<CR>
" Help!
" nnoremap <silent> <Leader>H :Helptags<CR>
" v:oldfiles and open buffers
nnoremap <silent> <Leader>hh :History<CR>
" Command history
" nnoremap <silent> <Leader>h: :History:<CR>
" Search history
" nnoremap <silent> <Leader>h/ :History/<CR>
endif
" DETECT INDENT:
" -----------------------------
" DetectIntent config (note: use :DetectIndent to use)
let g:detectindent_preferred_expandtab=1
let g:detectindent_preferred_intend=2
" COC:
" -----------------------------
if !exists('g:vscode')
" Open stuff in split
let g:coc_user_config = {}
" let g:coc_user_config['coc.preferences.jumpCommand'] = ':tabnew'
"
" let g:coc_suggest_disable = 1
" let g:coc_start_at_startup = v:false
" KEYMAPS
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
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)
nmap <silent> ga :CocAction<CR>
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Remap <C-j> and <C-k> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-j> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-j>"
nnoremap <silent><nowait><expr> <C-k> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-k>"
inoremap <silent><nowait><expr> <C-j> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-k> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-j> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-j>"
vnoremap <silent><nowait><expr> <C-k> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-k>"
endif
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Make <tab> auto-select the first completion item and notify coc.nvim to
" format on enter, <tab> could be remapped by other vim plugin
inoremap <silent><expr> <tab> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
endif
" PRETTIER:
" -----------------------------
let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0
let g:prettier#exec_cmd_async = 1
" Disables quick-fix to auto open when files have errors
let g:prettier#quickfix_enabled=0
@AeonFr
Copy link
Author

AeonFr commented Jan 13, 2021

Some prerequisites:

  1. Install some dependencies
brew install fd
brew install ripgrep
brew install bat
brew install the_silver_searcher
brew install git-delta
  1. Configure fzf (in bash config)
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'

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