" Syntax settings
syntax on
set background=dark
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'joonty/vim-phpqa'
Plugin 'joonty/vdebug'
call vundle#end() " required
filetype plugin indent on " required
execute pathogen#infect()
" Reopen file on same line as it was closed
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Tab and indent settings
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent
" Backup file dir
set backupdir=~/tmp
" Line numbers
set number
" FuGITive status line
set laststatus=2
set statusline=%<\ %f\ %{fugitive#statusline()}
" Set backspace to work as in other apps
set backspace=2
" Enable wmnu
set wmnu
" Add current line marker
set cursorline
" Set autocompletion
filetype plugin on
set omnifunc=syntaxcomplete#Complete
" Key remaps
" Remap Ctrl+x Ctrl+o to Ctrl+Space (omni complete)
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
\ "\<lt>C-n>" :
\ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
\ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
\ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-@> <C-Space>
" Add closing brackets when an opening bracket is written
" Squirly brackets
inoremap { {}<Left>
inoremap {<CR> {<CR>}<Esc>O
inoremap {{ {
inoremap {} {}
inoremap { {}<Left>
inoremap <expr> } strpart(getline('.'), col('.')-1, 1) == "}" ? "\<Right>" : "}"
" Parenthesis
inoremap ( ()<Left>
inoremap (<CR> (<CR>)<Esc>O
inoremap (( (
inoremap () ()
inoremap ( ()<Left>
inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"
" Square brackets
inoremap [ []<Left>
inoremap [<CR> [<CR>]<Esc>O
inoremap [[ [
inoremap [] []
inoremap [ []<Left>
inoremap <expr> ] strpart(getline('.'), col('.')-1, 1) == "]" ? "\<Right>" : "]"
" Add closing quotes when an opening bracket is written, and jump over closing
inoremap " ""<Left>
inoremap "" "
inoremap <expr> " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\<Right>" : "\"\"\<Left>"
inoremap ' ''<Left>
inoremap '' '
inoremap <expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<Right>" : "\'\'\<Left>"
" Autocomplete already-existing words in the file with tab (extremely useful!)
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
" Highligh 80 and 120+ columns
highlight ColorColumn ctermbg=0
let &colorcolumn="80,".join(range(120,999),",")
" ctag bar
nmap <F8> :TagbarToggle<CR>
" Folding and unfolding
map ,f :set foldmethod=indent<cr>zM<cr>
map ,F :set foldmethod=manual<cr>zR<cr>
" Map F6 and F7 keys to search for tags
" map <F6> g<C-]>
" map <F7> <C-W>g<C-]>
" VDebug settings
let g:vdebug_options = {}
let g:vdebug_options["port"] = 9000
let g:vdebug_options["path_maps"] = {
\ "/var/www/": "/Users/tomazlovrec/Development/vagrant/dev/"
\}
let g:vdebug_options["server"] = "0.0.0.0"
let g:vdebug_options["break_on_open"] = 0
let g:vdebug_keymap = {
\ "set_breakpoint" : "<C-b>",
\}
" Sessions...session everywhere!
" Creates a session
function! MakeSession()
let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
if (filewritable(b:sessiondir) != 2)
exe 'silent !mkdir -p ' b:sessiondir
redraw!
endif
let b:sessionfile = b:sessiondir . '/session.vim'
exe "mksession! " . b:sessionfile
endfunction
" Updates a session, BUT ONLY IF IT ALREADY EXISTS
function! UpdateSession()
let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
let b:sessionfile = b:sessiondir . "/session.vim"
if (filereadable(b:sessionfile))
exe "mksession! " . b:sessionfile
echo "updating session"
endif
endfunction
" Loads a session if it exists
function! LoadSession()
if argc() == 0
let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
let b:sessionfile = b:sessiondir . "/session.vim"
if (filereadable(b:sessionfile))
exe 'source ' b:sessionfile
else
echo "No session loaded."
endif
else
let b:sessionfile = ""
let b:sessiondir = ""
endif
endfunction
au VimEnter * nested :call LoadSession()
au VimLeave * :call UpdateSession()
map <leader>m :call MakeSession()<CR>