-
-
Save yriveiro/05b7d547c290e5f62b0bbc673630cc46 to your computer and use it in GitHub Desktop.
vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" | |
" ██╗ ██╗ ██╗ ███╗ ███╗ ██████╗ ██████╗ | |
" ██║ ██║ ██║ ████╗ ████║ ██╔══██╗ ██╔════╝ | |
" ██║ ██║ ██║ ██╔████╔██║ ██████╔╝ ██║ | |
" ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║ ██╔══██╗ ██║ | |
" ██╗╚████╔╝ ██║ ██║ ╚═╝ ██║ ██║ ██║ ╚██████╗ | |
" ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ | |
" | |
"""""""""""""""""""""""""""""" | |
" Plugins " | |
"""""""""""""""""""""""""""""" | |
call plug#begin('~/.vim/plugged') | |
" Colors & Highlighting | |
Plug 'altercation/vim-colors-solarized' | |
Plug 'neomake/neomake' " Linting | |
" File Navigation | |
Plug 'ctrlpvim/ctrlp.vim' " fuzzy file finder | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'scrooloose/nerdtree' " NerdTree file explorer | |
Plug 'mileszs/ack.vim' " vim frontend for ack | |
Plug 'vim-airline/vim-airline' " status bar | |
Plug 'tpope/vim-obsession' " save vim sessions and buffer constellations | |
" Editing | |
Plug 'editorconfig/editorconfig-vim' " sets indent-size tab-width etc. according to .editorconfig | |
Plug 'jiangmiao/auto-pairs' " insert or delete brackets, parens, quotes in pair. | |
Plug 'junegunn/vim-easy-align' " interactive align | |
Plug 'tpope/vim-surround' " quoting/parenthesizing made simple | |
Plug 'tomtom/tcomment_vim' | |
Plug 'djoshea/vim-autoread' " automatically reload a file that has changed externally | |
Plug 'terryma/vim-multiple-cursors' " sublime-style multiple selections for vim | |
Plug 'tpope/vim-abolish' " search for, substitute, and abbreviate multiple variants of a word | |
Plug 'tpope/vim-repeat' " enable repeating supported plugin maps with . | |
" Snippets / Autocompletion | |
Plug 'Valloric/YouCompleteMe', { 'do': './install.py --tern-completer' } " code-completion engine | |
Plug 'SirVer/ultisnips' " snippets plugin | |
Plug 'honza/vim-snippets' " exhaustive snippet collection | |
Plug 'mattn/emmet-vim' " emmet-style html-expansion via <c-y>, | |
Plug 'epilande/vim-es2015-snippets' " ES2015 snippets | |
Plug 'epilande/vim-react-snippets' " React snippets | |
" Language specific stuff | |
Plug 'leafgarland/typescript-vim', { 'for': 'typescript' } " typescript indentation and syntax highlighting | |
Plug 'Shougo/vimproc.vim', { 'for': 'typescript' } " async helper for Quramy/tsuquyomi | |
Plug 'Quramy/tsuquyomi', { 'for': 'typescript' } " omni-completion, go-to-symbol etc. | |
Plug 'ternjs/tern_for_vim', { 'for': 'javascript', 'do': 'npm install' } " intelligent javascript editing | |
Plug 'pangloss/vim-javascript', { 'for': 'javascript' } " vastly improved javascript indentation and syntax support | |
Plug 'mxw/vim-jsx', { 'for': 'javascript' } " JSX syntax highlighting and indenting | |
Plug 'flowtype/vim-flow', { 'for': 'javascript' } " flow completions and type checking | |
Plug 'stephenway/postcss.vim', { 'for': 'css' } " cutting-edge vim css syntax file | |
Plug 'ap/vim-css-color' " highlight css colors and variables in all kinds of filetypes | |
" Git | |
Plug 'tpope/vim-fugitive' " mainly for :Gblame >) | |
Plug 'Xuyuanp/nerdtree-git-plugin' " git status highlighting for NerdTree | |
call plug#end() " Add plugins to &runtimepath | |
"""""""""""""""""""""""""""""" | |
" Settings " | |
"""""""""""""""""""""""""""""" | |
set number " display line-numbers | |
set cursorline " highlight cursorline | |
set nowrap " no auto-wrapping of long lines | |
set expandtab " use spaces instead of tabs | |
set tabstop=2 " Render TABs using this many spaces. | |
set clipboard=unnamed " enable clipboard without "* registers | |
set shiftwidth=2 " Indentation amount for < and > commands. | |
set smartindent " autoindent new lines | |
set noswapfile " swapfiles are annoying | |
set timeoutlen=200 " Ever notice a slight lag after typing the leader key + command? This lowers the timeout | |
set incsearch " search as you type | |
set showmatch " Show matching brackets. | |
set gdefault " Use 'g' flag by default with :s/foo/bar/. | |
set noerrorbells " No annoying sound on errors | |
set visualbell " Visual feedback instead | |
set wildignore+=*/node_modules/*,*/vendor/*,*/jspm_packages/*,*/flow-typed/* " files to ignore for autocomplete | |
"""""""""""""""""""""""""""""" | |
" Global Config " | |
"""""""""""""""""""""""""""""" | |
" Keep undo history across sessions by storing it in a file | |
let nvimDir = '$HOME/.config/nvim' | |
if has('persistent_undo') | |
let myUndoDir = expand(nvimDir . '/undodir') | |
call system('mkdir ' . nvimDir) | |
call system('mkdir ' . myUndoDir) | |
let &undodir = myUndoDir | |
set undofile | |
endif | |
" Remember last location in file | |
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif | |
" Source .vimrc file after saving it | |
if has("autocmd") | |
autocmd! bufwritepost init.vim source $MYVIMRC | |
endif | |
"""""""""""""""""""""""""""""" | |
" Mappings " | |
"""""""""""""""""""""""""""""" | |
" set mapleader | |
let g:mapleader="," | |
" jj exits insert mode | |
inoremap jj <ESC> | |
" jj exit Insert Mode in :terminal buffers | |
tnoremap jj <C-\><C-n> | |
" Escape exit Insert Mode in :terminal buffers | |
tnoremap <Esc> <C-\><C-n> | |
" Escape removes highlight | |
nnoremap <silent> <ESC> :noh<CR> | |
" Shortcut to convert current buffer to :terminal buffer | |
map <Leader>t :terminal<CR> | |
" Remove trailing whitespaces on save | |
autocmd BufWritePre * :%s/\s\+$//e | |
" ,, maximizes current buffer in new tab | |
nnoremap <leader><leader> :tab split<CR> | |
" quicker saving | |
nnoremap <leader>w :w<CR> | |
" Shortcut to edit .vimrc | |
nmap <leader>v :tabedit $MYVIMRC<CR> | |
"""""""""""""""""""""""""""""" | |
" Windows / Buffers / Splits " | |
"""""""""""""""""""""""""""""" | |
" Open new split panes to right and bottom, which feels more natural than Vim’s default | |
set splitbelow | |
set splitright | |
nnoremap <leader>s :vsplit<CR> " vsplit | |
nnoremap <leader>d :split<CR> " hsplit | |
" change windowsizes in visual mode | |
" horizontally & vertically - always three chars else it takes ages | |
nnoremap <Char-246> 3<C-w>< | |
nnoremap <Char-228> 3<C-w>> | |
nnoremap <Char-220> 3<C-w>+ | |
nnoremap <Char-196> 3<C-w>- | |
" Smart way to manage buffers | |
nnoremap <leader>q :noautocmd q<CR> | |
nnoremap <leader>j :bp<CR> | |
nnoremap <leader>k :bn<CR> | |
nnoremap <leader>bd :bd<CR> " delete buffer | |
" Smart way to move between windows | |
nnoremap <C-h> <C-w>h | |
nnoremap <C-j> <C-w>j | |
nnoremap <C-k> <C-w>k | |
nnoremap <C-l> <C-w>l | |
" Smart way to manage tabs | |
nnoremap tl :tabnext<CR> | |
nnoremap th :tabprev<CR> | |
nnoremap tn :tabnew<CR> | |
nnoremap tc :tabclose<CR> | |
nnoremap tm :tabmove<CR> | |
nnoremap to :tabonly<CR> | |
" Delete hidden buffers | |
function! DeleteHiddenBuffers() | |
let tpbl=[] | |
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))') | |
for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1') | |
silent execute 'bwipeout' buf | |
endfor | |
endfunction | |
command! DeleteHiddenBuffers :call DeleteHiddenBuffers()<CR> | |
if !&scrolloff | |
" Show next 10 lines while scrolling. | |
set scrolloff=10 | |
endif | |
if !&sidescrolloff | |
" Show next 10 columns while side-scrolling. | |
set sidescrolloff=10 | |
endif | |
" let g:tern_request_timeout = 100 | |
"""""""""""""""""""""""""""""" | |
" Plugin Config " | |
"""""""""""""""""""""""""""""" | |
" Neomake | |
" Run Neomake on every buffer write | |
augroup vimrc_neomake | |
au! | |
autocmd BufWritePost * Neomake | |
augroup END``` | |
" let g:neomake_verbose = 3 " debug neomake | |
let g:neomake_open_list = 2 " auto-open error list | |
" Ctrl + f for fulltext search | |
map <C-f> :Ack!<space> | |
" TComment | |
map gcb :TCommentBlock<CR> | |
" Easy Align | |
" Start interactive EasyAlign in visual mode (e.g. vipga) | |
xmap ga <Plug>(EasyAlign) | |
" Start interactive EasyAlign for a motion/text object (e.g. gaip) | |
nmap ga <Plug>(EasyAlign) | |
if !exists('g:easy_align_delimiters') | |
let g:easy_align_delimiters = {} | |
endif | |
let g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignore_groups': ['String'] } | |
" 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 -g ""' | |
" ag is fast enough that CtrlP doesn't need to cache | |
let g:ctrlp_use_caching = 0 | |
endif | |
" UltiSnips | |
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe. | |
let g:UltiSnipsExpandTrigger="<tab>" | |
let g:UltiSnipsJumpForwardTrigger="<c-b>" | |
let g:UltiSnipsJumpBackwardTrigger="<c-z>" | |
function! g:UltiSnips_Complete() | |
call UltiSnips#ExpandSnippet() | |
if g:ulti_expand_res == 0 | |
if pumvisible() | |
return "\<C-n>" | |
else | |
call UltiSnips#JumpForwards() | |
if g:ulti_jump_forwards_res == 0 | |
return "\<TAB>" | |
endif | |
endif | |
endif | |
return "" | |
endfunction | |
au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>" | |
let g:UltiSnipsJumpForwardTrigger="<tab>" | |
let g:UltiSnipsListSnippets="<c-e>" | |
" NERDTree | |
" Size Standard Size | |
let g:NERDTreeWinSize=30 | |
" Show dotfiles | |
let g:NERDTreeShowHidden=1 | |
" No Secondary NERDTree Windows | |
let g:NERDTreeHijackNetrw=0 | |
" Open NERDTree | |
map <Leader>n :NERDTreeToggle<cr> | |
" Reset NERDTree Width | |
map <Leader>r :vertical resize 30<CR> | |
" Open Current File in NERDTree | |
map <Leader>f :NERDTreeFind<cr> | |
" Add space when outcommenting | |
let g:NERDSpaceDelims=1 | |
" Sessions | |
" Autoload sessions created by tpope's vim-obsession when starting Vim. | |
augroup sourcesession | |
autocmd! | |
autocmd VimEnter * nested | |
\ if !argc() && empty(v:this_session) && filereadable('Session.vim') | | |
\ source Session.vim | | |
\ endif | |
augroup END | |
let g:airline#extensions#branch#enabled = 0 | |
" this mapping Enter key to <C-y> to chose the current highlight item | |
" and close the selection list, same as other IDEs. | |
" CONFLICT with some plugins like tpope/Endwise | |
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
function! Multiple_cursors_before() | |
let s:old_ycm_whitelist = g:ycm_filetype_whitelist | |
let g:ycm_filetype_whitelist = {} | |
endfunction | |
function! Multiple_cursors_after() | |
let g:ycm_filetype_whitelist = s:old_ycm_whitelist | |
endfunction | |
" Git | |
let g:fugitive_github_domains = ['https://github.mdl.zone'] | |
"""""""""""""""""""""""""""""" | |
" Language Config " | |
"""""""""""""""""""""""""""""" | |
" HTML | |
" let g:syntastic_html_tidy_ignore_errors = [" proprietary attribute " , "trimming empty <", "unescaped &" , "lacks \"action", "is not recognized!", "discarding unexpected", " is invalid"] | |
" JavaScript | |
let g:neomake_verbose = 3 " debug | |
let g:neomake_javascript_enabled_makers = ['eslint', 'flow'] | |
let g:neomake_jsx_enabled_makers = ['eslint', 'flow'] | |
let g:neomake_javascript_eslint_exe = system('PATH=$(npm bin):$PATH && which eslint | tr -d "\n"') " try using local eslint, fallback to global | |
let g:javascript_enable_domhtmlcss = 1 " enables html & css highlighting within .js files (from pangloss/vim-javascript) | |
let g:jsx_ext_required = 0 " enable jsx highlighting and indentation for non *.jsx files | |
" Jump to definition inside preview buffer | |
autocmd FileType javascript,javascript.jsx nnoremap <leader>g :TernDefSplit<CR> | |
" TypeScript | |
if !exists("g:ycm_semantic_triggers") | |
let g:ycm_semantic_triggers = {} | |
endif | |
let g:ycm_semantic_triggers['typescript'] = ['.'] | |
let g:tsuquyomi_disable_quickfix = 1 | |
" let g:syntastic_typescript_checkers = ['tslint', 'tsuquyomi'] | |
autocmd FileType typescript syn clear foldBraces | |
autocmd FileType typescript JsPreTmpl html | |
autocmd FileType typescript nmap <buffer> <Leader>h : <C-u>echo tsuquyomi#hint()<CR> | |
autocmd FileType typescript nnoremap <leader>g :TsuDefinition<CR> | |
map <Leader>b :TsuGoBack<CR> | |
" CSS | |
let g:neomake_css_enabled_makers = ['stylelint'] | |
let g:neomake_css_stylelint_exe = system('PATH=$(npm bin):$PATH && which stylelint | tr -d "\n"') " try using local stylelint, fallback to global | |
autocmd BufNewFile,BufRead *.css set syntax=postcss " Get advanced highlighting for nested definitions, variables etc. | |
autocmd FileType css,scss,postcss setlocal omnifunc=csscomplete#CompleteCSS | |
""""""""""""""""""""""""""""""" | |
" Dotfiles Filetypes " | |
""""""""""""""""""""""""""""""" | |
au BufRead,BufNewFile Brewfile setf sh | |
au BufRead,BufNewFile .babelrc setf json | |
au BufRead,BufNewFile .eslintrc setf json | |
au BufRead,BufNewFile .stylelintrc setf json | |
"""""""""""""""""""""""""""""" | |
" Set Theme " | |
"""""""""""""""""""""""""""""" | |
let g:solarized_contrast='high' | |
let g:solarized_termcolors=256 | |
function! DarkTheme() | |
set background=dark | |
let g:solarized_termtrans=1 | |
colorscheme solarized | |
endfunction | |
command! Dark :call DarkTheme()<CR> | |
function! LightTheme() | |
set background=light | |
let g:solarized_termtrans=0 | |
colorscheme solarized | |
endfunction | |
command! Light :call LightTheme()<CR> | |
:call DarkTheme() | |
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 | |
set secure " safeguard init.vim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment