~ mitry /.vimrc

" @(#)		~/.vimrc
" Description:	vim имеет всего два режима - бибикать и все портить. :-)
" Author:	dMitry Alexandrow 
" Created:	2003-08-24
" Version:	$Id: .vimrc,v 3a3db05f5dce 2008/08/21 17:21:20 dmitry $

version 6.2

" Options:							{{{1
" ======================================
" General:							{{{2
set nocompatible	" It is important to set this first
set exrc		" enable reading .vimrc/.exrc/.gvimrc in the current directory
set cpoptions=BceFsM	" list of flags to specify Vi compatibility
"set nopaste		" paste mode, insert typed text literally
"set pastetoggle=	" key sequence to toggle paste mode
"set helpfile		" name of the main help file

"set runtimepath	" list of directories used for runtime files and plugins
if has('win32')
set runtimepath=~/.vim,$VIMRUNTIME,~/.vim/after
endif

" Store an editing session in the viminfo file; can be used at next session.
set sessionoptions=buffers,folds,sesdir,slash,unix
set viminfo='50,<10,f1,s1,%,!,n~/.vim/.viminfo
set viewdir=~/.vim/view	" directory where to store files with :mkview (~/.vim/view)
set directory=~/.backup//	" directories for the swap file (last // - use full file path)
"set noloadplugins	" don't load plugin scripts when starting up
set debug=msg		" set to `msg` to see error messages for 'foldexpr' & 'indentexpr'
"set verbose=9		" the higher the more messages are given
"set insertmode		" Insert mode is the default mode - makes Vim a modeless editor.
"set eventignore=	" list of autocommand events which are to be ignored

set isfname-== isf-=[ isf-=] isf-=#	" specifies the characters in a file name

let g:ausession= ".vimsession"	" file for autosaved session

" GUI:								{{{2
"set lm=ru_RU.cp1251	" langmenu: language to be used for the menu
set winaltkeys=no	" Don't use ALT keys for menus.
set guioptions=gmMr	" list of flags that specify how the GUI works
"		T	= Toolbar
"		M	= '$VIMRUNTIME/menu.vim' isn't sourced.
"		m	= Show menu
"		t	= tear-off menus
"		L	= Left-hand scrollbar isn't present

" Tab support for 7.+ version
if has('windows')
	set guioptions+=e
	set switchbuf+=usetab
	set sessionoptions+=tabpages
endif

if has("gui_win32")
	" set guifont=Andale_Mono:h8:cRUSSIAN
	" set guifont=Lucida_Console:h10:cRUSSIAN
	" set guifont=Lucida_Sans_Typewriter:h8:cRUSSIAN
	" set guifont=Courier_New:h10:cDEFAULT
	" set guifont=Liberation_Mono:h10:cRUSSIAN
	set guifont=DejaVu_Sans_Mono:h10:cRUSSIAN lines=999 columns=100
	" set columns=100
endif

" Windows:							{{{2
set noequalalways	" don't make all windows the same size when adding/removing windows
" set eadirection=ver	" in which direction 'equalalways' works: 'ver', 'hor' or 'both'
set hidden		" don't unload a buffer when no longer shown in a window
set switchbuf=useopen,split	" which window to use when jumping
set nowinfixheight	" don't keep the height of the window
set splitbelow		" a new window is put below the current one (with :split and :help)
set splitright		" a new window is put right of the current one (with :vsplit)
set winwidth=20		" minimal number of columns used for the current window
" set lines=999		" number of lines in the VIM display
" set winminwidth=3	" minimal number of columns used for any window
" set winheight=20	" minimal number of lines used for the current window
" set helpheight=10	" initial height of the help window
" let &winheight=has('gui')? &lines-10 : 20
let &winheight=has('gui')? 35 : 20

" statusline:
let &stl='--<%02n> %1*%t%* %3*%M%*[%(%R%W%Y%),%{&fenc}:%{&ff}] %2*%{mode()}%* %4*%k%* %= 0x%B at %1*%l%*/%L:%c%V --'
set laststatus=2	" Always a status line

" Moving Around Searching And Patterns:				{{{2
"set path=,;~/**	" list of directory names used for file searching
set cdpath=,,.,~	" list of directory names used for :cd

set nogdefault		" (don't) Use `g` flag by default in substitutes
set nohlsearch		" (no)highlighting the last used search pattern
set incsearch		" show match for partly typed search command
set ignorecase		" ignore case when using a search pattern
set magic		" 'magic' patterns - extended regular expressions: \s+
set smartcase		" override 'ignorecase' when pattern has upper case characters
set nostartofline	" Don't jump to start of line after delete and other misc commands
set whichwrap=<,>,[,],h,l,b,s,~	" list of flags specifying which commands wrap to another line
set nowrapscan		" Searches wrap around the end of the file.
set virtualedit=block	" Cursor can be anywhere in Visual block mode
"set virtualedit=all	" Cursor can be anywhere in all modes

" Tags:								{{{2
set tags+=./tags;/	" list of file names to search for tags: Upward tag search
set showfulltag		" when completing tags in Insert mode show more info
"set tagbsearch		" use binary searching in tags files
"set taglength=0	" number of significant characters in a tag name or zero
"set tagrelative	" file names in a tags file are relative to the tags file
"set tagstack		" a :tag command will use the tagstack

" Displaying Text:						{{{2
set display=lastline	" show the last line even if it doesn't fit - no @
set lazyredraw		" don't redraw while executing macros
set nonumber		" don't show the line number for each line
set scrolloff=3		" number of screen lines to show around the cursor
set sidescroll=1	" minimal number of columns to scroll horizontally
set sidescrolloff=3	" minimal number of columns to keep left and right of the cursor
set linebreak		" wrap long lines at a character in 'breakat'
set fillchars=stl:-,stlnc:-,vert:\|,fold:\ ,diff:-
set showbreak=>>

set nolist		" Don't show  as ^I and end-of-line as $
set nowrap		" no long lines wrap

if has('gui_running')

" list of strings used for list mode
let &listchars = 'tab:|' . nr2char(0xBB) . ',trail:' .nr2char(0xB7) . ',eol:$'

let &fillchars="stl:".nr2char(0xAD).",stlnc:".nr2char(0xAD).',vert:|,fold:'.nr2char(0xB7).',diff:'.nr2char(0xBF)

endif	" has('gui_running')

" Terminal:							{{{2
set ttyfast		" terminal connection is fast
"set term=builtin_gui	" name of the used terminal
"set guicursor		" specifies what the cursor looks like in different modes
"set titlelen=85	" percentage of 'columns' used for the window title
set titlestring=%F\ %h%w\ -\ gViM	" string to be used for the window title
set title		" show info in the window title
set icon		" set the text of the icon for this window
"set iconstring		" when not empty, text for the icon of this window
"set norestorescreen	" restore the screen contents when exiting Vim
set esckeys		" recognize keys that start with  in Insert mode

" Mouse:							{{{2
set mousehide		" Hide the mouse pointer while typing
set mousemodel=extend	" what the right mouse button is used for
set nomousefocus	" the window with the mouse pointer becomes the current one

" Messages And Info:						{{{2
set confirm		" Always use ':confirm'
set shortmess=aOItT	" To avoid the 'Hit ENTER to continue' prompt
set showcmd		" Show current uncompleted command
set showmode		" (no)show the current mode
set report=0		" Report when N lines were changed.  report=0 : show all changes
set noruler		" (no)Show the cursor position all the time
set noerrorbells	" no Ring the bell (beep or screen flash) for error messages.
set novisualbell	" (don't) Use visual flashing instead of beeping.
"set verbose=0		" show messages about what VIM is doing.

" Selecting:							{{{2
set selection=exclusive		" Selection is exclusive, mswin-style
"set selection=inclusive	" Selection is inclusive, unix-style
"set selection=old		" / behave mswin
set keymodel=startsel,stopsel	" Use shifted cursor keys to start/stop selection
set selectmode=			" No Select-mode: no replace selection with typing

" Editing:							{{{2
set backspace=2		" BackSpacing over everything (indent,eol,start) in insert mode
set undolevels=100	" maximum number of changes that can be undone
set tildeop		" `~` command behaves like an operator

if has("unix")		" list of dictionary files for keyword completion
set dictionary=~/.words,/usr/share/dict/*.words
else
set dictionary=~/.words,c:/usr/share/dict/*.words
endif

"set thesaurus=		" list of thesaurus files for keyword completion

set complete=.,w,b,t,k,i	" specifies how Insert mode completion works
set formatoptions=crqon1	" list of flags that tell how automatic formatting works
	"	t = Auto-wrap text using textwidth (does not apply to comments)
	"	c = Auto-wrap comments, inserting the comment leader
	"	r = Insert the comment leader after hitting  in Insert mode.
	"	o = Insert the comment leader after hitting 'o' or 'O' in Normal mode.
	"	q = Allow formatting of comments with "gq".
	"	n = Auto-listing
	"	1 = Don't break a line after a one-letter word.
set infercase		" adjust case of a keyword completion match
set showmatch		" show the matching bracket for the last ')'
set matchtime=3		" tenth of a second to show a match for 'showmatch' (def=5)
set nrformats=alpha,hex	" number formats recognized for CTRL-A and CTRL-X commands

if v:version >= 700
set completeopt=longest,menu,preview
endif

" Tabs And Indenting:						{{{2
set autoindent		" always set autoindenting on
set smartindent		" do clever autoindenting
set cinkeys+=;		" figure out indent when ; is pressed
set noexpandtab		" no expand  to spaces in Insert mode
set shiftround		" round to 'shiftwidth' for `<<` and `>>`
set smarttab		" a  in an indent inserts 'shiftwidth' spaces
set tabstop=8		" Number of spaces that a  in the file counts for.
"set copyindent		" Copy whitespace for indenting from previous line
"set preserveindent	" Preserve kind of whitespace when changing indent
set cinoptions=:0,l1,t0,g0,(0	" C-Indent options: Linux-kernel style
	" N	number of spaces
	" Ns	number of spaces * shiftwidth
	" >N	default indent
	" eN	extra indent if the { is at the end of a line
	" nN	extra indent if there is no {} block
	" fN	indent of the { of a function block
	" gN    indent of the C++ class scope declarations (public, private, protected)
	" {N	indent of a { on a new line after an if,while,for...
	" }N	indent of a } in reference to a {
	" ^N	extra indent inside a function {}
	" :N	indent of case labels
	" =N	indent of case body
	" lN	align case {} on the case line
	" tN	indent of function return type
	" +N	indent continued algibreic expressions
	" cN	indent of comment line after /*
	" (N    indent N characters from the line with the unclosed parentheses.
	" )N	vim searches for closing )'s at most N lines away
	" *N	vim searches for closing */ at most N lines away

" Folding:							{{{2
set foldenable		" set to display all folds open
set foldlevel=0		" Min folding level
set foldlevelstart=-1	" value for 'foldlevel' when starting to edit a file
set foldclose=all	" close a fold when the cursor leaves it
"set foldopen=all	" specifies for which commands a fold will be opened
set foldminlines=1	" minimum number of screen lines for a fold to be closed
set foldmethod=marker	" folding type: 'manual', 'indent', 'expr', 'marker' or 'syntax'

if has('gui') " && winwidth(0) > 80
	set foldcolumn=3	" width of the column used to indicate folds
endif

" DiffMode:							{{{2
set diffopt=filler,context:4,iwhite	" options for using diff mode
"set diffexpr		" expression used to obtain a diff file
"set patchexpr		" expression used to patch a file

" Reading And Writing:						{{{2
set noautoread		" (don't) automatically read a file when it was modified outside of Vim
set backup		" keep a backup file
"set patchmode=.orig	" keep oldest version of a file with this extension
set backupskip+=.passwd	" patterns which files a backup is not made
set backupdir=~/.backup,~/tmp,/tmp,c:/tmp
set fileformat=unix	" end-of-line format: unix - not dos
set fileformats=unix,dos	" list of file formats to look for when editing a file
set modeline		" enable using settings from modelines when reading a file (vim:ts=8:fenc=koi8-r)
set modelines=3         " number of lines to scan for modeline

" CommandLine Editing:						{{{2
set history=50			" keep 50 lines of command line history
set wildmode=longest:full,full	" specifies how command line completion works
set wildmenu			" enhanced mode command-line completion
set wildcharm=		" wildcard expansion inside a macro

" Ignore at auto-completion:
set wildignore=*.o,*.obj,*.exe,*.dll,*.com,*.class,*.au,*.wav,*.mp[23g],*.jar,*.rar,*.zip,*.gz,*.tgz,*.jpg,*.png,*.gif,*.avi,*.wmv,*.flv,*.djvu,*.pdf,*.chm,*.ps,*.dvi,tags,*/CVS/,*/.hg/,*.~*,*~

" Name extensions with lower priority
set suffixes+=.log
set suffixes+=.out
set suffixes+=.COPYING

" External Commands:						{{{2
set shellslash		" use forward slashes in file names; for Unix-like shells
if v:version < 700
	set grepprg=grep\ -rnEH		" program to use for the `:grep` command
else
	set grepprg=internal
endif

if has("filterpipe")
	set noshelltemp	" Use pipes on Unix
endif

set formatprg=		" program used to format lines with 'gq' command
set equalprg=		" program used for '=' command (global or local to buffer)
set keywordprg=		" program used for the 'K' command
" set warn		" warn when using a shell command and a buffer has changes

" MultiByte Chars:						{{{2

set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp1251,koi8-r,cp866,java
so :p:h/keymap/russian-jcuken-win.vim

if has('win32') && !has("gui_running") && $SHELL != ''
set termencoding=8bit-cp1252
endif

" Spelling:							{{{2

if has("spell")
set spelllang=en,ru
set spellfile=~/.words.utf-8.add
map		:setlocal spell! spell?
endif

" ======================================			}}}1
" Colors And Position:						{{{1

" Color scheme must be loaded _before_ `syntax on`
if has("gui_win32")
	colorscheme MSWin
else
	colorscheme Norton
endif

if has("gui_win32")
let g:browsefilter =
	\ "All Files (*.*)\t*.*\n"
	\."Config Files (*.ini *.cfg *.rc)\t*.ini;*.cfg;*.rc\n"
	\."C/C++ Source Files (*.c *.cpp *.h *.hpp)\t*.c;*.cpp;*.c++;*.h;*hpp\n"
	\."Java Source Files (*.java *.properties)\t*.java;*.properties\n"
	\."Batch Files (*.bat *.cmd)\t*.bat;*.cmd\n"
	\."Perl Scripts (*.pl *.pm)\t*.pl;*.pm\n"
	\."HTML Files (*.htm *.html *.jsp *.css)\t*.htm;*.html;*.jsp;*.css\n"
	\."Vim scripts (*.vim .vimrc)\t*.vim;.vimrc;.gvimrc;_vimrc;_gvimrc;\n"
endif

" AutoCommands:							{{{1

filetype plugin indent on	" Enable file type detection
syntax on

function! s:HiddenExec(str)	" Execute str keeping jumps and regisers {{{2
	if &ma && ! &ro
		normal! m`
		" silent! exe a:str
		silent exe a:str
		normal! g``zv
		call histdel("/", -1)
		let @/ = histget("/", -1)
	endif
endfunction	" }}}2
augroup ENCODINGS						" {{{2
	au!
	" au BufNewFile	*		setl fenc=cp1251
	" au BufNewFile	*.ini		setl fenc=cp1251

	au FileType	jproperties	nested Encoding java
	au FileType	mail		nested Encoding koi8-r
	" au FileType	dosini		nested Encoding cp1251

	" To show lang name on the statusline
	au BufNewFile,BufRead	*	let b:keymap_name="RU"
augroup END

augroup AUTOMOD							" {{{2
	au!

	" Save the buffer marks
	au BufUnload	*	wviminfo!

	" Remove trailing blanks and ^M
	au BufRead			*	call s:HiddenExec('%s/\r\+$//e')
	au BufWritePre,FileWritePre	*	call s:HiddenExec('%s/\s\+$//e')

	" To insert the current date and time in a *.html file when writing it:
	au BufWritePre	*.htm,*.html,*.php	call s:HiddenExec('%s/\') .'.vim')
	"au FuncUndefined	*	silent! source ~/.vim/macros/.vim

	" Jump to the last place you had been while reading Vim help files by use 'H
	au BufLeave	*	if &bt=='help' | mark H | endif
	au BufWinEnter	*	if &ft=~'^\v(help|man|info)$' || &pvw | exe 'wincmd K' | endif

	" VimTip214: Current buffer based menus.
	" If you have different menus for different filetypes, and you want to have
	" only the menu relevant to current buffer displayed, you can use this approach:
	au BufEnter	*	exe exists('b:BuffEnter')? b:BuffEnter : ''
	au BufLeave	*	exe exists('b:BuffLeave')? b:BuffLeave : ''

	au BufRead	~/.passwd	setl syn=url fdm=expr fde=outline#fold()

	if executable('pwgen') == 1
	au BufRead	~/.passwd	nno	p	"=substitute(system('pwgen'),'\n$','','')p
	elseif executable('makepasswd') == 1
	au BufRead	~/.passwd	nno	p	"=substitute(system('makepasswd -l 12'),'\n$','','g')p
	elseif executable('perl') == 1
	au BufRead	~/.passwd	nno	p	"=substitute(system('perl -MText::Password::Pronounceable -e "print Text::Password::Pronounceable->generate(8, 10)"'),'\n$','','')p
	endif
	" au BufRead	~/.passwd	nno	p	"=substitute(system('cscript.exe //NoLogo c:/bin/pwgen.js'),'\n$','','g')p

	au BufRead	~/.passwd	imap	p	p
	au BufRead	~/.passwd	nno	 "*yiW
	au BufRead	~/GTD/*		setf	vimwiki

	au BufRead	*.m3u,*.pls	nno	gx :!start /usr/opt/mplayer/mplayer -nocache 

augroup END

augroup SyntaxAdd						" {{{2
	au!
	au Syntax	*	syn match WhitespaceEOL	containedin=TOP /\s\+$/
	au Syntax	*	syn match WhitespaceEOL	containedin=TOP / \+\t/he=e-1
	au Syntax	*	syn match WhitespaceEOL	containedin=TOP /\t \+/hs=s+1

	au Syntax help,todo	syn clear WhitespaceEOL

	au Syntax *.[ch],*.[ch]pp runtime syntax/doxygen.vim
augroup END

augroup SESSSIONS						" {{{2
	au!
	au VimEnter	* nested if !strlen(v:this_session) && !argc() && !expand("") && filereadable(g:ausession) | exec 'so' g:ausession | endif

	au VimLeavePre	* if strlen(v:this_session)
	au VimLeavePre	*	let SESSION = v:this_session
	au VimLeavePre	*	exe 'mksession!' v:this_session
if has('win32')
	au VimLeavePre	*	exe 'silent!!start NirCmd.exe shortcut "'.v:this_session'" "~$folder.desktop$\Projects" '.fnamemodify(v:this_session,':p:h:t:r')
endif
	au VimLeavePre	* else
	au VimLeavePre	*	silent! unlet SESSION
	au VimLeavePre	* endif
augroup END

augroup CMDWindow			" // Command Window:	{{{2
	au!
	" Save new history after editing
	au CmdwinEnter	*	map 	:q
	au CmdwinLeave	*	exe 'call histdel("'.expand('').'")|%call histadd("'.expand('').'",getline("."))'
augroup END

augroup CVSCommand						"{{{2
	au User CVSBufferSetup	map q		:bwipeout
	au User CVSBufferSetup	map 	:bwipeout
augroup END

augroup GnuPG							" {{{2
	au!
	au BufReadPost	*.asc	:%!gpg -qd
	au BufWritePre	*.asc	:%!gpg -qea
	au BufWritePost	*.asc	:undo

	if !has("gui_running")
		au BufReadPost	*.asc	:redraw!
		"au VimLeave	*.asc	:!clear
	endif
augroup END

augroup EXTEXE			" // Associations:		{{{2
	au!

if has('win32')
	" Execute command and close opened for it buffer
	command! -nargs=* -bang -complete=file SExe silent exe '!start' iconv(,&enc,'cp1251') |bu#|bw!#

	" To make gf worked for URL, say, file:///C:/myfile.txt
	au BufReadCmd	file://*	bd!|edit :p:s?^file://??
	au BufReadCmd	reg://*		SExe! NirCmd.exe regedit :p:s?^reg://??
	au BufReadCmd	http://*	SExe! rundll32.exe shell32.dll,ShellExec_RunDLL :p

	" Multimedia (don't work w/out exe '!start' ; no spaces in path)
	" au BufReadCmd	*.mp3	SExe! madplay --tty-control :p
	au BufReadCmd	*.exe	SExe! :p

	au BufReadCmd	*.lnk,*.url,*.chm,*.pdf,*.djvu,*.zip,*.rar,*.mp3
		\ SExe! NirCmd.exe shexec open ":p"
		" \ SExe! RunDll32.exe shell32.dll,ShellExec_RunDLL ":p"

	au BufReadCmd	*.jpg,*.gif,*.ico,*.png,*.bmp,*.icl
		\ SExe! NirCmd.exe shexec view ":p"
endif

	" Decompile java classes
	au BufReadCmd	*.class	exe '0r!jad -p '
	au BufReadCmd	*.class	exe setlocal ft=java bt=nowrite nomod noma
augroup END

" ======================================			}}}1
" Syntax Highlighting:						{{{1

" Should be set _after_ 'syntax on'
hi! link StorageClass	Statement
hi! link Structure	Statement
hi! link Function	Normal

" Highlighting whitespaces at end of line
hi! link WhitespaceEOL	WarningMsg

hi! link diffRemoved	Comment
hi! link diffAdded	PreProc

let readline_has_bash = 1
let is_bash = 1
let sh_fold_enabled= 1

" Plugins:							{{{1

let user = 'dMitry Alexandrov'		" used by Templates
let replyto = 'dmitry.alexandrow@gmail.com'	" - '' -
let copyright = strftime("%Y").', Mitrysoft Corp.  All rights reserved.'
let username = 'Mitry'			" used by JCommenter
let spec_chglog_format = '%Y-%n-%d ' .user.' <'.replyto.'>'

" -------------
" Environment:
let $EDITOR = (has('gui_running')?'g':'') . 'vim --remote-silent'
let $MAIL = 'Inbox.mbx'			" Used by mailbrowser
let $TERM = has('gui')? 'dump' : $TERM

" Explore:							{{{2
let explDetailedHelp=0	" Show more help
let explDetailedList=0	" the size and date to do not show by default
let explVertical=1	" Split vertically
let explWinSize=25	" the number of rows or columns
let explDirsFirst=-1	" Directories at the bottom of the list
let explSplitRight=1	" Put new window to the right of the explorer
let explStartRight=0	" Put new explorer window to the left of the current window
let explUseSeparators=0	" Include separator lines between directories, files, and suffixes
"let explHideFiles='^\.,\.gz$,\.exe$,\.dat$,\.zip$,\.class$,\.log$'

noremap		:aboveleft 25vsplit %:p:h
map	gz	NetrwBrowseX

" TagList:							{{{2
let Tlist_Inc_Winwidth=1
let Tlist_Display_Prototype=0
let Tlist_Compact_Format=1
let Tlist_Exit_OnlyWindow=1

map		:Tlist

" Calendar: (cp-1251)						{{{2
let g:calendar_navi_label = 'Пред,Сегодня,След'
let g:calendar_mruler = 'Янв,Фев,Мар,Апр,Май,Июн,Июл,Авг,Сен,Окт,Ноя,Дек'
let g:calendar_wruler = 'Вс Пн Вт Ср Чт Пт Сб'
let g:calendar_monday = 1
let g:calendar_focus_today=1

hi! CalWeekend guifg=red
hi! link CalSaturday	CalWeekend
hi! link CalSunday	CalWeekend
hi! link CalMemo	Type
hi! link CalToday	Todo

" map this way to disable mapping in Calendar.vim plugin (NO noremap)
map			CalendarV
map		CalendarH

" CVSCommand:							{{{2
"let loaded_cvscommand = 1	" Don't load
let CVSCommandDeleteOnHide=1	" automatically delete temporary CVS results
let CVSCommandDiffOpt='wbBu'	" options passed to the diff command (fefault: wbBc)
let CVSCommandEdit='split'	" the original buffer is replaced ('edit') or split
let CVSCommandEnableBufferSetup=0	" set 'CVSRevision' 'CVSBranch' vars

" Mru:								{{{2
let MRU_File = '~/.vim/.mru_files'
"let MRU_Max_Entries=20


" Changelog:							{{{2
let changelog_username = username	" used by changelog ftplugin

" o - switches to the ChangeLog buffer opened for the current directory.
runt ftplugin/changelog.vim

" Commenting:							{{{2
" EnhancedCommentify:						{{{3
let EnhCommentifyRespectIndent='yes'	" - yes/no - in lowcase ?!?!
let EnhCommentifyPretty='yes'		" -
let EnhCommentifyUseSyntax='yes'	" -
let EnhCommentifyUseBlockIndent='yes'	" -
let EnhCommentifyMultiPartBlocks='yes'	" - Mulitline-comments
"let EnhCommentifyUseAltKeys='no'	" Use alt keybindings  instead of X.
"let EnhCommentifyUserBindings='yes'	" -

nmap		Traditionalj
imap			i
vmap		VisualTraditionalgv

" Copy current line and commentify it
nmap		:copy -1
imap			

" Doxygen:							{{{3
let DoxygenToolkit_briefTag=".."
let DoxygenToolkit_authorName=username
" Disable Some Plugins:						{{{2
let loaded_matchparen=1			" showing matching parens ??? by Bram Moolenaar
let loaded_gzip=1			" plugin for editing compressed files
let loaded_GetLatestVimScripts=1	" disable GetLatestVimScripts
let loaded_rrhelper = 1			" helper function(s) for --remote-wait
" let loaded_netrw = 1			" file transfer and local/remote directory listing (Explore)

if has('win32')
let netrw_use_nt_rcp=1			" use the rcp of WinNT for netrw
endif

" let loaded_netrwFileHandlers=1
" let loaded_netrwSettings=1
" let loaded_vimball=1			" construct a file containing both paths and files ???

" ======================================			}}}1
" Key Mapping:							{{{1

" See also:
" ~/.vim/plugins/SpKeys.vim	Standard mapping for  and  :
" ~/.vim/plugins/MetaMove.vim	blockwise select mode

" Select Current Word:						{{{2
nmap		ciw
nmap		ciW
omap		iw
omap		iW
vmap		iw
vmap		iW

" Undo: 							{{{2
map			
map		

" Help: 							{{{2
if has("win32")
	noremap 	:emenu Help.English-Russian
endif

" In insert and command mode:
map!		

" How prev help topic
map		s`H:setl bt=help

" Show Syntax Highlighting groups the item under the cursor
map	?	:echomsg "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"
map		?

" Show buffer key mappings
map		:map buffer>

" Deleting:							{{{2
noremap			db
cnoremap		

" Delete current line
imap		dd
nmap		diw

" Delete to the clipboard
imap		"*yyddi
nmap		"*dd

" Delete the word right
map		dw

" Delete the rest of the line
map		d$

" Delete empty lines in the selection
vmap	d	:g/^$/d

" Don't delete whole line if selection exists
vmap	C	c
nmap		ciw

" Saving: 							{{{2
noremap		:update
noremap		:wall
noremap		:browse confirm saveas

" Searching: 						{{{2
nnoremap		/
cnoremap		%s!!!g

nnoremap		:.,$s!\<\>!!g
vnoremap		y:.,$s!=escape(@",'\!')!!g
cnoremap		.,$s!!!g

nnoremap		:%s!\<\>!!g
cnoremap		%s!!!g

" Search current word in the other window
noremap			yiwpgg:call search(@@)

" Windows:							{{{2
map		5+
map		_
map		5-
map		1_
map		=

map		K
map		J
map		H
map		L

" Jump between windows
nnoremap		p

" Sroll other window
nmap		pp
nmap		pp

" Switch buffers
nmap		:buffer

" WinTabs support
if has('windows')
nnoremap		^T
" nnoremap		:simalt ~n
" nnoremap		:tabnew

map			gt
map		gT

map		gt
map		gT

map			1gt
map			2gt
map			3gt
map			4gt
map			5gt
map			6gt
map			7gt
map			8gt
map			9gt
map			10gt

else

map			:sbuffer
map		

endif

" QuickFix: Development/Compile 				{{{2
nmap		:wallcclosesilent makebotright cwindow 4
nmap		:botright cwindow 4cnextzv
nmap		:botright cwindow 4cprevzv

" VimTip94: :ptjump on the tag
" map		g}
" map	]	g

" Show Tags
" map		:silent ptag 

" Mode Switch:							{{{2
nmap		:setlocal wrap! wrap?
nmap		:setlocal list! list?
nmap		:setlocal number! number?
nmap		:setlocal hlsearch! hlsearch?

" Insert/Normal mode switching
" map		:set insertmode! im?

" Folding:							{{{2
" Hide/show fold column
nmap	zi	zi:let &l:fdc=&l:fen*&g:fdc
nmap	zZ	:let &l:fdc=v:count

" Tip#1330: Easily open and close folds
nmap	 za
nmap		zozt
nmap		zczz

" Goto next/prev folder
nmap		zjzvzt
nmap		zkzv[zzt

" Fold an entire block of code
map		v%zf

" View cursor line only
nmap	zV		zMzx

" Lines: Copy/Move/Swap						{{{2

" have Y behave analogously to D rather than to dd
nmap Y y$

" With no selection - copy current line
nmap		"+yy
imap		"+yy
cmap		

" Move lines up/down
nmap		:move +1
imap			
vmap		:move =line("'>")+1gv

map			:move -2
imap				
vmap			:move -2gv

" Copy chars from prev/next line
inoremap		
inoremap		

" Copy line - like yyp , but keep cursor position
nmap	z		:copy .
imap	z		z

" Add selection to clipboard
vnoremap 	:let @c=@*gv"Cy:let @*=@c

" Copy whole bubber to clipboard
nmap		:%yank *

" Meta-A is Select all
noremap			ggVG

" Copy current word to the clipboard
noremap			"*yiw

" Change current word with clipboard
nmap			ciw*

" CursorKeys: use screen lines					{{{2
" editing mapping (make cursor keys work like in windows.
" ie:  move to next word.
nmap		b
vmap		b
nmap		vb
imap		vb

if &sel == 'exclusive'
nmap		w
vmap		w
nmap		vw
imap		vw
else
nmap		e
vmap		e
nmap		ve
imap		ve
endif

nnoremap			
nnoremap		

" Indenting:							{{{2
" In visual mode,  will shift the block and restore selection
"  will do the same thing, going backward.
vmap		>gv
vmap		gv

nmap		>>
nmap		

inoremap 	

" Encodings: i18n & l10n					{{{2
function! s:FEncNext()	" // File Encoding switching
	let b:encstring = (!exists("b:encstring"))? substitute(&fencs, ',', ' ', 'g') : b:encstring

	if &fenc=='' | let &l:fenc=&enc | return | endif
	" place current fenc to the end of the string
	let b:encstring = substitute(b:encstring, '^\v(.*<'. &fenc .'>)\s+(.*)$', '\2 \1', '')
	let nenc = substitute(b:encstring, '^\v\s*(\S+).+', '\1', '')

	if expand('%') == ''
		let &l:fenc=nenc
	else
		silent exec 'vi ++enc=' . nenc
	endif
endfunction

map  :call FEncNext()

" Switch LangMap:
nmap		:set im:set noim
map!			

" SwitchCase:							{{{2
imap	SwitchCase =(@@==#toupper(@@))?tolower(@@):(@@==#tolower(@@))?substitute(@@,'\<.','\u&',''):toupper(@@)`]
nmap		ciwSwitchCase
vmap		ciSwitchCasegv
imap		ciWSwitchCase

map	SxCase	ciw

" Digraphs:							{{{2
dig ** 8226	" •
dig .. 8230	" &hellip
" dig 	160	"  

" Insert DateTime FileName:					{{{2
imap		=strftime('%Y-%m-%d')
imap		=strftime('%H:%M')
imap		='@(#) '.expand('%:p:~')
imap		='vim: set ft='.&ft.' ts='. &ts . ' noet fenc=' . &fenc . ':'
imap		='(c) '.copyright
imap		=strftime('Mitry[%Y-%m-%d]: ')
imap		=user.' <'.replyto.'>'
imap		=replyto

imap			=expand("%:p:h")/
imap			=expand("%:p:~:.:h")/

nmap			i
nmap			i
nmap			i
nmap			i
nmap			i
nmap			i
nmap			i

" copy full-file-name to clipboard
nmap		:let @*=expand("%:p")

" Command Mode Abbrs:						{{{2
cabb	E	echo
cnoremap E echo

cmap		~/.vim/
cmap		%s!!!g
cmap		.,$s!!!g
cmap			\(.\{-}\)

" Escape commandline:
cmap			eescape(getcmdline(), ' \')

" Copy to clipboard:
cmap		=setreg('*',getcmdline())?'':''

" Insert current line:
cmap		=strtrans(getline('.'))

" Delete the word after cursor
cmap		esubstitute(getcmdline(), '\%'.getcmdpos().'c\k\+\s*', '','')

" Insert paths
cmap		=expand("%:p:h")/
cmap		=expand("%:p:~:.:h")/
cmap		=getcwd()/
cmap		~/.vim/ftplugin/=&ft
cmap		~/.vim/

" Paths
cnoremap		=expand("%:p:~:.:h")/
cnoremap		~/.vim/
cnoremap		$VIMRUNTIME/
cnoremap		~/src/
cnoremap		/usr/src/

" Edit Files:							{{{2
" // Forcebly edit file under cursor
" nmap gf :edit %:p:h/
" nmap	gf	:tryfind cfile>catchedit %:p:h/cfile>endtry
nmap	gf	:tryfind cfile>catchedit cfile>endtry

nmap v	:sp ~/.vim/.vimrc
nmap V	:sp ./.vimrc
nmap M	:sp ~/.vim/menu.vim
nmap p	:sp ~/.passwd
" nmap o	:sp ~/.plan
nmap o	:sp ~/GTD/@someday
nmap O	:sp `=g:diary_file`
nmap T	:pedit `=exists('b:my_ftplugin')? b:my_ftplugin : '~/.vim/ftplugin/'.&ft.'.vim'`P
nmap d	:sp ++enc=cp866 ~/Desktop/2down.lst
nmap e	:e =expand("%:p:~:.:h")/
" Scratch
nmap s	:tabnew +setl\ bt=nofile

" Edit vimsession-extra file:
nmap X	:sp `=fnamemodify(v:this_session,':p:r').'.x.vim'`
nmap S	:exe exists('SESSION')? 'so '.SESSION : 'echoerr "No last session known!"'

" Template/snippets:
nmap t	:read  ~/.vim/templates/=&ft/
vmap t	:write ~/.vim/templates/=&ft/

nmap m	:sfind Makefile

if has('win32') && isdirectory('c:/var/log/cron/')
nmap n	:pedit ++enc=cp1251 +$ c:/var/log/cron/=strftime('nnCron%m%d.log')
endif

" Complition							{{{2
if v:version >= 700

" ** These two mappings are probably the most rare, yet most valuable: **
inoremap		pumvisible()? "\c-n>" : "\c-n>\c-r>=pumvisible() ? \"\\down>\" : \"\"\cr>"
inoremap		pumvisible()? "\c-n>" : "\c-n>\c-r>=pumvisible() ? \"\\up>\" : \"\"\cr>"
" inoremap		pumvisible()? "\c-n>" : "\c-x>\c-o>\c-n>\c-p>\c-r>=pumvisible() ? \"\\down>\" : \"\"\cr>"

endif

" Abbreviations:						{{{2
iabbr	dM	=user.' <'.replyto.'>'
iabbr	NEO	Nomen est omen

" Exec File:							{{{2
if has('win32')

" command Sh		:call system('RunDll32.exe shell32.dll,ShellExec_RunDLL "'.iconv(expand(),&enc,'cp866').'"')
command! -nargs=* Sh	:exe 'silent !start' 'RunDll32.exe shell32.dll,ShellExec_RunDLL "'.iconv(expand(),&enc,'cp1251').'"'

nmap	gx	:silent !start RunDll32.exe shell32.dll,ShellExec_RunDLL 
" nmap	gX	:silent !start RunDll32.exe shell32.dll,ShellExec_RunDLL "%:p"
" nmap	gX	:call system('RunDll32.exe shell32.dll,ShellExec_RunDLL "'.iconv(expand('%:p'),&enc,'cp866').'"')
nmap	gX	:exe 'silent !start' 'RunDll32.exe shell32.dll,ShellExec_RunDLL "' . iconv(expand('%:p'),&enc,'cp1251') . '"'
map		gX

map			:silent!!start c:/opt/far/far.exe /i /c %:p:h:gs?/?\\?

if executable('NirCmd.exe')
" Jump to regkey in the RegEdit via NirCmd
map	gy	:silent!!start NirCmd.exe regedit :s?^\[\|]$??:s?^-??

" Make link to the current file on the desktop
map		:silent!!start NirCmd.exe shortcut "%:p" "~$folder.desktop$" "%:p:t:r"
" Make link to the current session on the desktop
map		:if strlen(v:this_session)
	\  exe ':silent!!start NirCmd.exe shortcut "'.v:this_session'" "~$folder.desktop$\Projects" '.fnamemodify(v:this_session,':p:h:t:r')
	\  else  echoerr "No session!!"  endif

endif
endif

" GUI:								{{{2
if has('gui')

" Toggle GUI Option:
function! s:SwitchGui(opt)
	exe "set go".(&go =~# a:opt? '-=' : '+=').a:opt
	set lines=999
endfunc

" Switch Main GUI Menu:
nmap		:call SwitchGui('m')
nmap		:call SwitchGui('T')
" map		:if &go =~#'m'\|set go-=m\|else\|set go+=m\|endif\|set lines=999

" Increase/Decrease Fontsize:
" @see http://vim.wikia.com/wiki/VimTip760
nnoremap 	:let &gfn=substitute(&gfn,':h\zs\d\+','\=eval(submatch(0)+1)','')set lines=999
nnoremap 	:let &gfn=substitute(&gfn,':h\zs\d\+','\=eval(submatch(0)-1)','')set lines=999

endif
" ===============================				}}}2

" Start block selection:
nnoremap	 $

" Restore ability to use  redefined by indeneting with 
nnoremap		zv
nnoremap		zv

inoremap		O
inoremap		o

" Auto-completion assigned
inoremap		

" Quick insert 1 char
nnoremap		ir

" Quick paste
inoremap		"

" Disable  - suspend vim
map		
map!		

" Correct syntax synchronization
map	r	:syntax sync fromstart

" VimTip44: The last command-line change (those invoked with ":",
" e.g. :s/foo/bar ) can be repeated with the "@:" command.
map		@:

" VimTip637: execute accidently inserted commands
" If you are in insert mode and typed an command for normal mode, you can
" use it.  This mapping switches to normal mode, undo'es the last insertion
" and takes it as a command.
inoremap		u@.

" Puts "" around the word under cursor or the visual selected area
nnoremap	"	ciw"""
vnoremap	"	c"""

nnoremap	'	ciw'"'
vnoremap	'	c'"'

nnoremap	)	ciw(")
vnoremap	)	c(")`[

" Swap the current and preceeding word at the line end
nmap		daWgepe

" don't use ex mode, use q for line formatting
nmap	Q	gw}
vmap	Q	gq

" Format block of lines
nmap	g=	=g%
map		=g%

" Visually select the last copy/pasted text (didn't work ?)
nnoremap		`[v`]
inoremap		`[v`]

" Duplicate current line and in/decriment
nmap		:copy .
nmap		:copy -

" ======================================
"echo "Key mapping done!!!"

" Commands:							{{{1
" Redir: Copy vim command output to the system clipboard	{{{2
command! -nargs=+ -complete=command Redir
	\   redir @a
	\ | silent 
	\ | redir END
	\ | 20new [Scratch: ]
	\ | 1put! a
	\ | setlocal bh=delete bt=nofile nomod
	\ | wincmd p

" CD: to the dir of the current buffer for current window	{{{2
command! CD lcd %:p:h
command! Cd lcd %:p:h

" Info:								{{{2
" Define Info cmd to source script file which redefine this one
command! -nargs=* Info
	\ delcommand Info |
	\ runt scripts/Info.vim |
	\ Info 

" Man:								{{{2
" Define Man cmd to source script file which redefine this one
command! -nargs=1 Man
	\ delcommand Man |
	\ runt ftplugin/man.vim |
	\ Man 

" WinHelp: Invoke Windows help					{{{2
if has('win32')
command! -nargs=1 -complete=file WinHelp
	\ call libcallnr(expand('~/.vim/etc/wvimhlp.dll'), 'winhelp',
	\  . '|' . iconv(expand(''), &enc, 'cp1251'))
endif
" Encoding: Change file encoding				{{{2
command! -nargs=1 -bar Encoding if &fenc!= | visual ++enc= | endif

" Far: invoke far manager					{{{2
if has('win32')
command! -nargs=0 -bar Far :silent!!start c:/opt/far/far.exe -i %:p:h
endif

" Move (append) lines to the other file				{{{2
" Usage: :{range}Move [file_name]
command! -complete=file -range -bang -nargs=? Move :,write >> |:,delete
" ======================================			}}}1

source	~/.vim/menu.vim		" My customized menu
" runt! menu.vim

"runtime etc/wordlist.vim	" common english misstypes
set secure			" safer working with script files in the curdir

" EOF ~/.vim/.vimrc // vim: fen:fdm=marker:fcl=all:fdl=0:fml=1:ts=8:ff=unix:  
Your Ad Here