Skip to content

Instantly share code, notes, and snippets.

@danhere
Created March 15, 2017 21:08
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 danhere/e3630c5d8ab98132565fd454b64b7acf to your computer and use it in GitHub Desktop.
Save danhere/e3630c5d8ab98132565fd454b64b7acf to your computer and use it in GitHub Desktop.
My vimrc
" Use vim settings, rather then vi settings (much better!)
" This must be first, because it changes other options as a side effect.
set nocompatible
" ==========================================================================
" Plugins
" ==========================================================================
call plug#begin('~/.vim/plugged')
" Utils
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Style
Plug 'bling/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'chriskempson/base16-vim'
Plug 'dracula/vim'
" Syntax
Plug 'pangloss/vim-javascript'
Plug 'scrooloose/syntastic'
Plug 'mattn/emmet-vim'
Plug 'othree/html5.vim'
Plug 'farneman/expression-engine-vim-syntax'
Plug 'cakebaker/scss-syntax.vim'
" Tools
Plug 'alvan/vim-closetag'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-surround'
Plug 'junegunn/vim-easy-align'
Plug 'wincent/command-t'
Plug 'tpope/vim-fugitive'
Plug 'valloric/youcompleteme'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'junegunn/vim-easy-align'
call plug#end()
filetype plugin indent on " enable detection, plugins and indenting in one step
syntax on
" Editing behaviour {{{
set showmode " always show what mode we're currently editing in
set nowrap " don't wrap lines
set tabstop=4 " a tab is four spaces
set softtabstop=4 " when hitting <BS>, pretend like a tab is removed, even if spaces
set expandtab " expand tabs by default (overloadable per file type later)
set shiftwidth=4 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set number " always show line numbers
set showmatch " set show matching parenthesis
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,
" case-sensitive otherwise
set smarttab " insert tabs on the start of a line according to
" shiftwidth, not tabstop
set scrolloff=4 " keep 4 lines off the edges of the screen when scrolling
set virtualedit=all " allow the cursor to go in to "invalid" places
set hlsearch " highlight search terms
set incsearch " show search matches as you type
set gdefault " search/replace "globally" (on a line) by default
set listchars=tab:▸\ ,trail:·,extends:#,nbsp:·
set nolist " don't show invisible characters by default,
" but it is enabled for some file types (see later)
set pastetoggle=<F2> " when in insert mode, press <F2> to go to
" paste mode, where you can paste mass data
" that won't be autoindented
set mouse=a " enable using the mouse if terminal emulator
" supports it (xterm does)
set fileformats="unix,dos,mac"
set formatoptions+=1 " When wrapping paragraphs, don't end lines
" with 1-letter words (looks stupid)
set nrformats= " make <C-a> and <C-x> play well with
" zero-padded numbers (i.e. don't consider
" them octal or hex)
set shortmess+=I " hide the launch screen
set clipboard=unnamed " normal OS clipboard interaction
set autoread " automatically reload files changed outside of Vim
set guifont=Consolas:h20
set linespace=8
if has("gui_running")
" Remove toolbar, left scrollbar and right scrollbar
set guioptions-=T
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
set guifont=Consolas:h20
set linespace=8
else
set bg=dark
endif
colorscheme dracula
let g:closetag_filenames = "*.html,*.xhtml,*.phtml"
nnoremap <D>; <Plug>(easymotion-bd-f)
nmap <Leader>f <Plug>(easymotion-overwin-f)
" Toggle show/hide invisible chars
nnoremap <leader>i :set list!<cr>
" Toggle line numbers
" nnoremap <leader>N :setlocal number!<cr>
" Thanks to Steve Losh for this liberating tip
" See http://stevelosh.com/blog/2010/09/coming-home-to-vim
nnoremap / /\v
vnoremap / /\v
" Speed up scrolling of the viewport slightly
nnoremap <C-e> 2<C-e>
nnoremap <C-y> 2<C-y>
" }}}
" Editor layout {{{
set termencoding=utf-8
set encoding=utf-8
set lazyredraw " don't update the display while executing macros
set laststatus=2 " tell VIM to always put a status line in, even
" if there is only one window
set cmdheight=1 " use a status bar that is 2 rows high
" }}}
" Vim behaviour {{{
set hidden " hide buffers instead of closing them this
" means that the current buffer can be put
" to background without being written; and
" that marks and undo history are preserved
set switchbuf=useopen " reveal already opened files from the
" quickfix window instead of opening new
" buffers
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
if v:version >= 730
set undofile " keep a persistent backup file
set undodir=~/.vim/.undo,~/tmp,/tmp
endif
set nobackup " do not keep backup files, it's 70's style cluttering
set noswapfile " do not write annoying intermediate swap files,
" who did ever restore from swap files anyway?
set directory=~/.vim/.tmp,~/tmp,/tmp
" store swap files in one of these directories
" (in case swapfile is ever turned on)
set viminfo='20,\"80 " read/write a .viminfo file, don't store more
" than 80 lines of registers
set wildmenu " make tab completion for files/buffers act like bash
set wildmode=list:full " show a list when pressing tab and complete
" first full match
set wildignore=*.swp,*.bak,*.pyc,*.class
set title " change the terminal's title
set visualbell " don't beep
set noerrorbells " don't beep
set showcmd " show (partial) command in the last line of the screen
" this also shows visual selection info
set nomodeline " disable mode lines (security measure)
"set ttyfast " always use a fast terminal
set cursorline " underline the current line, for quick orientation
" }}}
" Map Ctrl-f to find
map <C-f> /
" Shortcut mappings {{{
" Since I never use the ; key anyway, this is a real optimization for almost
" all Vim commands, as I don't have to press the Shift key to form chords to
" enter ex mode.
nnoremap ; :
nnoremap <leader>; ;
" Avoid accidental hits of <F1> while aiming for <Esc>
noremap! <F1> <Esc>
nnoremap <leader>Q :q<CR> " Quickly close the current window
nnoremap <leader>q :bd<CR> " Quickly close the current buffer
" Use Q for formatting the current paragraph (or visual selection)
vnoremap Q gq
nnoremap Q gqap
" set breakindent on " keep paragraph indentation when re-wrapping text
" Sort paragraphs
vnoremap <leader>s !sort -f<CR>gv
nnoremap <leader>s vip!sort -f<CR><Esc>
" make p in Visual mode replace the selected text with the yank register
vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>
" Swap implementations of ` and ' jump to markers
" By default, ' jumps to the marked line, ` jumps to the marked line and
" column, so swap them
nnoremap ' `
nnoremap ` '
" Use the damn hjkl keys
noremap <up> <nop>
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
" Remap j and k to act as expected when used on long, wrapped, lines
nnoremap j gj
nnoremap k gk
" Easy window navigation
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" nnoremap <leader>w <C-w>v<C-w>l
" Complete whole filenames/lines with a quicker shortcut key in insert mode
inoremap <C-f> <C-x><C-f>
inoremap <C-l> <C-x><C-l>
" Use ,d (or ,dd or ,dj or 20,dd) to delete a line without adding it to the
" yanked stack (also, in visual mode)
nnoremap <silent> <leader>d "_d
vnoremap <silent> <leader>d "_d
" vnoremap <silent> x "_x TODODODOOo
" Quick yanking to the end of the line
nnoremap Y y$
" YankRing stuff
let g:yankring_history_dir = '$HOME/.vim/.tmp'
nnoremap <leader>r :YRShow<CR>
" Edit the vimrc file
nnoremap <silent> <leader>ev :e $MYVIMRC<CR>
nnoremap <silent> <leader>sv :so $MYVIMRC<CR>
" Clears the search register
nnoremap <silent> <leader>/ :nohlsearch<CR>
" Pull word under cursor into LHS of a substitute (for quick search and
" replace)
nnoremap <leader>z :%s#\<<C-r>=expand("<cword>")<CR>\>#
" Keep search matches in the middle of the window and pulse the line when moving
" to them.
nnoremap n n:call PulseCursorLine()<cr>
nnoremap N N:call PulseCursorLine()<cr>
" Quickly get out of insert mode without your fingers having to leave the
" home row (either use 'jj' or 'jk')
inoremap jj <Esc>
" Quick alignment of text
" nnoremap <leader>al :left<CR>
" nnoremap <leader>ar :right<CR>
" nnoremap <leader>ac :center<CR>
" Jump to matching pairs easily, with Tab
nnoremap <Tab> %
vnoremap <Tab> %
" Folding
nnoremap <Space> za
vnoremap <Space> za
" NERDTree settings {{{
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <leader>m :NERDTreeClose<CR>:NERDTreeFind<CR>
nnoremap <leader>N :NERDTreeToggle<CR>
" Store the bookmarks file
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
" Show the bookmarks table on startup
let NERDTreeShowBookmarks=1
" Show hidden files, too
let NERDTreeShowFiles=1
let NERDTreeShowHidden=1
" Quit on opening files from the tree
let NERDTreeQuitOnOpen=1
" Highlight the selected entry in the tree
let NERDTreeHighlightCursorline=1
" Use a single click to fold/unfold directories and a double click to open
" files
let NERDTreeMouseMode=2
" Don't display these kinds of files
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.py\$class$', '\.obj$',
\ '\.o$', '\.so$', '\.egg$', '^\.git$', '__pycache__', '\.DS_Store' ]
" }}}
" vim-flake8 default configuration
let g:flake8_show_in_gutter=1
" Conflict markers {{{
" highlight conflict markers
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
" shortcut to jump to next conflict marker
nnoremap <silent> <leader>c /^\(<\\|=\\|>\)\{7\}\([^=].\+\)\?$<CR>
" }}}
" Filetype specific handling {{{
" only do this part when compiled with support for autocommands
if has("autocmd")
augroup invisible_chars "{{{
au!
" Show invisible characters in all of these files
autocmd filetype vim setlocal list
autocmd filetype python,rst setlocal list
autocmd filetype ruby setlocal list
autocmd filetype javascript,css setlocal list
augroup end "}}}
augroup vim_files "{{{
au!
" Bind <F1> to show the keyword under cursor
" general help can still be entered manually, with :h
autocmd filetype vim noremap <buffer> <F1> <Esc>:help <C-r><C-w><CR>
autocmd filetype vim noremap! <buffer> <F1> <Esc>:help <C-r><C-w><CR>
augroup end "}}}
augroup js_files "{{{
" Defer to import-sort for sorting JavaScript imports (instead of using Unix sort)
autocmd filetype javascript nnoremap <leader>s :write<cr>mX:!import-sort --overwrite %<cr>:edit!<cr>`X
augroup end " }}}
augroup markdown_files "{{{
au!
autocmd filetype markdown noremap <buffer> <leader>p :w<CR>:!open -a 'Marked 2' %<CR><CR>
augroup end " }}}
augroup css_files "{{{
au!
autocmd filetype css,less setlocal foldmethod=marker foldmarker={,}
augroup end "}}}
augroup javascript_files "{{{
au!
autocmd filetype javascript setlocal expandtab
autocmd filetype javascript setlocal listchars=trail:·,extends:#,nbsp:·
autocmd filetype javascript setlocal foldmethod=marker foldmarker={,}
" Toggling True/False
autocmd filetype javascript nnoremap <silent> <C-t> mmviw:s/true\\|false/\={'true':'false','false':'true'}[submatch(0)]/<CR>`m:nohlsearch<CR>
" Enable insertion of "debugger" statement in JS files
autocmd filetype javascript nnoremap <leader>b Odebugger;<esc>
augroup end "}}}
augroup textile_files "{{{
au!
autocmd filetype textile set tw=78 wrap
" Render YAML front matter inside Textile documents as comments
autocmd filetype textile syntax region frontmatter start=/\%^---$/ end=/^---$/
autocmd filetype textile highlight link frontmatter Comment
augroup end "}}}
augroup git_files "{{{
au!
" Don't remember the last cursor position when editing commit
" messages, always start on line 1
autocmd filetype gitcommit call setpos('.', [0, 1, 1, 0])
augroup end "}}}
endif
" }}}
" Restore cursor position upon reopening files {{{
autocmd BufReadPost *
\ if &filetype != "gitcommit" && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" }}}
" Extra vi-compatibility {{{
" set extra vi-compatible options
set cpoptions+=$ " when changing a line, don't redisplay, but put a '$' at
" the end during the change
set formatoptions-=o " don't start new lines w/ comment leader on pressing 'o'
au filetype vim set formatoptions-=o
" somehow, during vim filetype detection, this gets set
" for vim files, so explicitly unset it again
" }}}
" Ignore common directories
let g:ctrlp_custom_ignore = {
\ 'dir': 'node_modules\|bower_components',
\ }
" Invoke CtrlP, but CommandT style
nnoremap <c-u>p :CtrlP ['~/Sites/']<cr>
nnoremap <leader>. :CtrlPTag<cr>
nnoremap <leader>b :CtrlPBuffer<cr>
" Learn Vim Script the Hard Way Exercises
"noremap - ddp
"noremap _ ddkP
" C-U in insert/normal mode, to uppercase the word under cursor
inoremap <c-u> <esc>viwUea
nnoremap <c-u> viwUe
" Use shift-H and shift-L for move to beginning/end
" nnoremap H 0
" nnoremap L $
" Pulse ------------------------------------------------------------------- {{{
function! PulseCursorLine()
let current_window = winnr()
windo set nocursorline
execute current_window . 'wincmd w'
setlocal cursorline
redir => old_hi
silent execute 'hi CursorLine'
redir END
let old_hi = split(old_hi, '\n')[0]
let old_hi = substitute(old_hi, 'xxx', '', '')
hi CursorLine guibg=#3a3a3a
redraw
sleep 20m
hi CursorLine guibg=#4a4a4a
redraw
sleep 30m
hi CursorLine guibg=#3a3a3a
redraw
sleep 30m
hi CursorLine guibg=#2a2a2a
redraw
sleep 20m
execute 'hi ' . old_hi
windo set cursorline
execute current_window . 'wincmd w'
endfunction
" }}}
" Powerline configuration ------------------------------------------------- {{{
let g:Powerline_symbols = 'compatible'
"let g:Powerline_symbols = 'fancy'
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment