Skip to content

Instantly share code, notes, and snippets.

@dpaez
Forked from tinchoz49/.vimrc
Last active February 16, 2017 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpaez/d2578547e979dab3ce2fa2126766e3c1 to your computer and use it in GitHub Desktop.
Save dpaez/d2578547e979dab3ce2fa2126766e3c1 to your computer and use it in GitHub Desktop.
dk's 🆒 vim config :neckbeard:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer:
" deka
" Based on the Awesome vimrc project by Amir Salihefendic
" https://github.com/amix/vimrc
"
" Sections:
" -> General
" -> VIM user interface
" -> Colors and Fonts
" -> Files and backups
" -> Text, tab and indent related
" -> Visual mode related
" -> Moving around, tabs and buffers
" -> Status line
" -> Editing mappings
" -> vimgrep searching and cope displaying
" -> Spell checking
" -> Misc
" -> Helper functions
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" no vi-compatible
set nocompatible
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')
" Fugitive
Plug 'tpope/vim-fugitive'
" Zencoding ;)
Plug 'mattn/emmet-vim'
" Indent Guides visually
Plug 'nathanaelkane/vim-indent-guides'
" Automatic closing of quotes, parenthesis, brackets, etc
Plug 'Raimondi/delimitMate'
" Better file browser
Plug 'scrooloose/nerdtree'
" nerdtree git plugin
Plug 'Xuyuanp/nerdtree-git-plugin'
" Class/module browser
Plug 'majutsushi/tagbar'
" Airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" CtrlP
Plug 'ctrlpvim/ctrlp.vim'
Plug 'okcompute/vim-ctrlp-session'
" CtrlPtjump
Plug 'ivalkeen/vim-ctrlp-tjump'
" Syntastic
Plug 'vim-syntastic/syntastic', { 'do': 'npm install -g resolve-eslint' }
" multiple cursors/selections
Plug 'terryma/vim-multiple-cursors'
" editorconfig!
Plug 'editorconfig/editorconfig-vim'
" supertab
Plug 'ervandew/supertab'
" css syntax
Plug 'JulesWang/css.vim'
Plug 'ntpeters/vim-better-whitespace'
" handle code comments
Plug 'tpope/vim-commentary'
" Dracula theme
Plug 'dracula/vim'
" base16-vim
Plug 'chriskempson/base16-vim'
" Autoformat
Plug 'Chiel92/vim-autoformat', { 'do': 'npm install -g js-beautify' }
" extra syntax
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
" MD support a la vim
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
Plug 'tpope/vim-markdown'
Plug 'tpope/vim-surround'
Plug 'shime/vim-livedown', { 'do': 'npm install -g livedown' }
" All plugins have been loaded
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugins
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" Fast saving
nmap <leader>w :w!<cr>
" :W sudo saves the file
" (useful for handling the permission-denied error)
command W w !sudo tee % > /dev/null
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" Turn on the WiLd menu
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
set wildignore+=.git\*,.hg\*,.svn\*
endif
"Always show current position and line number
set ruler
set number
" 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
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config)
set lazyredraw
" For regular expressions turn magic on
set magic
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" No annoying sound on errors
set noerrorbells
set novisualbell
" set t_vb=
set tm=500
" Add a bit extra margin to the left
set foldcolumn=1
" Folds
" =====
set foldmethod=indent " Fold based on indent
set foldnestmax=3 " Deepest fold is 3 levels
set nofoldenable " Don't fold by default
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set t_Co=256
if (has("termguicolors"))
set termguicolors
endif
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set background=dark
colorscheme dracula
" Enable syntax highlighting
syntax enable
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
" Use Unix as the standard file type
set ffs=unix,dos,mac
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 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 related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4
" tab length exceptions on some file types
" 1 tab == 2 spaces
autocmd FileType html setlocal shiftwidth=2 tabstop=2 softtabstop=2
" Linebreak on 500 characters
set lbr
set tw=500
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f', '')<CR>
vnoremap <silent> # :call VisualSelection('b', '')<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
map <space> /
map <C-Space> ?
" 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
" Navigate windows with meta+arrows
map <M-Right> <c-w>l
map <M-Left> <c-w>h
map <M-Up> <c-w>k
map <M-Down> <c-w>j
" Insert mode map
imap <M-Right> <ESC><c-w>l
imap <M-Left> <ESC><c-w>h
imap <M-Up> <ESC><c-w>k
imap <M-Down> <ESC><c-w>j
" Close the current buffer
map <leader>bd :Bclose<cr>
" Close all the buffers
map <leader>ba :1,1000 bd!<cr>
" Useful mappings for managing tabs
map tt :tabnew<cr>
map tc :tabclose<cr>
map to :tabonly<cr>
map tm :tabmove
map tn :tabnext<cr>
map tp :tabprevious<cr>
map ts :tabsplit<cr>
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map te :tabedit <c-r>=expand("%:p:h")<cr>/
" Tabs navigation with arrows (Control + Shift + Arrow)
map <C-S-Right> :tabnext<cr>
map <Alt-Right> :tabnext<cr>
map <C-S-Left> :tabprevious<CR>
" insert mode map
imap <C-S-Right> <ESC>:tabnext<CR>
imap <C-S-Left> <ESC>:tabprevious<CR>
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" ctrlPBuffer settings
nnoremap <C-b><C-b> :CtrlPBuffer<CR>
nnoremap <C-b><C-n> :bn<CR>
nnoremap <C-b><C-w> :bw<CR>
nnoremap <C-s><C-s> :CtrlPSession<CR>
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
""""""""""""""""""""""""""""""
" => Markdown writer mode
""""""""""""""""""""""""""""""
let g:goyo_height = '95%'
let g:goyo_width = '81'
let g:vim_markdown_frontmatter=1
let g:markdown_fenced_languages = ['javascript', 'js=javascript', 'json=javascript', 'sh', 'bash=sh']
let g:limelight_conceal_ctermfg = 'gray'
" autocmd! User GoyoEnter GitGutterEnable
autocmd BufNewFile,BufReadPost *.md :Goyo
autocmd FileType mkd set | set autoindent | set colorcolumn=0 | set linebreak | set nonumber | set shiftwidth=4 | set spell | set tabstop=4 | set wrap
map <Leader>g :Goyo<CR>
function! s:goyo_enter()
" silent !tmux resize-pane -t $TMUX_PANE -Z
let b:quitting = 0
let b:quitting_bang = 0
autocmd QuitPre <buffer> let b:quitting = 1
cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
set noshowmode
set noshowcmd
set scrolloff=999
Limelight
endfunction
function! s:goyo_leave()
" silent !tmux resize-pane -t $TMUX_PANE -Z
" Quit Vim if this is the only remaining buffer
if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
if b:quitting_bang
qa!
else
qa
endif
endif
set showmode
set showcmd
set scrolloff=5
Limelight!
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
""""""""""""""""""""""""""""""
" => Syntastic
""""""""""""""""""""""""""""""
nnoremap <Leader>l :SyntasticCheck<CR>
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_loc_list_height = 5
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 1
let g:syntastic_javascript_eslint_exe = 'eslint --quiet'
let g:syntastic_javascript_checkers = ['eslint']
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Format the status line
"set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Delete trailing white space on save, useful for Python and CoffeeScript ;)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
autocmd BufWrite *.coffee :call DeleteTrailingWS()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
" Toggle paste mode on and off
map <leader>pp :setlocal paste!<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
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 == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.' . a:extra_filter)
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE ON '
endif
return ''
endfunction
" Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ZenCoding
let g:user_zen_mode='a'
let g:user_emmet_leader_key='<C-Y>'
" Tagbar
" toggle tagbar display
map <F4> :TagbarToggle<CR>
" autofocus on tagbar open
let g:tagbar_autofocus = 1
" Nerd Tree
map <leader>n :NERDTreeToggle<cr>
map <leader>nb :NERDTreeFromBookmark
map <leader>nf :NERDTreeFind<cr>
" do NOT show these file types
let NERDTreeIgnore = ['\.pyc$', '\.pyo$']
" Airline
let g:airline_powerline_fonts = 1
let g:airline_theme = 'bubblegum'
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#tabline#enabled = 1
" CTRL-P
" disable open in current dir
let g:ctrlp_working_path_mode = 0
map <leader>ff :CtrlP<cr>
map <c-b> :CtrlPBuffer<cr>
let g:ctrlp_max_height = 20
let g:ctrlp_custom_ignore = 'node_modules\|^\.DS_Store\|^\.git\|^\.coffee'
" CtrlPTjump
nnoremap <S-Space> :CtrlPtjump<cr>
vnoremap <S-Space> :CtrlPtjumpVisual<cr>
" Indent guides
let g:indent_guides_guide_size = 1
let g:indent_guides_enable_on_vim_startup = 1
hi IndentGuidesOdd ctermbg=black
hi IndentGuidesEven ctermbg=darkgrey
hi CursorLine guibg=#303000 ctermbg=234i
set cursorline
" Autoformat
nnoremap <C-f> :Autoformat<CR>
" fugitive options
set diffopt+=vertical
" Highlight ES6 template strings
let g:jsx_ext_required = 0
" SuperTab
let g:SuperTabLongestHighlight = 1
let g:SuperTabClosePreviewOnPopupClose = 1
let g:SuperTabLongestEnhanced = 1
let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment