~ pento /.vimrc

"-------------------------
" Pento VIM settings
" Last changes: 25.02.2007
"-------------------------

"-------------------------
" Common settings
"-------------------------
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" Enable loading filetype and indentation plugins
filetype plugin on
filetype indent on

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

" keep 50 lines of command line history
set history=50                

" show the cursor position all the time
set ruler                

" display incomplete commands
set showcmd                

" Turn on number vertical line
set nu

" I don't like backups
set nobackup

" Autoclose folds, when moving out of them
"set foldclose=all

" Open all folds
set foldenable
" I like {{{ }}} folds
"set foldmethod=marker
set foldmethod=indent

" Use incremental searching
set incsearch

" Do not highlight search results
set nohlsearch

" Jump 5 lines when running out of the screen
set scrolljump=7

" Indicate jump out of the screen when 10 lines before end of the screen
set scrolloff=7

" write all tmp files to /tmp
set dir=/tmp

" gui font
" set guifont=Misc\ Console\ 10
"set guifont=Bitstream\ Vera\ Sans\ Mono\ 10


" Turn off any bell
set novisualbell
set t_vb=   

" Enable mouse
set mouse=a
set mousemodel=popup

" default encoding
set termencoding=utf-8

" do NOT unload buffer when switch to another one
" this allows to edit several files in the same time without having to save
" them each time you switch between them
set hidden

" hide button panel
set guioptions-=T

" Make command line one line high
set ch=1

" Hide the mouse when typing text
set mousehide

" turn on autoindent
set autoindent

" I like highlighting strings inside C comments
"let c_comment_strings=0

" Switch on syntax highlighting if it wasn't on yet.
if !exists("syntax_on")
syntax on
endif

" allow to use backspace instead of "x"
set backspace=indent,eol,start whichwrap+=<,>,[,]

" expand tab to spaces ?
" set expandtab

" default tab size
set shiftwidth=4
set softtabstop=4
set tabstop=4
"set textwidth=80

" status line
set statusline=%<%f%h%m%r\ %b\ %{&encoding}\ 0x\ \ %l,%c%V\ %P 
set laststatus=2

" Auto indent after a {
set smartindent

" scan the files given with the 'dictionary' option
"set complete+=k           

" Fix <Enter> for comment
set fo+=cr

" Session options
set sessionoptions=curdir,buffers,tabpages

set foldcolumn=2

"-------------------------
" Bindings
"-------------------------

" Make <Backspace> act as <Delete> in Visual mode?
vmap <BS> x

" Wrap selected text to 80 symbols per line
vmap <C-b> <esc>:'<,'>!fold -w 120 -s<cr>

" CTRL-C and CTRL-Insert are Copy
vmap <C-C> "+yi
imap <C-V> <esc>"+gPi

" Make shift-insert work like in Xterm
map <S-Insert> <MiddleMouse>

" use CTRL-F for omni completion
imap <C-F> 

" Search & replace the word under the cursor
nmap ; :%s/\<<c-r>=expand("<cword>")<cr>\>/

" map F2 to quick save
nmap <F2> :w<cr>
vmap <F2> <esc>:w<cr>i
imap <F2> <esc>:w<cr>i

" F3 - list all errors        
nmap <F3> :copen<cr>
vmap <F3> <esc>:copen<cr>
imap <F3> <esc>:copen<cr>

" F3 - list all errors        
nmap <C-F3> :cclose<cr>
vmap <C-F3> <esc>:cclose<cr>
imap <C-F3> <esc>:cclose<cr>

" F4 - Project toogle
map <silent><F4> <Plug>ToggleProject
vmap <silent><F4> <esc><Plug>ToggleProject
imap <silent><F4> <esc><Plug>ToggleProject

" F5 - show buffers
nmap <F5> :ls<cr>:b
vmap <F5> <esc>:ls<cr>:b
imap <F5> <esc>:ls<cr>:b

" F6 - prev buffer
map <F6> :bp<cr>
vmap <F6> <esc>:bp<cr>i
imap <F6> <esc>:bp<cr>i

" F7 - newxt buffer
map <F7> :bn<cr>
vmap <F7> <esc>:bn<cr>i
imap <F7> <esc>:bn<cr>i

" F8 - Marks
map <F8> :marks<cr>
vmap <F8> <esc>:marks<cr>
imap <F8> <esc>:marks<cr>

" F9 to make
map <F9> :make<cr>
vmap <F9> <esc>:make<cr>i
imap <F9> <esc>:make<cr>i

" F10 kill buffer
map <F10> :bd<cr>
vmap <F10> <esc>:bd<cr>
imap <F10> <esc>:bd<cr>

" F8 - Tlist
map <F11> :TlistToggle<cr>
vmap <F11> <esc>:TlistToggle<cr>
imap <F11> <esc>:TlistToggle<cr>


" F12 to quick explorer
map <F12> :Ex<cr>
vmap <F12> <esc>:Ex<cr>i
imap <F12> <esc>:Ex<cr>i

" < & > to indent blocks
vmap < <gv
vmap > >gv

" Switch off 'Replace mode'
imap <Ins> <Esc>i

" C-T - new tab
map <C-t> :tabnew<cr>
vmap <C-t <esc>:tabnew<cr>
imap <C-t> <esc>:tabnew<cr>

" Open tag under cursor in new tab
map <C-W>] <C-W>]:tab split<CR>gT:q<CR>gt 

" Encoding menu
set wildmenu
set wcm=<Tab> 
menu Encoding.&koi8-r :e ++enc=koi8-r<CR>
menu Encoding.&windows-1251 :e ++enc=cp1251<CR>
menu Encoding.&cp866 :e ++enc=cp866<CR>
menu Encoding.&utf-8 :e ++enc=utf8 <CR>

map {<CR> {<CR>}<Esc>O

" Tab autocompletion
function InsertTabWrapper()
     let col = col('.') - 1
     if !col || getline('.')[col - 1] !~ '\k'
         return "\<tab>"
     else
         return "\<c-p>"
     endif
endfunction

imap <tab> <c-r>=InsertTabWrapper()<cr>

set complete=""
set complete+=.
set complete+=k
set complete+=b
set complete+=t
"set completeopt-=preview
set completeopt+=longest


" my own func to read *.out files and to paste their content to the current
function CopyBack()
let file=expand("%")
let out_file=substitute(file, '\.phpt', ".out", '')
execute "$read ".out_file
endfunction

map ff <esc>:call CopyBack()<cr>

let g:snippetsEmu_key = "<C-l>"


"-------------------------
" Colors
"-------------------------
"
colorscheme spec

au BufRead,BufNewFile *.phps    set filetype=php
au BufRead,BufNewFile *.thtml    set filetype=php
au BufRead,BufNewFile *.c    set filetype=c
au BufEnter *.nasl setfiletype nasl

iabbrev cline -----------------------------------------------------------------
iabbrev bcline =================================================================

let g:SessionMgr_AutoManage = 0
let g:SessionMgr_DefaultName = "mysession"

" Tag list settings
let g:Tlist_Show_One_File = 1
let g:Tlist_GainFocus_On_ToggleOpen = 1


set mps-=[:]


" New settings

" y, d, c и т.д. без указания регистра используют иксовый clipboard
set clipboard+=unnamed

" Что б не тянутся к esc в режиме вставки (мне кажется самое удобное)
imap jj <Esc>

nmap <Leader>va <Plug>VCSAdd
nmap <Leader>vn <Plug>VCSAnnotate
nmap <Leader>vc <Plug>VCSCommit
nmap <Leader>vd <Plug>VCSDiff
nmap <Leader>vg <Plug>VCSGotoOriginal
nmap <Leader>vG <Plug>VCSGotoOriginal!
nmap <Leader>vl <Plug>VCSLog
nmap <Leader>vL <Plug>VCSLock
nmap <Leader>vr <Plug>VCSReview
nmap <Leader>vs <Plug>VCSStatus
nmap <Leader>vu <Plug>VCSUpdate
nmap <Leader>vU <Plug>VCSUnlock
nmap <Leader>vv <Plug>VCSVimDiff

function MoveTabLeft()
    let current_tab = tabpagenr()
   if current_tab > 1
       let current_tab = current_tab - 2
       execute 'tabmove' current_tab
    endif
endfunction

function MoveTabRight()
    let current_tab = tabpagenr()
    execute 'tabmove' current_tab
endfunction

map <Leader>tl :call MoveTabLeft()<CR>
map <Leader>tr :call MoveTabRight()<CR>

let g:TranslateIt_Bin = "sdcv"

if &term =~ "xterm"
        let &t_SI = "\<Esc>]12;green\x7"
        let &t_EI = "\<Esc>]12;blue\x7"
endif


" For 'view' mode
if &readonly == 1
        set nonumber
        set nofoldenable
        set foldcolumn=10

        nmap <F10> :qa<cr>
        nmap <Space> <PageDown>
endif