Skip to content

Instantly share code, notes, and snippets.

@hlidotbe
Created May 30, 2013 08:49
Show Gist options
  • Save hlidotbe/5676597 to your computer and use it in GitHub Desktop.
Save hlidotbe/5676597 to your computer and use it in GitHub Desktop.
vimrc
""
"" Before plugins
""
set shell=/bin/bash
let mapleader = "`"
""
"" Basic Setup
""
set nocompatible " Use vim, no vi defaults
set number " Show line numbers
set ruler " Show line and column number
syntax enable " Turn on syntax highlighting allowing local overrides
set encoding=utf-8 " Set default encoding to UTF-8
set laststatus=2
set showbreak=↪
set textwidth=120
set colorcolumn=+1
""
"" Whitespace
""
set nowrap " don't wrap lines
set tabstop=2 " a tab is two spaces
set shiftwidth=2 " an autoindent (with <<) is two spaces
set expandtab " use spaces, not tabs
set list " Show invisible characters
set backspace=indent,eol,start " backspace through everything in insert mode
" List chars
"
set listchars="" " Reset the listchars
set listchars=tab:\ \ " a tab should display as " ", trailing whitespace as "."
set listchars+=trail:. " show trailing spaces as dots
set listchars+=extends:> " The character to show in the last column when wrap is
" off and the line continues beyond the right of the screen
set listchars+=precedes:< " The character to show in the last column when wrap is
""
"" Searching
""
set hlsearch " highlight matches
set incsearch " incremental searching
""
"" Wild settings
""
" TODO: Investigate the precise meaning of these settings
" set wildmode=list:longest,list:full
" Disable output and VCS files
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
" Disable archive files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Ignore bundler and sass cache
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Disable temp and backup files
set wildignore+=*.swp,*~,._*
""
"" Backup and swap files
""
set backupdir=~/.vim/_backup/ " where to put backup files.
set directory=~/.vim/_temp/ " where to put swap files.
filetype plugin indent on
""
"" NERDTree
""
let NERDTreeHijackNetrw = 1
let NERDTreeQuitOnOpen = 1
let NERDTreeMinimalUI = 1
""
"" Delimitmate
""
let delimitMate_expand_space=1
let delimitMate_expand_cr=1
let g:UltiSnipsExpandTrigger="<C-l>"
let g:UltiSnipsJumpForwardTrigger="<C-l>"
let g:UltiSnipsJumpBackwardTrigger="<C-A-l>"
let g:ycm_register_as_syntastic_checker=0
call pathogen#infect()
""
"" After plugins
""
""
"" General Mappings (Normal, Visual, Operator-pending)
""
" use :w!! to write to a file using sudo if you forgot to 'sudo vim file'
" (it will prompt for sudo password when writing)
cmap w!! %!sudo tee > /dev/null %
" Toggle paste mode
nmap <silent> <F4> :set invpaste<CR>:set paste?<CR>
imap <silent> <F4> <ESC>:set invpaste<CR>:set paste?<CR>
" format the entire file
nmap <leader>fef ggVG=
" upper/lower word
nmap <leader>u mQviwU`Q
nmap <leader>l mQviwu`Q
" upper/lower first char of word
nmap <leader>U mQgewvU`Q
nmap <leader>L mQgewvu`Q
" cd to the directory containing the file in the buffer
nmap <silent> <leader>cd :lcd %:h<CR>
" Create the directory containing the file in the buffer
nmap <silent> <leader>md :!mkdir -p %:p:h<CR>
" Some helpers to edit mode
" http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
" Swap two words
nmap <silent> gw :s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR>`'
" Underline the current line with '='
nmap <silent> <leader>ul :t.\|s/./=/g\|:nohls<cr>
" set text wrapping toggles
nmap <silent> <leader>tw :set invwrap<CR>:set wrap?<CR>
" find merge conflict markers
nmap <silent> <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
" Map the arrow keys to be based on display lines, not physical lines
map <Down> gj
map <Up> gk
" Toggle hlsearch with <leader>hs
nmap <leader>hs :set hlsearch! hlsearch?<CR>
" Adjust viewports to the same size
map <Leader>= <C-w>=
" Map command-[ and command-] to indenting or outdenting
" while keeping the original selection in visual mode
vmap <A-]> >gv
vmap <A-[> <gv
nmap <A-]> >>
nmap <A-[> <<
omap <A-]> >>
omap <A-[> <<
imap <A-]> <Esc>>>i
imap <A-[> <Esc><<i
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" Easier split navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
set splitbelow
set splitright
""
"" Command-Line Mappings
""
" Insert the current directory into a command-line path
cmap <C-P> <C-R>=expand("%:p:h") . "/"<CR>
""
"" Zencoding config
""
let g:user_zen_expandabbr_key = '<c-e>'
let g:user_zen_settings = {'indentation' : ' '}
" Colorscheme
"set t_Co=256
set background=dark
" solarized options
"let g:solarized_termcolors = 256
"let g:solarized_visibility = "high"
"let g:solarized_contrast = "high"
colors solarized
" CTRL-P config
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$\|build$\|cache$\|tmp$',
\ 'file': '\.png$\|\.jpg$\|\.gif$|\.ico$\|^\.DS_Store$'
\ }
" CTAGS config
let g:tagbar_ctags_bin = '/usr/local/bin/ctags'
let g:tagbar_autoclose = 1
let g:tagbar_autofocus = 1
nnoremap <silent> <F8> :TagbarToggle<CR>
set tags+=./tags;
" NERDTree
let g:NERDTreeIgnore = ['\~$', '.*\.pyc$']
map <Leader>n :NERDTreeToggle<CR>
" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
let explicitDirectory = isdirectory(a:directory)
let directory = explicitDirectory || empty(a:directory)
if explicitDirectory
exe "cd " . fnameescape(a:directory)
endif
"" Allows reading from stdin
"" ex: git diff | mvim -R -
if strlen(a:directory) == 0
return
endif
if directory
NERDTree
wincmd p
bd
endif
if explicitDirectory
wincmd p
endif
endfunction
"augroup AuNERDTreeCmd
"autocmd AuNERDTreeCmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
set so=23
function! NeatFoldText() "{{{2
let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{{\d*\s*', '', 'g') . ' '
let lines_count = v:foldend - v:foldstart + 1
let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |'
let foldchar = '·'
let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
let foldtextend = lines_count_text . repeat(foldchar, 8)
let length = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g'))
return foldtextstart . repeat(foldchar, winwidth(0)-length) . foldtextend
endfunction
set foldtext=NeatFoldText()
" }}}2
set foldmethod=marker
set wildignore+=*.png,*.jpg,*.gif,*.ico,.DS_Store
"let g:syntastic_disabled_filetypes = ['less']
"let g:syntastic_enable_signs=1
"let g:syntastic_quiet_warnings=1
let g:indent_guides_guide_size=1
noremap <Leader>s :update<CR>
noremap <Leader>h :nohl<CR>
noremap <Space> za
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
map <Leader>trim :%s/\s\+$//g<CR>
nmap <Leader>L= :Tabularize /=<CR>
vmap <Leader>L= :Tabularize /=<CR>
nmap <Leader>L: :Tabularize /:<CR>
vmap <Leader>L: :Tabularize /:<CR>
nmap <d-[> >>
nmap <d-]> <<
vmap <d-[> <gv
vmap <d-]> >gv
" relative number
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
nnoremap <C-n> :call NumberToggle()<cr>
set clipboard=unnamed
set statusline=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
map <C-S-r> :NERDTreeFind<CR>
set timeoutlen=500
set ttimeoutlen=100
map <C-/> :NERDCommenterToggle<CR>
imap <C-/> <Esc>:NERDCommenterToggle<CR>i
inoremap <C-g>n <C-R>=delimitMate#JumpAny("\<C-g>n")<CR>
nmap <Left> <<
nmap <Right> >>
vmap <Left> <gv
vmap <Right> >gv
nmap <Up> [e
nmap <Down> ]e
vmap <Up> [egv
vmap <Down> ]egv
map <Leader>f :Ack
map <Leader>e :!elfinder -x "html, ctp, erb" -s
nnoremap - :Switch<cr>
map <F12> :!ctags -R --exclude=.git --exclude=logs --exclude=doc .<CR>
au BufRead,BufNewFile *.rb setlocal tags+=~/.vim/tags/ruby_and_gems
"let g:ackprg = 'ag --nogroup --nocolor --column'
" Search Dash for word under cursor
function! SearchDash()
let s:browser = "/usr/bin/open"
let s:wordUnderCursor = expand("<cword>")
let s:url = "dash://".s:wordUnderCursor
let s:cmd ="silent ! " . s:browser . " " . s:url
execute s:cmd
redraw!
endfunction
map <leader>da :call SearchDash()<CR>
"" Status line super config
"" statusline setup
"set statusline =%#identifier#
"set statusline+=[%t] "tail of the filename
"set statusline+=%*
""display a warning if fileformat isnt unix
"set statusline+=%#warningmsg#
"set statusline+=%{&ff!='unix'?'['.&ff.']':''}
"set statusline+=%*
""display a warning if file encoding isnt utf-8
"set statusline+=%#warningmsg#
"set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
"set statusline+=%*
"set statusline+=%h "help file flag
"set statusline+=%y "filetype
""read only flag
"set statusline+=%#identifier#
"set statusline+=%r
"set statusline+=%*
""modified flag
"set statusline+=%#identifier#
"set statusline+=%m
"set statusline+=%*
""display a warning if &et is wrong, or we have mixed-indenting
"set statusline+=%#error#
"set statusline+=%{StatuslineTabWarning()}
"set statusline+=%*
"set statusline+=%{StatuslineTrailingSpaceWarning()}
"set statusline+=%{StatuslineLongLineWarning()}
""set statusline+=%#warningmsg#
""set statusline+=%{SyntasticStatuslineFlag()}
""set statusline+=%*
""display a warning if &paste is set
"set statusline+=%#error#
"set statusline+=%{&paste?'[paste]':''}
"set statusline+=%*
"set statusline+=%= "left/right separator
"set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
"set statusline+=%c, "cursor column
"set statusline+=%l/%L "cursor line/total lines
"set statusline+=\ %P "percent through file
"set laststatus=2
""recalculate the trailing whitespace warning when idle, and after saving
"autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
""return '[\s]' if trailing white space is detected
""return '' otherwise
"function! StatuslineTrailingSpaceWarning()
"if !exists("b:statusline_trailing_space_warning")
"if !&modifiable
"let b:statusline_trailing_space_warning = ''
"return b:statusline_trailing_space_warning
"endif
"if search('\s\+$', 'nw') != 0
"let b:statusline_trailing_space_warning = '[\s]'
"else
"let b:statusline_trailing_space_warning = ''
"endif
"endif
"return b:statusline_trailing_space_warning
"endfunction
""return the syntax highlight group under the cursor ''
"function! StatuslineCurrentHighlight()
"let name = synIDattr(synID(line('.'),col('.'),1),'name')
"if name == ''
"return ''
"else
"return '[' . name . ']'
"endif
"endfunction
""recalculate the tab warning flag when idle and after writing
"autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
""return '[&et]' if &et is set wrong
""return '[mixed-indenting]' if spaces and tabs are used to indent
""return an empty string if everything is fine
"function! StatuslineTabWarning()
"if !exists("b:statusline_tab_warning")
"let b:statusline_tab_warning = ''
"if !&modifiable
"return b:statusline_tab_warning
"endif
"let tabs = search('^\t', 'nw') != 0
""find spaces that arent used as alignment in the first indent column
"let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0
"if tabs && spaces
"let b:statusline_tab_warning = '[mixed-indenting]'
"elseif (spaces && !&et) || (tabs && &et)
"let b:statusline_tab_warning = '[&et]'
"endif
"endif
"return b:statusline_tab_warning
"endfunction
""recalculate the long line warning when idle and after saving
"autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
""return a warning for "long lines" where "long" is either &textwidth or 80 (if
""no &textwidth is set)
""
""return '' if no long lines
""return '[#x,my,$z] if long lines are found, were x is the number of long
""lines, y is the median length of the long lines and z is the length of the
""longest line
"function! StatuslineLongLineWarning()
"if !exists("b:statusline_long_line_warning")
"if !&modifiable
"let b:statusline_long_line_warning = ''
"return b:statusline_long_line_warning
"endif
"let long_line_lens = s:LongLines()
"if len(long_line_lens) > 0
"let b:statusline_long_line_warning = "[" .
"\ '#' . len(long_line_lens) . "," .
"\ 'm' . s:Median(long_line_lens) . "," .
"\ '$' . max(long_line_lens) . "]"
"else
"let b:statusline_long_line_warning = ""
"endif
"endif
"return b:statusline_long_line_warning
"endfunction
""return a list containing the lengths of the long lines in this buffer
"function! s:LongLines()
"let threshold = (&tw ? &tw : 80)
"let spaces = repeat(" ", &ts)
"let line_lens = map(getline(1,'$'), 'len(substitute(v:val, "\\t", spaces, "g"))')
"return filter(line_lens, 'v:val > threshold')
"endfunction
""find the median of the given array of numbers
"function! s:Median(nums)
"let nums = sort(a:nums)
"let l = len(nums)
"if l % 2 == 1
"let i = (l-1) / 2
"return nums[i]
"else
"return (nums[l/2] + nums[(l/2)-1]) / 2
"endif
"endfunction
"Ghetto Powerline
let g:last_mode = ""
function! Mode()
let l:mode = mode()
if l:mode !=# g:last_mode "Mode change
let g:last_mode = l:mode
if mode ==# "n" | hi User2 ctermfg=28 ctermbg=22 cterm=bold | hi User3 ctermfg=22 ctermbg=236
elseif mode ==# "i" | hi User2 ctermfg=23 ctermbg=231 cterm=bold | hi User3 ctermfg=231 ctermbg=236
elseif mode ==# "R" | hi User2 ctermfg=231 ctermbg=160 cterm=bold | hi User3 ctermfg=160 ctermbg=236
elseif mode ==? "v" | hi User2 ctermfg=160 ctermbg=208 cterm=bold | hi User3 ctermfg=208 ctermbg=236
elseif mode ==# "^V" | hi User2 ctermfg=160 ctermbg=208 cterm=bold | hi User3 ctermfg=208 ctermbg=236
endif
endif
if mode ==# "n" | return " NORMAL "
elseif mode ==# "i" | return " INSERT "
elseif mode ==# "R" | return " REPLACE "
elseif mode ==# "v" | return " VISUAL "
elseif mode ==# "V" | return " V·LINE "
elseif mode ==# "^V" | return " V·BLOCK "
else | return l:mode
endif
endfunc
hi link User1 Statusline
hi Statusline cterm=NONE
hi User1 ctermfg=231 ctermbg=236 cterm=NONE
hi User4 ctermfg=238 ctermbg=236 cterm=bold
hi User5 ctermfg=76 ctermbg=236 cterm=bold
hi User6 ctermfg=196 ctermbg=236 cterm=bold
set laststatus=2 "Always show statusline
set statusline=%2*%{Mode()}%3*%1*%=%{&enc}\ ⮃\ %{&ff}\ ⮃\ [%5*%{tolower(&ft)}%1*
set statusline+=,%6*%{&mod?'+':''}%1*%{&mod?'':'-'}
set statusline+=%{&ro?',':''}%6*%{&ro?'⭤':''}%1*]\ [⭡\ %03l:%4*%03v%1*]
autocmd CursorMovedI * if pumvisible() == 0|silent! pclose|endif
autocmd InsertLeave * if pumvisible() == 0|silent! pclose|endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment