Skip to content

Instantly share code, notes, and snippets.

@cravacuore
Last active April 6, 2020 22:38
Show Gist options
  • Save cravacuore/d15fbd1ff10f9e13a5e0 to your computer and use it in GitHub Desktop.
Save cravacuore/d15fbd1ff10f9e13a5e0 to your computer and use it in GitHub Desktop.
My always getting better (for me) frankenstein vim config for life.
" Vim config mostly based on thoughtbot config
" with parts of various mythical creatures
" and some of my crazy ideas
" First python call defines what version uses after, call python3 to force it first.
if has('python3')
endif
"" vim-plug plugin manager
"" Automatically setting up vim-plug, taken from https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
"Add your bundles here
"
" Plugins via Github repos
"" Style plugins
Plug 'edkolev/tmuxline.vim' " Tmux statusline generator
Plug 'vim-airline/vim-airline' " Powerline-like vim only
Plug 'vim-airline/vim-airline-themes' " Powerline-airline themes
Plug 'powerline/fonts' " Needed fonts for airline
Plug 'joshdick/onedark.vim' " Dark color scheme
" Plug 'morhetz/gruvbox' " Retro groove color scheme
" Plug 'trevordmiller/nova-vim' " A coding color scheme
" Plug 'crusoexia/vim-monokai' " Monokai font color scheme
" Plug 'kristijanhusak/vim-hybrid-material' " Material color scheme
""
"" Snippets
Plug 'SirVer/ultisnips' " Templates for quick repeatable tasks
Plug 'honza/vim-snippets' " Pre-created snippets for ultisnips use
""
"" Syntax + autocompletions
Plug 'neoclide/coc.nvim', {'branch': 'release'} " Intellisense engine, full language server protocol
Plug 'ctrlpvim/ctrlp.vim' " Ctrl + P functionality (use with AG)
Plug 'dense-analysis/ale' " Asynchronous lint, check syntax and fix files, with LSP support.
Plug 'Raimondi/delimitMate' " Auto close (){}[]..
Plug 'mattn/emmet-vim' " Support for expanding abbreviations similar to emmet.
"
" Plug 'Valloric/YouCompleteMe' " Automagically full featured completion manager
" Plug 'Shougo/neocomplete.vim' " Next generation completion framework
" Plug 'sheerun/vim-polyglot' " Syntax bundle. Lots of languages syntax pack. On demand load.
" Plug 'ervandew/supertab' " Subl-like tab completion for already on file text
" Plug 'scrooloose/syntastic' " Runs external syntax checkers
" Plug 'othree/javascript-libraries-syntax.vim' " Syntax for JS libraries.
" Plug 'christoomey/vim-run-interactive'
"Plug 'posva/vim-vue' " Syntax Highlight for Vue.js components.
""
"" Utils
Plug 'tpope/vim-eunuch' " Vim sugar for shell commands. :Remove :Move :SudoEdit :Chmod
Plug 'tpope/vim-repeat' " . repeat functionality for plugins as well
Plug 'tpope/vim-surround' " Change surround ()[]''... cs
Plug 'tpope/vim-unimpaired' " Pairs of handy bracket mappings (]q, [q, [e, ]e)
Plug 'pbrisbin/vim-mkdir' " Creates necesary folders for :e /some/file
Plug 'vim-scripts/tComment' " Comment lines easy with gc(motion)c
Plug 'jeetsukumaran/vim-filebeagle' " File browser, only to browse and open
Plug 'junegunn/vim-easy-align' " For fast tabulation on multiple lines
Plug 'mhinz/vim-startify' " Start page for vim
Plug 'kien/rainbow_parentheses.vim' " Show matching parentheses with colors
Plug 'andymass/vim-matchup' " Highlights symbols and words under the cursor which % can work on; their matches and more
Plug 'justinmk/vim-sneak' " Motion to find next ocurrences of exactly two characters
Plug 'terryma/vim-expand-region' " Fast visual selection + config below for vvv
Plug 'terryma/vim-multiple-cursors' " Sublime-like multiple fast word selection
Plug 'vim-scripts/IndexedSearch' " Show the number of occurrences in a search
Plug 'ConradIrwin/vim-bracketed-paste' " Automatically sets paste mode when pasting, to avoid auto-indentation
Plug 'vimwiki/vimwiki' " Wiki/Todo list inside vim (Leader+ww)
Plug 'mileszs/ack.vim' " Find/Search util. Needs 'ack' installed on system
Plug 'junegunn/goyo.vim' " Distraction-free writing in Vim.
Plug 'junegunn/limelight.vim' " Dim fonts to focus on current paragraph, integrates with Goyo.
Plug 'kristijanhusak/vim-carbon-now-sh' " Code screenshot with style (opens highlighted text on carbon.now.sh)
" Plug 'ap/vim-css-color' " Preview colors in source code while editing
" Plug 'christoomey/vim-tmux-navigator' " Seamless navigation between tmux panes and vim splits
" Plug 'metakirby5/codi.vim' " The interactive scratchpad for hackers.
" Plug 'vim-scripts/ctags.vim'
""
"" Git plugins
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'airblade/vim-gitgutter' " Git diff in the 'gutter' (sign column)
""
"" Ruby
Plug 'tpope/vim-endwise' " Ends certain structures automatically (ex: ruby 'end')
" Plug 'thoughtbot/vim-rspec' " RSpec integration
" Plug 'skalnik/vim-vroom' " Run Ruby tests (rspec, cucumber)
" Plug 'tpope/vim-bundler' " Ruby bundler integration :Bundle
" Plug 'tpope/vim-rails' " Ruby on rails wrapper
""
call plug#end()
" /vim-plug plugin manager end
" It also needs installed on system for plugins to use: eslint / ack
" VIM Config
"
" Automatic reload of vimrc file
autocmd! bufwritepost /etc/vimrc source %
" Change this shell setting accordingly (primary if using gitgutter)
" TODO - automatically change this setting
set shell=/bin/zsh
" set shell=/bin/fish
" Setting Leader to Space
let mapleader = " "
scriptencoding utf-8
set encoding=utf-8
set termencoding=utf-8
set backspace=2 " backspace deletes like most programs in insert mode
set noshowmode " getting rid of vim's default mode indicator
set history=500
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set laststatus=2 " always display the status line
set autowrite " automatically :write before running commands
set path+=** " search down into subfolders (to :find files into subfolders)
" Search settings
set incsearch " do incremental searching
set ignorecase " case insensitive
set smartcase " if searching with uppercase letters, finds exactly matches
" Disable backup and swap files
set nobackup
set nowritebackup
set noswapfile
" Save and restore folds (see viewdir, default: ~/.vim/view)
" au BufWinLeave * mkview
" au BufWinEnter * silent loadview
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set shiftround
set expandtab
" Persist selection when indenting visual blocks
vnoremap < <gv
vnoremap > >gv
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
endif
" Using 24-bit 'truecolor' colors
if (has("termguicolors"))
set termguicolors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
filetype plugin indent on
" Onedark transparency - transparent bg setting
if (has("autocmd") && !has("gui_running"))
augroup colorset
autocmd!
let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16" : "7" }
autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) " `bg` will not be styled since there is no `bg` setting
augroup END
endif
" Sets colorscheme
set t_Co=256 " Forces vim to use 256 terminal color range
" colorscheme monokai
" colorscheme hybrid_reverse
colorscheme onedark
" colorscheme nova
" colorscheme gruvbox
" set bg=dark " Can be changed to 'light' when using gruvbox colorscheme
let g:enable_bold_font = 1
" Transparent background
" hi Normal ctermbg=none
" Sneak replacing 'f' motion
nmap f <Plug>Sneak_s
nmap F <Plug>Sneak_S
xmap f <Plug>Sneak_s
xmap F <Plug>Sneak_S
omap f <Plug>Sneak_s
omap F <Plug>Sneak_S
" Rainbow Parentheses always on
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
augroup vimrcEx
autocmd!
" When editing a file, always jump to the last known cursor position.
" Don't do it for commit messages, when the position is invalid, or when
" inside an event handler (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Set syntax highlighting for specific file types
autocmd BufRead,BufNewFile Appraisals set filetype=ruby
autocmd BufRead,BufNewFile *.md set filetype=markdown
" Automatically wrap at 80 characters for Markdown
" autocmd BufRead,BufNewFile *.md setlocal textwidth=80
" Automatically wrap at 72 characters and spell check git commit messages
autocmd FileType gitcommit setlocal textwidth=72
autocmd FileType gitcommit setlocal spell
" Allow stylesheets to autocomplete hyphenated words
autocmd FileType css,scss,sass setlocal iskeyword+=-
augroup END
" Display extra whitespaces
set list listchars=tab:»·,trail:·,nbsp:·
" Automatically remove trailing spaces when saving + save cursor position
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" If want to go to new line at 80 characters
" set textwidth=80
" Line Numbers
set rnu
set number
set numberwidth=5
" Tab completion
" will insert tab at beginning of line,
" will use completion if not at beginning
set wildmode=list:longest,list:full
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>
inoremap <S-Tab> <c-n>
" Exclude Javascript files in :Rtags via rails.vim due to warnings when parsing
let g:Tlist_Ctags_Cmd="ctags --exclude='*.js'"
" Index ctags from any project
map <Leader>ct :!ctags -R .<CR>
" Switch between the last two files
nnoremap <leader><leader> <c-^>
" Change between buffers shortcut
nnoremap <silent> [b :bprevious<cr>
nnoremap <silent> ]b :bnext<cr>
" Don't use arrow keys
" nnoremap <Left> :echoe "Use h"<CR>
" nnoremap <Right> :echoe "Use l"<CR>
" nnoremap <Up> :echoe "Use k"<CR>
" nnoremap <Down> :echoe "Use j"<CR>
" Disable arrow movement, resize splits instead.
" (Note: 'Ctrl + W + =' make splits equal)
nnoremap <Up> :resize -2<CR>
nnoremap <Down> :resize +2<CR>
nnoremap <Left> :vertical resize -2<CR>
nnoremap <Right> :vertical resize +2<CR>
" vim-rspec mappings
" nnoremap <Leader>t :call RunCurrentSpecFile()<CR>
" nnoremap <Leader>s :call RunNearestSpec()<CR>
" nnoremap <Leader>l :call RunLastSpec()<CR>
"""
" Working with Django projects mappings (based on:
" https://code.djangoproject.com/wiki/UsingVimWithDjango)
let g:last_relative_dir = ''
nnoremap \1 :call RelatedFile ("models.py")<cr>
nnoremap \2 :call RelatedFile ("views.py")<cr>
nnoremap \3 :call RelatedFile ("tests.py")<cr>
nnoremap \4 :call RelatedFile ("forms.py")<cr>
nnoremap \5 :call RelatedFile ("services.py")<cr>
nnoremap \6 :call RelatedFile ("urls.py")<cr>
nnoremap \7 :call RelatedFile ( "templates/" )<cr>
nnoremap \8 :call RelatedFile ("admin.py")<cr>
nnoremap \9 :e urls.py<cr>
nnoremap \0 :e settings.py<cr>
fun! RelatedFile(file)
" This is to check that the directory looks djangoish
if filereadable(expand("%:h"). '/models.py') || isdirectory(expand("%:h") . "/templatetags/")
exec "edit %:h/" . a:file
let g:last_relative_dir = expand("%:h") . '/'
return ''
endif
if g:last_relative_dir != ''
exec "edit " . g:last_relative_dir . a:file
return ''
endif
echo "Cant determine where relative file is : " . a:file
return ''
endfun
fun! SetAppDir()
if filereadable(expand("%:h"). '/models.py') || isdirectory(expand("%:h") . "/templatetags/")
let g:last_relative_dir = expand("%:h") . '/'
return ''
endif
endfun
autocmd BufEnter *.py call SetAppDir()
"""
" Run commands that require an interactive shell (vim-run-interactive)
" nnoremap <Leader>r :RunInInteractiveShell<space>
" Open file with CtrlP shortcut
nnoremap <Leader>o :CtrlP<CR>
" Ignore node_modules folder for CtrlP
let g:ctrlp_custom_ignore = 'node_modules'
" Save file shortcut
nnoremap <Leader>w :w<CR>
" Treat <li> and <p> tags like the block tags they are
let g:html_indent_tags = 'li\|p'
" Open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright
" Quicker window movement
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Syntastic settings
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
" let g:syntastic_html_tidy_ignore_errors = [" proprietary attribute \"ng-"]
" ALE settings (https://davidtranscend.com/blog/configure-eslint-prettier-vim/)
" eslint must be installed on system (npm i -g eslint)
let g:ale_sign_error = '✘'
let g:ale_sign_warning = '⚠'
highlight ALEErrorSign ctermbg=NONE ctermfg=red
highlight ALEWarningSign ctermbg=NONE ctermfg=yellow
let g:ale_fixers = ['eslint']
let g:ale_fix_on_save = 1
" Vim-vue settings - disabling other preprocessors
let g:vue_disable_pre_processors = 1
" Javascript-libraries-syntax settings
" let g:used_javascript_libs = 'vue,react,jquery,d3'
" Activate limelight when starting Goyo
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!
" Carbon code screenshot (carbon.now.sh)
vnoremap <F5> :CarbonNowSh<CR>
" TODO - add bg
" \ 'bg': 'rgba\(173%2C187%2C199%2C1)',
let g:carbon_now_sh_options =
\ { 'ln': 'true',
\ 't': 'one-dark',
\ 'l': 'auto',
\ 'fm': 'Source Code Pro' }
" Always use vertical diffs
set diffopt+=vertical
" Config for vvv fast visual selection with vim-expand-region plugin
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
vmap <Enter> <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" neocomplete config
" let g:neocomplete#enable_at_startup = 1
" if !exists('g:neocomplete#force_omni_input_patterns')
" let g:neocomplete#force_omni_input_patterns = {}
" endif
" " let g:neocomplete#force_omni_input_patterns.python = '\%([^. \t]\.\|^\s*@\|^\s*from\s.\+import \|^\s*from \|^\s*import \)\w*'
" " <TAB>: completion.
" inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" coc config
" Use <c-space> to trigger completion
inoremap <silent><expr> <c-space> coc#refresh()
" List of extensions
let g:coc_global_extensions = [
\ 'coc-tsserver',
\ 'coc-prettier',
\ 'coc-eslint',
\ 'coc-tailwindcss',
\ 'coc-ultisnips',
\ 'coc-vetur'
\ ]
" 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=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" 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> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" 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)
" 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>')
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current line.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Use <TAB> for selections ranges.
" NOTE: Requires 'textDocument/selectionRange' support from the language server.
" coc-tsserver, coc-python are the examples of servers that support it.
nmap <silent> <TAB> <Plug>(coc-range-select)
xmap <silent> <TAB> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" / end coc config
" airline
let g:airline_powerline_fonts = 1
let g:airline_theme = "onedark" " wombat / gruvbox / onedark / badcat / murmur / badwolf / hybrid / bubblegum
" Using tmux plugins data on tmuxline preset
"
" Internet connection available?
let online_status="Online: #( ~/.tmux/plugins/tmux-online-status/scripts/online_status_icon.sh )"
" Battery
let battery_status="Batt: #( ~/.tmux/plugins/tmux-battery/scripts/battery_percentage.sh )"
" Date and Time formats
let date ="%m-%d"
let time ="%R"
" tmuxline - 'a''b''c'/'win''cwin'/'x''y''z'
let g:tmuxline_preset = {
\'a': '#S',
\'win': '#I: #W',
\'cwin': '#I: #W',
\'x': [battery_status, online_status],
\'y': [date, time],
\'z': '#H',
\ 'options': {
\'status-justify': 'left'}
\}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment