Skip to content

Instantly share code, notes, and snippets.

@teki
Last active January 2, 2016 18:38
Show Gist options
  • Save teki/8344485 to your computer and use it in GitHub Desktop.
Save teki/8344485 to your computer and use it in GitHub Desktop.
vimrc
set nocompatible
" load plugins if they are available
let s:myvimrc = expand($MBE . "/vim/vimrc")
let s:hasplugins = filereadable(s:myvimrc)
if s:hasplugins
filetype on
filetype off
set rtp+=$MBE . "/vim/bundle/vundle"
call vundle#rc($MBE . "/vim/bundle")
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
" BundleInstall
Bundle 'vim-scripts/L9'
Bundle 'vim-scripts/Mark--Karkat'
Bundle 'vim-scripts/YankRing.vim'
Bundle 'kien/ctrlp.vim'
Bundle 'bling/vim-airline'
Bundle 'airblade/vim-gitgutter'
Bundle 'scrooloose/syntastic.git'
Bundle 'sheerun/vim-polyglot'
Bundle 'vim-scripts/a.vim'
Bundle 'Valloric/YouCompleteMe'
"Bundle 'jdonaldson/vaxe'
Bundle 'abudden/TagHighlight'
Bundle 'altercation/vim-colors-solarized'
"Bundle 'vim-scripts/Colour-Sampler-Pack'
"Bundle 'ScrollColors'
set background=dark
colorscheme solarized
else
let s:myvimrc = expand("~/.vimrc")
endif
function! s:EditMyVimrc()
execute ":e " s:myvimrc
endfunction
if !exists("*s:ReloadMyVimrc")
function s:ReloadMyVimrc()
execute ":source " s:myvimrc
endfunction
endif
filetype plugin indent on
syntax on
syn sync minlines=1000
" file
set autowriteall
set autoread
set nobackup
set noswapfile
if has("persistent_undo")
set undofile
set undodir=$HOME/.vimundo
set undolevels=1000
set undoreload=10000
endif
set hidden
" edit
set backspace=indent,eol,start
set pastetoggle=<F5>
set clipboard=unnamed
set modelines=0
set encoding=utf-8
set cindent
set cinoptions=l1,c4,(s,U1,w1,m1,j1
set cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set shiftround
set virtualedit=block
set nostartofline
set nojoinspaces
set lazyredraw
set gdefault
au FileType javascript setl tabstop=2 shiftwidth=2
if !s:hasplugins
function! MyStatusLine()
let s = '%9* %* ' " pad the edges for better vsplit separation
let s .= '%%%n '
if bufname('') != '' " why is this such a pain in the ass?
let s .= "%{ pathshorten(fnamemodify(expand('%F'), ':~:.')) }" " short-hand path of of the current buffer
else
let s .= '%f' " an empty filename doesn't make it through the above filters
endif
let s .= '%m' " modified
let s .= '%r' " read-only
let s .= '%w' " preview window
let s .= ' %<' " start truncating from here if the window gets too small
if bufname('#') != '' " if there's an alternate buffer, display the name
let s .= '(#' . bufnr('#') . ' '
let s .= fnamemodify(bufname('#'), ':t')
let s .= ')'
endif
let s .= ' %y' " file-type
let s .= ' <'
let s .= '%{&fileencoding}' " fileencoding
let s .= ',%{&fileformat}' " line-ending type
let s .= '>'
let s .= '%a' " (args of total)
let s .= '%=' " separate right- from left-aligned
if exists("*VimBuddy")
let s .= '%{VimBuddy()} ' " Vimming will never be lonely again.
endif
let s .= '%l' " current line number
let s .= ',%c' " column number
let s .= '%V' " virtual column number (doesn't count indentation)
let s .= ' of %L' " total line numbers
let s .= ' %P' " Percentage through file
return s
endfunction
set statusline=%!MyStatusLine()
endif
set laststatus=2
set scrolloff=3
set number
set showmode
set showcmd
set cmdheight=2
set laststatus=2
set viminfo='100,f1,:100,/100
set visualbell
set cursorline
set ttyfast
set wildmenu
set wildmode=longest:full,list:longest
" search
set incsearch
set hlsearch
set ignorecase
set smartcase
set showmatch
set path=.,**
" search with proper regexp
"nnoremap / /\v
"vnoremap / /\v
" prog
"set tags=./tags,tags,~/trunk.gitt/tags
set tags=./tags,tags
set grepprg=met\ -g
let filetype_m='objc'
" automatic config reload
autocmd! bufwritepost vimrc :call <SID>ReloadMyVimrc()
" let's make W do the same as w
cnoreabbrev <expr> W getcmdtype()==':'&&getcmdline()=~#'^W'?'w':'W'
" error window, next error, prev error
nmap <F8> :cn<cr>zz
nmap <S-F8> :cp<cr>zz
nmap <C-F8> :cw<cr>zz
" save file
map <C-s> :w<CR>
imap <C-s> <C-s>i
" move a logical line up
map j gj
map k gk
map <Down> gj
map <Up> gk
" copy/paste, undor redo
map <C-c> yy
vmap <C-c> y
map <C-v> p
map <C-z> :u<cr>
map <C-y> :redo<cr>
imap <C-z> <C-z>i
imap <C-y> <C-r>i
imap <C-c> <esc>yy
imap <C-v> <esc>pa
imap <C-z> <esc>ua
imap <C-r> <esc>r
" split line
nmap K i<cr><esc>==
" home
imap <Home> <esc>^i
nmap <Home> <esc>^
" replace word with yank buffer
nnoremap S "_diwP
" delete /skip yank buffer/
nnoremap dD "_dd
" fix page down and page up
nnoremap <silent> <PageUp> <C-U><C-U>
vnoremap <silent> <PageUp> <C-U><C-U>
inoremap <silent> <PageUp> <C-\><C-O><C-U><C-\><C-O><C-U>
nnoremap <silent> <PageDown> <C-D><C-D>
vnoremap <silent> <PageDown> <C-D><C-D>
inoremap <silent> <PageDown> <C-\><C-O><C-D><C-\><C-O><C-D>
" alternate between the last buffers
nmap <C-e> :b#<CR>
" buffer list (ctrlp replaces it)
nmap <C-Tab> :ls<cr>:b<space>
let mapleader = ","
" clear highlights, diff, quikc views
nmap <leader><Space> :noh<cr>:ccl<cr>:pc<cr>:diffoff<cr>
" edit vimrc
nmap <leader>0 :call <SID>EditMyVimrc()<cr>
" reindent block
nmap <leader>= mg[[=i{`gzz
" open header
nmap <leader>, :A<cr>
set listchars=tab:>-,trail:»,precedes:<,extends:>,eol:¶
" Highlight problem lines: more than 80 chars, trailing spaces, only whitespace
nnoremap <silent> <leader>x
\ :set nolist!<CR>:set nolist?<CR>
\ :if exists('w:long_line_match') <Bar>
\ silent! call matchdelete(w:long_line_match) <Bar>
\ unlet w:long_line_match <Bar>
\ elseif &textwidth > 0 <Bar>
\ let w:long_line_match = matchadd('ErrorMsg', '\%>'.&tw.'v.\+', -1) <Bar>
\ else <Bar>
\ let w:long_line_match = matchadd('ErrorMsg', '\%>80v.\+', -1) <Bar>
\ endif<CR>
" platform
fun! IsWin()
if has('win32')
return 1
endif
return 0
endfun
fun! IsMac()
if has('mac')
return 1
endif
return 0
endfun
fun! IsLinux()
if has('unix')
return 1
endif
return 0
endfun
fun! IsPosix()
if IsMac() || IsLinux()
return 1
endif
return 0
endfun
" markdown
augroup mkd
autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:&gt;
augroup END
" Remember last position in file
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" select pasted text
nnoremap <leader>v V`]
" handy things for grepping
cno ,c %:h/*
cno ,g cs find e
" Visual mode related
" In visual mode when you press * or # to search for the current selection
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>
" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSearch('gv')<CR>
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
" From an idea by Michael Naumann
function! VisualSearch(direction) 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 . '/' . ' **/*.')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
set diffopt+=vertical
" gui
if IsWin()
set guifont=Consolas:h10
elseif IsMac()
set guifont=Monaco:h12
else
set guifont=DejaVu\ Sans\ Mono\ 10
endif
set guioptions-=T
if !s:hasplugins
function! Smart_TabComplete()
let line = getline('.') " current line
let substr = strpart(line, -1, col('.')+1) " from the start of the current
" line to one character right
" of the cursor
let substr = matchstr(substr, "[^ \t]*$") " word till cursor
if (strlen(substr)==0) " nothing to match on empty string
return "\<tab>"
endif
let has_period = match(substr, '\.') != -1 " position of period, if any
let has_slash = match(substr, '\/') != -1 " position of slash, if any
if (!has_period && !has_slash)
return "\<C-X>\<C-P>" " existing text matching
elseif ( has_slash )
return "\<C-X>\<C-F>" " file matching
else
return "\<C-X>\<C-O>" " plugin matching
endif
endfunction
inoremap <tab> <c-r>=Smart_TabComplete()<CR>
endif
"""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""
" plugins
"""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""
if !s:hasplugins
finish
endif
let g:syntastic_javascript_checkers=['jshint']
let g:syntastic_c_checkers=['make']
let g:syntastic_cpp_checkers=['ycm']
" taghighlight
map <leader>u :UpdateTypesFileOnly<cr>
" fuzzy finder
"nmap <C-tab> :FufBuffer<cr>
"nmap <leader>p :FufTaggedFile<cr>
"nmap <leader>f :FufFileWithCurrentBufferDir<cr>
"nmap <leader>t :FufTag<cr>
"nmap <leader>l :FufLine<cr>
"let g:fuf_reuseWindow = 0
"let g:fuf_abbrevMap = { "^all:" : [ "**/", ], }
" ctrlp
let g:ctrlp_match_window_bottom = 0
let g:ctrlp_match_window_reversed = 0
nmap <C-Tab> :CtrlPMRU<cr>
nmap <leader>t :CtrlPTag<cr>
let g:ctrlp_working_path_mode = 'a'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files']
" yankring
let g:yankring_replace_n_pkey = ''
let g:yankring_replace_n_nkey = ''
"nmap <M-v> :YRShow<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment