Skip to content

Instantly share code, notes, and snippets.

@ramlev
Created January 15, 2012 19:52
Show Gist options
  • Save ramlev/1616985 to your computer and use it in GitHub Desktop.
Save ramlev/1616985 to your computer and use it in GitHub Desktop.
Vim configuration file.
set nocompatible
filetype off " force reloading after pathogen is loaded
" Use pathogen to easily modify the runtime path to include all
" plugins under the ~/.vim/bundle directory
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
filetype plugin indent on " enable detection, plugins and indenting in one step
set mouse=a " use mouse gestures
let mapleader = "," " Change mapleader to ,
set number " always show line numbers
set ruler
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%)
syntax on
set visualbell " dont beep
set noerrorbells " dont beep
" Status bar
set laststatus=2 " tell VIM to always put a status line in, even if there is only one window
set cmdheight=2 " use a status bar that is towo rows high
" Set encoding
set encoding=utf-8
set termencoding=utf-8
" Whitespace stuff
set wrap " wrap lines
set tabstop=2 " a tab is two spaces
set backspace=indent,eol,start " allow backspacing over everything in insertmode
set autoindent " always set autoindenting on
set copyindent " copy the previus indentation on autoindenting
set shiftwidth=2 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with and '
set showmatch " show matching parenthesis
set smarttab " insert tabs on the start of a line according to shiftwidth, not tabstop
set softtabstop=2 " when hitting <BS>, pretend like a tab is removed, even if spaces
set expandtab " expand tabs by default (overloadable per file type later)
set list listchars=tab:\ \ ,trail:·
set title " change the terminals title
"vertical/horizontal scroll off settings
set scrolloff=4 " keep four lines off the edges of the screen when scrolling
" set virtualedit=all " allow the cursor to go in to "invalid" places
set sidescrolloff=7
set sidescroll=1
set showmode " Always show what mode we're currently editing in.
set showcmd
set hidden
set wildmenu
set cursorline
set ttyfast
" Searching
set hlsearch " highlight searchterms
set incsearch " show search matches as you type
set ignorecase "ignore case when searching
set smartcase " ignore case if search pattern is all lowercase case-sensitive otherwise
" Backup files
set nobackup
set nowritebackup
set noswapfile
" Tab completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc
" Enable syntastic syntax checking
let g:syntastic_enable_signs=1
let g:syntastic_auto_jump=0
let g:syntastic_phpcs_conf='--standard=DrupalCodingStandard'
" Check php files for errors
set makeprg=php\ -l\ %
set errorformat=%m\ in\ %f\ on\ line\ %l
" Check javascript files for errors
au BufWriteCmd *.js JSHint
" Map <CTRL>-P to check the file for syntax
:noremap <C-P> :call PHPsynCHK()<CR>
" CTRLP
let g:ctrlp_working_path_mode = 0
nmap <Leader>p :CtrlPBuffer<CR>
nmap <Leader>P :CtrlPMRU<CR>
map <F8> :!/usr/local/bin/ctags -R --tag-relative=yes --langmap=php:.profile.engine.inc.module.theme.php --php-kinds=cdfi --languages=php --recurse<CR>
" Tagbar
nmap <Leader>l ::TagbarClose<CR>:TagbarToggle<CR>
nmap <Leader>L :TagbarClose<CR>
map <Leader>t :vsplit <CR>:exec("tag ".expand("<cword>"))<CR>
map <Leader>T :exec("tag ".expand("<cword>"))<CR>
" Gundo.vim
nnoremap <Leader>u :GundoToggle<CR>
" Without setting this, ZoomWin restores windows in a way that causes
" equalalways behavior to be triggered the next time CommandT is used.
" This is likely a bludgeon to solve some other issue, but it works
set noequalalways
nnoremap <Leader>W :%s/\s\+$//<cr>
nnoremap <Leader>M :%s/
//g<cr>
" reselect text that was just pasted with ,v
nnoremap <leader>v V`]
" buffergator
nnoremap <Leader>B :BuffergatorToggle<cr>
" Command-T configuration
let g:CommandTMaxHeight=20
" NERDTree configuration
let NERDTreeIgnore=['\.rbc$', '\~$']
let NERDTreeShowFiles=1 " Show files
let NERDTreeShowHidden=1 " Show hidden files as well
let NERDTreeQuitOnOpen=0 " Quit on opening files from the tree
let NERDTreeHighlightCursorline=1 " Highlight the selected entry in the tree
let g:NERDTreeWinSize=40
nmap <Leader>n :NERDTreeClose<CR>:NERDTreeToggle<CR>
nmap <Leader>m :NERDTreeClose<CR>:NERDTreeFind<CR>
nmap <Leader>N :NERDTreeClose<CR>
autocmd FocusGained * call s:UpdateNERDTree()
" ZoomWin configuration
map <Leader><Leader> :ZoomWin<CR>
" CTags
map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
" Opens an edit command with the path of the currently edited file filled in
" Normal mode: <Leader>e
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: <Leader>t
map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
" Unimpaired configuration
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" Use modeline overrides
set modeline
set modelines=10
" Buffers
nnoremap <leader><LEFT> :bp<cr>
nnoremap <leader><RIGHT> :bn<cr>
" PHP
let php_sql_query=1
let php_htmlInStrings=1
let php_noShortTags=1
let php_folding=0
set omnifunc=phpcomplete#CompletePHP
if has("autocmd")
" Auto source .vimrc file on save
"autocmd bufwritepost .vimrc source $MYVIMRC
autocmd BufWritePost *.js JSHint! " Verify javascript files through jshint on save.
" Drupal *.module and *.install files.
augroup module
autocmd BufRead,BufNewFile *.module set filetype=php
autocmd BufRead,BufNewFile *.inc set filetype=php
autocmd BufRead,BufNewFile *.install set filetype=php
autocmd BufRead,BufNewFile *.test set filetype=php
autocmd BufRead,BufNewFile *.vcl :set ft=vcl
augroup END
endif
autocmd BufRead vhosts.conf set filetype=nginx
autocmd BufRead nginx.conf set filetype=nginx
" Project Tree
" Show NERDTree on startup
autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
if has("gui_running")
" Command-Return for fullscreen
macmenu Window.Toggle\ Full\ Screen\ Mode key=<D-CR>
set t_Co=256
set guifont=Droid\ Sans\ Mono:h12
colorscheme github
set fuoptions=maxhorz,maxvert
set transparency=5
" Remove toolbar, left scrollbar and right scrollbar
set guioptions=aAce
set guioptions-=T
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
else
set bg=dark
colorscheme desert256
endif
"statusline setup
set statusline=%n:%f "tail of the filename
"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
set statusline+=%r "read only flag
set statusline+=%m "modified flag
"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+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
"display a warning if &paste is set
set statusline+=%#error#
set statusline+=%{&paste?'[paste]':''}
set statusline+=%*
set statusline+=%{fugitive#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
"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 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 tabs = search('^\t', 'nw') != 0
let spaces = search('^ ', 'nw') != 0
if tabs && spaces
let b:statusline_tab_warning = '[mixed-indenting]'
elseif (spaces && !&et) || (tabs && &et)
let b:statusline_tab_warning = '[&et]'
else
let b:statusline_tab_warning = ''
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
"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
" Close all open buffers on entering a window if the only
" buffer that's left is the NERDTree buffer
function s:CloseIfOnlyNerdTreeLeft()
if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1
if winnr("$") == 1
q
endif
endif
endif
endfunction
" 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 " . a:directory
endif
if directory
NERDTree
wincmd p
bd
endif
if explicitDirectory
wincmd p
endif
endfunction
" NERDTree utility function
function s:UpdateNERDTree(...)
let stay = 0
if(exists("a:1"))
let stay = a:1
end
if exists("t:NERDTreeBufName")
let nr = bufwinnr(t:NERDTreeBufName)
if nr != -1
exe nr . "wincmd w"
exe substitute(mapcheck("R"), "<CR>", "", "")
if !stay
wincmd p
end
endif
endif
if exists(":CommandTFlush") == 2
CommandTFlush
endif
endfunction
" Utility functions to create file commands
function s:CommandCabbr(abbreviation, expansion)
execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
endfunction
function s:FileCommand(name, ...)
if exists("a:1")
let funcname = a:1
else
let funcname = a:name
endif
execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
endfunction
function s:DefineCommand(name, destination)
call s:FileCommand(a:destination)
call s:CommandCabbr(a:name, a:destination)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment