Last active
June 10, 2019 20:54
-
-
Save mikowl/c924486cfec6b5c39b7da737038a8f39 to your computer and use it in GitHub Desktop.
.vimrc (NerdTree version)
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
set encoding=utf8 | |
set nocompatible | |
" Plugins | |
call plug#begin('~/.vim/plugged') | |
Plug 'tpope/vim-sensible' | |
Plug 'tpope/vim-fugitive' | |
Plug 'tpope/vim-repeat' | |
Plug 'tpope/vim-markdown' | |
Plug 'masukomi/vim-markdown-folding' | |
Plug 'easymotion/vim-easymotion' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'scrooloose/nerdtree' | |
Plug 'Xuyuanp/nerdtree-git-plugin' | |
Plug '/usr/local/opt/fzf' | |
Plug 'junegunn/fzf.vim' | |
Plug 'ctrlpvim/ctrlp.vim' | |
Plug 'rbong/vim-crystalline' | |
Plug 'mattn/emmet-vim' | |
Plug 'terryma/vim-multiple-cursors' | |
Plug 'arcticicestudio/nord-vim' | |
Plug 'ryanoasis/vim-devicons' | |
Plug 'godlygeek/tabular' | |
Plug 'luochen1990/rainbow' | |
Plug 'posva/vim-vue' | |
call plug#end() | |
" # General | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Enable filetype plugins | |
filetype plugin on | |
filetype indent on | |
"Set auto read when a file is changed from the outside | |
set autoread | |
"Copy to system clicpboard | |
set clipboard=unnamed | |
" Set leader key | |
let mapleader = "," | |
" :W sudo saves the file | |
command W w !sudo tee % > /dev/null | |
" Automatically source vimrc on save. | |
autocmd! bufwritepost $MYVIMRC source $MYVIMRC | |
" Save folds | |
augroup remember_folds | |
autocmd! | |
au BufWinLeave ?* mkview 1 | |
au BufWinEnter ?* silent loadview 1 | |
augroup END | |
" Markdown | |
" set foldmethod=manual | |
set foldcolumn=2 | |
" fenced code block | |
let g:markdown_fenced_languages = ['html', 'css', 'php', 'javascript', 'python', 'bash=sh', 'vim'] | |
augroup markdown | |
au! | |
au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown | |
augroup END | |
" vim-markdown-folding | |
if has("autocmd") | |
filetype plugin indent on | |
endif | |
" default to nested folding | |
autocmd FileType markdown set foldexpr=StackedMarkdownFolds() | |
" open markdown preview in chrome | |
autocmd BufEnter *.md exe 'noremap <silent> <leader>gc :!open % -a Google\ Chrome <cr>' | |
" spell check | |
set spellfile=~/.vim/spell/en.utf-8.add | |
" lazy drawing | |
" set lazyredraw | |
set ttyfast | |
" change cursors depending on mode | |
let &t_SI = "\e[6 q" | |
let &t_EI = "\e[2 q" | |
" highlight line when in insert mode | |
autocmd InsertEnter,InsertLeave * set cul! | |
" # Color schemes | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Enable syntax and plugins | |
syntax on | |
" Set colorscheme | |
" Color schemes I like: nord, one, night-owl, palenight | |
set background=dark | |
colorscheme nord | |
let g:nord_italic = 1 | |
" # Interface | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Set 7 lines to the cursor when moving vertically using j/k | |
set so=7 | |
" Display all matching files when we tab complete | |
set wildmenu | |
"Always show current position | |
set ruler | |
" Height of the command bar | |
set cmdheight=1 | |
" A buffer becomes hidden when it is abandoned | |
set hid | |
" Configure backspace so it acts as it should act | |
set backspace=eol,start,indent | |
set whichwrap+=<,>,h,l | |
" Search settings | |
set smartcase " smart cases when search | |
set hlsearch " highlight search results | |
set incsearch " incremental searching | |
set ignorecase " ignore case when searching | |
" For regular expressions turn magic on | |
set magic | |
set showmatch " shows matching brackets | |
set mat=2 | |
" Diable sounds | |
set noerrorbells | |
set novisualbell | |
set t_vb= | |
set tm=500 | |
" Add a bit of margin to left | |
set foldcolumn=2 | |
" # Files, backups and undo | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Turn backup off, since most stuff is in SVN, git et.c anyway... | |
set nobackup | |
set nowb | |
set noswapfile | |
" # Text, tab, and indent stuff | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Indent | |
set expandtab | |
set shiftwidth=2 | |
set autoindent | |
set smartindent | |
" Disable auto-wrap | |
set nowrap | |
set textwidth=0 | |
set wrapmargin=0 | |
" Set word wrap in markdown files | |
au BufRead,BufNewFile *.md set wrap linebreak nolist | |
au BufRead,BufNewFile *.md setlocal textwidth=80 | |
set ai " Auto indent | |
set si " Smart indent | |
" Line numbers | |
set number | |
highlight LineNr ctermfg=24 | |
" # Visual mode stuff | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Visual mode pressing * or # searches for the current selection | |
" Super useful! From an idea by Michael Naumann | |
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR> | |
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR> | |
" # Moving around, tabs, windows, and buffers | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Disable highlight when <leader><cr> is pressed | |
map <silent> <leader><cr> :noh<cr> | |
" Smart way to move between windows | |
map <C-j> <C-W>j | |
map <C-k> <C-W>k | |
map <C-h> <C-W>h | |
map <C-l> <C-W>l | |
" toggle folds in markdown files (vim-fold-toggle plugin) | |
nnoremap <leader>ft :FoldToggle<CR> | |
" Split vertically to bottom | |
set splitbelow | |
" buffers | |
nnoremap <leader>b :buffers<CR>:buffer<space> | |
" # Status line | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Always show the status line | |
set laststatus=2 | |
" # Key bindings | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Make `jj` and `jk` throw you into normal mode | |
inoremap jj <esc> | |
inoremap jk <esc> | |
" Remap HJKL to something more useful | |
nnoremap H ^ | |
nnoremap L $ | |
nnoremap J <C-d> | |
nnoremap K <C-u> | |
" I don't like d to copy | |
nnoremap <leader>d "_d | |
xnoremap <leader>d "_d | |
xnoremap <leader>p "_dP | |
" Type mm to cut a line | |
nnoremap mm yydd | |
" Find & replace helpers | |
" /foo<CR>, press CMD+d, fill and hit return | |
nnoremap <C-g> :%s///g<Left><Left> | |
" and here for those who have 'gdefault' enabled | |
nnoremap gs :%s//<Left> | |
" Move visual block | |
vnoremap J :m '>+1<CR>gv=gv | |
vnoremap K :m '<-2<CR>gv=gv | |
" Moves the matches for your search to the center of the screen when you press n or N | |
nnoremap n nzz | |
nnoremap N Nzz | |
" Type ,w to save, ,q to exit | |
nmap <leader>w :w!<cr> | |
nmap <leader>q :q!<cr> | |
" Type ,wq to save and exit | |
nmap <leader>wq :wq!<cr> | |
set conceallevel=2 | |
" # Misc | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Briefly highlight the part of the buffer that was yanked. | |
function! s:hl_yank() abort | |
let [sl, el, sc, ec] = [line("'["), line("']"), col("'["), col("']")] | |
if sl == el | |
let pos_list = [[sl, sc, ec - sc + 1]] | |
else | |
let pos_list = [[sl, sc, col([sl, "$"]) - sc]] + range(sl + 1, el - 1) + [[el, 1, ec]] | |
endif | |
for chunk in range(0, len(pos_list), 8) | |
call matchaddpos('IncSearch', pos_list[chunk:chunk + 7]) | |
endfor | |
redraw! | |
call timer_start(500, {t_id -> clearmatches()}) | |
endfunction | |
augroup HlYank | |
autocmd! | |
autocmd TextYankPost * if v:event.operator ==# 'y' | call s:hl_yank() | endif | |
augroup END | |
" Remove the Windows ^M - when the encodings gets messed up | |
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm | |
" Fix esc lag | |
set timeoutlen=1000 ttimeoutlen=0 | |
" # Functions | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" # Plugin settings | |
""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Bracket highlighting | |
let g:rainbow_active = 1 | |
" Search down into subfolders, provides tab-completion | |
set path+=** | |
" Emmet | |
imap <expr> <tab> emmet#expandAbbrIntelligent("\<tab>") | |
" easymotion | |
nnoremap ,z H:call EasyMotion#WB(0, 0)<CR> | |
" Git gutter | |
set updatetime=100 | |
" let g:EasyMotion_use_upper = 1 " Use uppercase target labels and type as a lower case | |
let g:EasyMotion_smartcase = 1 " type `l` and match `l`&`L` | |
let g:EasyMotion_use_smartsign_us = 1 " Smartsign (type `3` and match `3`&`#`) | |
let g:EasyMotion_do_mapping = 0 " Disable default mappings | |
map <Leader> <Plug>(easymotion-prefix) | |
" Jump to anywhere you want with minimal keystrokes, with just one key binding. | |
" `s{char}{label}` | |
nmap s <Plug>(easymotion-overwin-f) | |
" JK motions: Line motions | |
map <Leader>j <Plug>(easymotion-j) | |
map <Leader>k <Plug>(easymotion-k) | |
" Fuzzy Find :FZF | |
nmap <leader>f :FZF<cr> | |
nnoremap <C-p> :CtrlP<Cr> | |
" NERDTree | |
nmap <leader>ne :NERDTreeToggle<cr> | |
" alternate shortcut | |
map <silent> <C-\> :NERDTreeToggle<CR> | |
" open NT automatically when vim starts up on opening a directory | |
autocmd StdinReadPre * let s:std_in=1 | |
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif | |
" Close vim if the only window left is NT | |
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif | |
let NERDTreeMinimalUI = 1 | |
"let NERDTreeDirArrows = 1 | |
hi Directory guifg=#838CBF ctermfg=6d | |
hi NERDTreeClosable guifg=#89DDFF ctermfg=175 | |
hi NERDTreeOpenable guifg=#89DDFF ctermfg=108 | |
" NERDTrees File highlighting | |
function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg) | |
exec 'autocmd filetype nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:guibg .' guifg='. a:guifg | |
exec 'autocmd filetype nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension .'$#' | |
endfunction | |
call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '#151515') | |
call NERDTreeHighlightFile('ini', 'yellow', 'none', 'yellow', '#151515') | |
call NERDTreeHighlightFile('md', 'blue', 'none', '#3366FF', '#151515') | |
call NERDTreeHighlightFile('yml', 'yellow', 'none', 'yellow', '#151515') | |
call NERDTreeHighlightFile('config', 'yellow', 'none', 'yellow', '#151515') | |
call NERDTreeHighlightFile('conf', 'yellow', 'none', 'yellow', '#151515') | |
call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '#151515') | |
call NERDTreeHighlightFile('html', 'cyan', 'none', 'yellow', '#151515') | |
call NERDTreeHighlightFile('styl', 'cyan', 'none', 'cyan', '#151515') | |
call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '#151515') | |
call NERDTreeHighlightFile('less', 'cyan', 'none', 'cyan', '#151515') | |
call NERDTreeHighlightFile('coffee', 'Red', 'none', 'red', '#151515') | |
call NERDTreeHighlightFile('js', 'Red', 'none', '#ffa500', '#151515') | |
call NERDTreeHighlightFile('php', 'Magenta', 'none', '#ff00ff', '#151515') | |
" NERDTree git plugin | |
let g:NERDTreeIndicatorMapCustom = { | |
\ "Modified" : "✹", | |
\ "Staged" : "✚", | |
\ "Untracked" : "✭", | |
\ "Renamed" : "➜", | |
\ "Unmerged" : "═", | |
\ "Deleted" : "✖", | |
\ "Dirty" : "✗", | |
\ "Clean" : "✔︎", | |
\ 'Ignored' : '☒', | |
\ "Unknown" : "?" | |
\ } | |
" Crystalline | |
function! StatusLine(current, width) | |
let l:s = '' | |
if a:current | |
let l:s .= crystalline#mode() . crystalline#right_mode_sep('') | |
else | |
let l:s .= '%#CrystallineInactive#' | |
endif | |
let l:s .= ' %f%h%w%m%r ' | |
if a:current | |
let l:s .= crystalline#right_sep('', 'Fill') . ' %{fugitive#head()}' | |
endif | |
let l:s .= '%=' | |
if a:current | |
let l:s .= crystalline#left_sep('', 'Fill') . ' %{&paste ?"PASTE ":""}%{&spell?"SPELL ":""}' | |
let l:s .= crystalline#left_mode_sep('') | |
endif | |
if a:width > 80 | |
let l:s .= ' %{&ft}[%{&enc}][%{&ffs}] %l/%L %c%V %P ' | |
else | |
let l:s .= ' ' | |
endif | |
return l:s | |
endfunction | |
function! TabLine() | |
let l:vimlabel = has('nvim') ? ' NVIM ' : ' VIM ' | |
return crystalline#bufferline(2, len(l:vimlabel), 1) . '%=%#CrystallineTab# ' . l:vimlabel | |
endfunction | |
let g:crystalline_enable_sep = 1 | |
let g:crystalline_statusline_fn = 'StatusLine' | |
let g:crystalline_tabline_fn = 'TabLine' | |
let g:crystalline_theme = 'dracula' | |
set showtabline=2 | |
set guioptions-=e | |
set laststatus=2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment