" Vim: set fdm=marker sw=2 " Author: Maxim Kim " WWW: http://habamax.ru/myvim/ " Last Change: 2010-05-10 13:12 " General {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nocompatible autocmd! " use .vim folder instead of vimfiles on windows. if !has("unix") set rtp& let &rtp = '~/.vim,'.&rtp.',~/.vim/after' endif filetype plugin indent on syntax on set hidden set browsedir=buffer let mapleader = "," " Always cd to the current file's directory autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ / """ end of General }}} " UI {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set shortmess+=I set winaltkeys=no set guioptions-=T " No toolbar set laststatus=2 set showtabline=2 set cmdheight=1 set number set splitbelow splitright set winminwidth=0 winminheight=0 set scrolloff=3 set lazyredraw set display=lastline " Font {{{ if has("gui_running") if has("unix") set gfn=DejaVu\ Sans\ Mono\ 12,Liberation\ Mono\ 14 else set gfn=Consolas:h14,DejaVu_Sans_Mono:h12,Courier_New:h14 endif endif " end of Font }}} " set ruler " setup statusline set stl=%f\ %m%y[%{(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\") \\ &&\ &bomb)?\",B\":\"\")}]%r%w[%{&ff}]%=%k\ (%l/%L),%v\ (%p%%) " maximize GVim au GUIEnter * set lines=999 columns=999 " autocomplete is getting much better :e ... set wildchar= wildmenu wildmode=full set wildignore=*.o,*.obj,*.bak,*.exe,*.swp " turn off beeping... set visualbell au GuiEnter * set t_vb= set t_vb= """ end of UI }}} " Text {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " encodings&fileformat set encoding=utf8 set fileencoding=utf8 set fileencodings=utf-8,cp1251 set fileformats=unix,dos set fileformat=unix set tabstop=8 shiftwidth=4 expandtab smarttab set autoindent set hlsearch incsearch ignorecase set nowrap set linebreak set listchars=tab:>-,trail:·,extends:> " backspace and cursor keys wrap to previous/next line set backspace=indent,eol,start whichwrap+=<,>,[,] set formatoptions+=nro set comments=n:>,fb:-,fb:* set formatlistpat=^\\s\\+[*#-]\\s* autocmd BufRead,BufNewFile *.txt setfiletype text autocmd FileType text setlocal tw=79 """ end of Text }}} " Sessions {{{ set sessionoptions=buffers,curdir,help,tabpages,winsize function! SaveSession() wall if !empty(v:this_session) exe "mksession! ".v:this_session endif endfunction nmap :call SaveSession() nmap :1,$bd so ~/.vim_sessions/ " End of Sessions }}} " Backup {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if !isdirectory(expand('~/.vim_backups')) call mkdir(expand('~/.vim_backups')) endif set backup set backupdir=~/.vim_backups/ set directory=~/.vim_backups/,. " End of Backup }}} " Handy buffer switching "{{{ set switchbuf=useopen nmap b :ls:b "}}} " Spell checking {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " По умолчанию проверка орфографии выключена. set spelllang=ru,en set nospell map :set spell! \:echo "Spell check: ".strpart("OFFON", 3 * &spell, 3) " End of Spell checking}}} " Misc keybindings {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" nmap gk nmap k gk vmap gk vmap k gk nmap gj nmap j gj vmap gj vmap j gj imap gj imap gk vnoremap > >gv vnoremap < gt map gT " run current file noremap :w:silent !"%" noremap :w:!% " Capitalize inner word map guiw~w " UPPERCASE inner word map gUiww " lowercase inner word map guiww " just one space on the line, preserving indent map m`:s/\S\+\zs\s\+/ /g``:nohl:echo 'Just one space' " saving file imap :updatea map :update " surroundings {{{ nnoremap " ciw""" vnoremap " c""" nnoremap ' ciw'"' vnoremap ' c'"' nnoremap ( ciw(") vnoremap ( c(")`[ nnoremap < ciw<"> vnoremap < c<">`[ nnoremap > ciw<"> vnoremap > c<">`[ nnoremap ` ciw`"` vnoremap ` c`"``[ nnoremap * ciw*"* vnoremap * c*"*`[ nnoremap _ ciw_"_ vnoremap _ c_"_`[ "}}} " Clipboard copy and paste "{{{ noremap gg"+yG`` inoremap gg"+yGgi nnoremap "+yy vnoremap "+y inoremap "+yygi nnoremap "+p vnoremap "+p inoremap "+p`]a nnoremap g<С-Insert> "+yiw nnoremap g viw"+p "}}} " scrollers nnoremap nnoremap vnoremap vnoremap " redraws the screen and removes any search highlighting. nnoremap :nohl " Underline current line "{{{ nnoremap __ "zyy"zp$r- nnoremap ++ "zyy"zp$r= nnoremap ___ o78i- vnoremap ___ c78i- nnoremap +++ o78i= vnoremap +++ c78i= "}}} " find visually selected text vnoremap * y/" " wrap ON/OFF map :set wrap! wrap? map l :set list! list? " replace word under cursor map :%s/\<\>//gc nmap t :tabnew nmap v :e $MYVIMRC " run selected vimscript vmap r "vy:@v " run vimscript line nmap r "vyy:@v " I need this to test what the heck is going on in my set fdm=expr nmap f :echo 'Foldlevel:' foldlevel(line('.')) """ end of Misc keybindings }}} " Commands {{{ " remove trailing spaces command! RemoveTrailingSpaces :silent! %s/\v(\s+$)|(\r+$)//g \:exe 'normal ``' \:echo 'Remove trailing spaces and ^Ms.' " evaluate current line, save result into unnamed buffer " the next line without comment should echo -1 " 1+2-4 command! Eval let @"=eval(getline('.'))|echo @" " end of Commands }}} " Russian localization {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Russian keymap " Try C-6 to toggle keymaps in insert or search mode " set keymap=russian-jcukenwin " set iminsert=0 imsearch=0 " nmap a set langmap=йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ] set langmap+=фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э\' set langmap+=яz,чx,сc,мv,иb,тn,ьm,б\,,ю.,ё\' set langmap+=ЙQ,ЦW,УE,КR,ЕT,НY,ГU,ШI,ЩO,ЗP,Х\{,Ъ\} set langmap+=ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж\:,Э\" set langmap+=ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б\<,Ю\> " Encodings {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Меню выбора кодировки текста (koi8-r, cp1251, cp866, utf8) menu Encoding.cp866 :e ++enc=cp866 menu Encoding.windows-1251 :e ++enc=cp1251 menu Encoding.koi8-r :e ++enc=koi8-r menu Encoding.utf-8 :e ++enc=utf8 " set wildcharm= " map :emenu Encoding. """ end of Encodings }}} """ end of Russian localization }}} " Folding {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nofoldenable set foldminlines=1 foldlevel=1 " I want foldmarkers to be applied with space before a comment. noremap zf :set opfunc=MyFoldMarkerg@ vnoremap zf :call MyFoldMarker(visualmode(), 1) function! s:set_fold_markers(lnum_st, lnum_end) "{{{ let markers = split(&foldmarker, ",") function! s:set_line(ln, marker) "{{{ let cmnt = substitute(&commentstring, "%s", a:marker, "") let line = getline(a:ln) if line =~ '^\s*$' let space = '' else let space = ' ' endif let line = substitute(line, '\s*$', space, '').cmnt call setline(a:ln, line) endfunction "}}} call s:set_line(a:lnum_st, markers[0]) call s:set_line(a:lnum_end, markers[1]) endfunction "}}} function! MyFoldMarker(type, ...) "{{{ let sel_save = &selection let &selection = "inclusive" let reg_save = @@ if a:0 " Invoked from Visual mode, use '< and '> marks. call s:set_fold_markers("'<", "'>") elseif a:type == 'line' call s:set_fold_markers("'[", "']") elseif a:type == 'block' endif let &selection = sel_save let @@ = reg_save endfunction "}}} """ end of Folding }}} " Diff {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set diffopt+=vertical set diffexpr=MyDiff() function! MyDiff() "{{{ let opt = '-a --binary ' if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 = v:fname_new if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif let arg3 = v:fname_out if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif let eq = '' if $VIMRUNTIME =~ ' ' if &sh =~ '\ '.arg3.eq endfunction "}}} """ end of Diff }}} " Abbreviations {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" iab teh the iab tihs this iab todo: TODO: iab done: DONE: iab fixme: FIXME: iab fixed: FIXED: iab mmk Maxim Kim iab ммк Максим Ким " lorem ipsum inoreabbrev dolorem Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? inoreabbrev mdash  — inoreabbrev nbsp   inoreabbrev <<< < inoreabbrev >>> > " Insert Date Time iab idate =strftime("%Y-%m-%d %H:%M") """ end of Abbreviations }}} " Colors {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if has("gui_running") try " colorscheme manuscript colorscheme tundra catch set bg=light colorscheme default endtry else set bg=dark hi clear endif """ end of Colors }}} " Misc {{{ " Autoclose tags on html, xml, etc autocmd FileType html,xhtml,xml imap " Ctags let g:ctags_cmd = '"'.expand('~').'/ctags.exe"' command! Ctags silent execute '!'.g:ctags_cmd.' *.'.expand('%:e') " Do not highlight matching parens " let g:loaded_matchparen = 1 set mouse=a " End of Misc }}} " Plugins {{{ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Vimwiki {{{ let wiki = {} let wiki.path = '~/vimwiki/' let wiki.css_name = 'css/styles.css' let wiki.nested_syntaxes = { \ 'python': 'python', \ 'vim': 'vim', \ 'vb': 'vb', \ } let g:vimwiki_list = \ [wiki, \ {'path': '~/work/vimwiki_wiki/'}, \ {'path': '~/testwiki/', 'syntax': 'media'}] let g:vimwiki_menu = 'Plugin.Vimwiki' let g:vimwiki_w32_dir_enc = 'cp1251' let g:vimwiki_dir_link = 'index' let g:vimwiki_use_calendar = 1 let g:vimwiki_camel_case = 1 "}}} " Netrw {{{ let g:netrw_silent = 1 let g:netrw_keepdir = 0 let g:netrw_special_syntax = 1 let g:netrw_list_hide = "\.pyc$,\.swp$,\.bak$" let g:netrw_retmap = 1 nmap e :Explore "}}} " TOHtml {{{ let html_use_css = 1 let html_number_lines = 0 "}}} " NERDCommenter {{{ let NERDSpaceDelims = 1 "}}} " Calendar {{{ let g:calendar_navi_label = 'Пред,Сегодня,След' let g:calendar_mruler = 'Янв,Фев,Мар,Апр,Май,Июн,Июл,Авг,Сен,Окт,Ноя,Дек' let g:calendar_wruler = 'Вс Пн Вт Ср Чт Пт Сб' let g:calendar_monday = 1 "}}} " My Scripts {{{ " Check no more than 30 lines from start for 'Last Change:' and update it with " the current datetime. function! LastChangeUpdate() "{{{ for linenr in range(1, min([30, line('$')])) let line = getline(linenr) if line =~ 'Last Change:' let line = substitute(line, 'Last Change:.*$', \ 'Last Change: '.strftime("%Y-%m-%d %H:%M"), '') call setline(linenr, line) break endif endfor endfunction "}}} "}}} """ end of Plugins }}}