]> git.phdru.name Git - dotfiles.git/blob - .vimrc
.vimrc: Exit vim if the only window is option window
[dotfiles.git] / .vimrc
1 " User configuration file for Vi IMproved.
2 "
3 " vim 6.0+ required, 7.0+ recommended.
4
5 " 1 important
6
7 " Remove ALL autocommands in case the file is sourced for the second time
8 autocmd!
9
10 language messages C " Print messages in English
11
12 if exists("b:wrap") " Only do this on the second and subsequent :source's
13    let fenc = &fileencoding
14    let ftype = &filetype
15    let mod = &modified
16    set all& " Reset all options, except terminal options, to their default value.
17    execute 'set fileencoding=' . fenc
18    execute 'set filetype=' . ftype
19    if mod
20       set modified
21    else
22       set nomodified
23    endif
24    unlet fenc ftype mod
25 endif
26
27 " No, it is not VI, it is VIM! It is important to set this first, because this
28 " command resets many other options.
29 set nocompatible
30
31 " Set behavior to xterm, not mswin
32 behave xterm
33
34 " 2 moving around, searching and patterns
35
36 set ignorecase    " Ignore case in search patterns
37 set smartcase     " Match 'word' case-insensitive and 'Word' case-sensitive
38
39 set nostartofline " Keep cursor's column
40 set whichwrap=b,s,h,l,<,>,[,],~ " Wrap to the previous/next line on all keys and ~ command
41
42 " 4 displaying text
43
44 set display=lastline,uhex " Show the last line instead of '@'; show non-printable chars as <hex>
45 set lazyredraw    " Do not update screen while executing macros
46 set list          " listchars only works with 'list'
47 " Show tabs, non-breaking/trailing spaces, long lines
48 set listchars=tab:>_,nbsp:_,trail:_,extends:+,precedes:+
49 " Another usefull additions: eol:$,space:_
50 set wrap          " Visually wrap long lines
51
52 " With 'set wrap' wrap long lines at a character in 'breakat'
53 " Please note 'nolist' is required to use 'linebreak'
54 set linebreak showbreak=+\ " A plus and a space
55
56 set sidescroll=1  " The minimal number of columns to scroll horizontally
57
58 " 5 highlighting
59
60 colorscheme phd
61 set nohlsearch    " Stop the search highlighting
62
63 " 6 multiple windows
64
65 set hidden        " Don't unload a buffer when no longer shown in a window; allow to switch between buffers/windows when the buffer is modified
66 set laststatus=2  " Always show status line
67
68 set splitbelow    " A new window is put below of the current one
69 set splitright    " A new window is put right of the current one
70
71 " 8 terminal
72
73 set ttyfast       " terminal connection is fast
74
75 set title         " Set title to the value of 'titlestring' or to 'filename - VIM'
76 set titleold=     " string to restore the title to when exiting Vim
77 " String to use for the Vim window title; with statusline printf items:
78 " display filename, modification flag, full path, argument list status,
79 " the current user, host and program name (to distinguish vim/view/etc).
80 set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)\ -\ [%{$USER}@%{hostname()}]\ %{v:progname}
81
82 " 9 using the mouse
83
84 set mouse=ar      " Use mouse in all modes, plus hit-return
85
86 " 12 messages and info
87
88 set ruler         " Show cursor position below each window
89 set showcmd       " Show (partial) command keys in the status line
90
91 " Short message for [Modified];
92 " overwrite message for writing a file with subsequent message;
93 " truncate long file messages
94 set shortmess=mot
95
96 " 14 editing text
97
98 set backspace=indent,eol,start
99 set complete+=k   " Scan spell dictionaries for completion in addition to standard places
100 set infercase     " adjust case of a keyword completion match
101 set nojoinspaces  " Do not insert two spaces after a '.', '?' and '!' with a join command
102 set nrformats=hex " I seldom edit octal numbers, but very often dates like 2001-02-01
103
104 " Default value 'croql' is a compromise for both natural and programming
105 " languages, but as any compromise it works good for neither natural nor
106 " programming languages. This value is good for natural texts,
107 " let ftplugins to set values suitable for programming languages.
108 set formatoptions=2t " list of flags that tell how automatic formatting works
109
110 " 15 tabs and indenting
111
112 set expandtab     " expand <Tab> to spaces in Insert mode
113 set shiftwidth=3  " number of spaces used for each step of (auto)indent
114 set smarttab      " a <Tab> in an indent inserts 'shiftwidth' spaces
115 set softtabstop=3 " number of spaces to insert for a <Tab>
116
117 set noautoindent  " Do not automatically set the indent of a new line
118
119 " 18 mapping
120
121 set timeout timeoutlen=3000 ttimeoutlen=100 " allow timing out up to 3 seconds halfway into a mapping; 100 ms to wait for a key code or mapped key sequence to complete
122
123 " 19 reading and writing files
124 if v:version >= 703
125    set cryptmethod=blowfish " encryption method for file writing: zip or blowfish
126 endif
127
128 " 20 the swap file
129
130 let myUndoDir = expand('~/tmp/vim/undo')
131 if !isdirectory(myUndoDir)
132     " Create dirs
133     call mkdir(myUndoDir, 'p')
134 endif
135
136 " list of directories for the swap file; remove . (the current directory)
137 if has("win32")
138    set directory=~/tmp/vim//,$TEMP//,c:/tmp//,c:/temp//
139 else
140    set directory=~/tmp/vim//,~/tmp//,/var/tmp//,/tmp//
141 endif
142 " if a directory ends in two path separators "//"
143 " or "\\", the swap file name will be built from the complete path to
144 " the file with all path separators substituted to percent '%' signs.
145 " This will ensure file name uniqueness in the preserve directory.
146
147 " 21 command line editing
148
149 set history=1000  " how many command lines are remembered
150 set suffixes+=.pyc,.pyo " list of file name extensions that have a lower priority
151 set wildignore+=*.py[co] " Ignore these patterns when completing file names
152 set wildmenu      " command-line completion shows a list of matches
153 set wildmode=longest,list:longest,full " Bash-vim completion behavior
154
155 " Keep undo history across sessions by storing it in a file
156 if has('persistent_undo')
157     let &undodir = myUndoDir
158     set undofile
159 endif
160
161 " 22 executing external commands
162
163 if has("filterpipe")
164    set noshelltemp " Use pipes on Unix
165 endif
166
167 " 25 multi-byte characters
168
169 " Automatically detected character encodings
170 set fileencodings=ucs-bom,us-ascii,utf-8,koi8-r,cp1251,cp866,latin1
171
172 " 26 various
173
174 " ! - when included, save and restore global variables that start
175 "     with an uppercase letter, and don't contain a lowercase letter;
176 " h - disable the effect of 'hlsearch';
177 " ' - number of files for which the marks are remembered;
178 " " and < - maximum number of lines saved for a register;
179 " s - maximum size of an item in Kbytes.
180 if version < 603
181    set viminfo=!,h,'50,\"1000
182 else
183    set viminfo=!,h,'50,<1000,s10
184 endif
185
186 " c - convert viminfo to the current encoding;
187 if has("iconv")
188    set viminfo^=c
189 endif
190
191 " Removable media paths
192 if has("win32")
193    set viminfo+=ra:,rb:
194 endif
195
196 " ----------
197
198 if has("gui_running")
199    set background=light
200
201    if has("win32")
202       "set guifont=Courier_New:h18:cRUSSIAN
203       set guifont=Lucida_Console:h18:cRUSSIAN
204    else
205       set guifont=Monospace\ 16
206       set toolbar=icons,text " how to show the toolbar
207    endif
208
209    set guicursor+=a:blinkon0 " Stop cursor blinking
210
211    " Make shift-insert work like in Xterm
212    " map <S-Insert> <MiddleMouse>
213    " map! <S-Insert> <MiddleMouse>
214
215    " ----------
216    " From http://slobin.pp.ru/vim/_vimrc.html
217
218    " Arrows should go into wrapped lines, but not while popup menu is visible
219    imap <expr> <Down> pumvisible() ? "<Down>" : "<C-O>gj"
220    imap <expr> <Up> pumvisible() ? "<Up>" : "<C-O>gk"
221
222    " The <CR> key should select from completion menu without adding a newline
223    imap <expr> <CR> pumvisible() ? "<C-Y>" : "<CR>"
224    " ----------
225
226 else
227    if (&term =~ "linux") || ($BACKGROUND == 'DARK') || ($BACKGROUND == 'dark')
228          \ || has("win32")
229       " Background of the terminal is black or dark grey
230       set background=dark
231    else
232       set background=light
233    endif
234
235    if (&term =~ "linux")
236       execute 'set t_kb=' . nr2char(127)
237    endif
238
239    if (&term =~ "rxvt") || (&term =~ "screen") || (&term =~ "term") || (&term =~ "vt100")
240       execute 'set t_kb=' . nr2char(127)
241
242       if has ("terminfo")
243          " set t_Co=256
244          set t_Co=16
245       else
246          set t_Co=8
247          set t_Sf="\e[3%dm"
248          set t_Sb="\e[4%dm"
249       endif
250
251       " 'autoselect' to always put selected text on the clipboard;
252       " 'unnamed' to use the * register like unnamed register '*'
253       " for all yank, delete and put operations;
254       " This allows to use mouse for copy/paste in local xterm,
255       " but prevents to save the unnamed register between sessions.
256       " set clipboard=autoselect,unnamed,exclude:cons\|linux
257
258       " Use xclip to copy/paste to/from X clipboard at remote host
259       " vmap "+y :!xclip -i -sel clip
260       " map "+p :r!xclip -o -sel clip
261       " Enable X11Forwarding and use ssh -X or even -Y
262    endif
263
264    if (&term =~ "screen")
265       set ttymouse=xterm2 " Enable mouse codes under screen/tmux
266       if empty(&t_ts)
267          " Enable window title under screen/tmux
268          let &t_ts = "\e]2;"
269          let &t_fs = "\007"
270       endif
271    endif
272
273    " Automatically set paste mode in Vim when pasting in bracketed paste mode
274    " https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode
275    function! WrapForTmux(s)
276      if !exists('$TMUX')
277        return a:s
278      endif
279
280      let tmux_start = "\<Esc>Ptmux;"
281      let tmux_end = "\<Esc>\\"
282
283      return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
284    endfunction
285
286    let &t_SI .= WrapForTmux("\<Esc>[?2004h")
287    let &t_EI .= WrapForTmux("\<Esc>[?2004l")
288
289    function! XTermPasteBegin()
290      set pastetoggle=<Esc>[201~
291      set paste
292      return ""
293    endfunction
294
295    inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
296 endif
297
298 " Multiline comments often confuse vim syntax highlighting - these maps
299 " allow to resynchronize; the first is faster, the second is more thorough
300 nmap \sc :syntax sync clear<Enter>
301 nmap \ss :syntax sync fromstart<Enter>
302
303
304 " AUTOCOMMANDS
305
306 " Enable filetype detection
307 filetype plugin indent on
308
309 runtime macros/matchit.vim
310
311 " Reread me after editing
312 autocmd BufWritePost ~/.vimrc source ~/.vimrc | syntax on
313
314 if version >= 700
315 " Save all files before running any quickfix command (grep, makeprg, etc.)
316 autocmd QuickFixCmdPre * wall
317 " automatically close quickfix if it's the only window left
318 autocmd WinEnter * if winnr('$') == 1 && 
319    \ index(["nofile", "quickfix"], &buftype) >= 0 | quit | endif
320 endif
321
322 " Syntax highlighting
323 autocmd BufReadPost * syntax on
324
325
326 " Restore last known cursor position
327 function! RestorePosition()
328    if exists('b:position_restored')
329       return
330    endif
331
332    if line("'\"") > 0
333       call cursor(line("'\""), col("'\""))
334    endif
335    let b:position_restored = 1
336 endfunction
337
338 " When editing a file, always jump to the last cursor position (if saved)
339 autocmd BufReadPost * call RestorePosition()
340
341
342 function! SetupEncoding(encoding)
343    if !has("iconv") || exists('b:encoding_set') || strlen(a:encoding) == 0
344       return
345    endif
346
347    call RestorePosition()
348    let b:encoding_set = 1
349    if len(expand('%'))
350       execute "edit ++enc=" . a:encoding
351    endif
352 endfunction
353
354
355 " From http://lwn.net/Articles/226514/
356
357 augroup gpg
358 " Remove ALL autocommands for the current group.
359 autocmd!
360 autocmd BufReadPre,FileReadPre *.gpg set viminfo=
361 autocmd BufReadPre,FileReadPre *.gpg setlocal noswapfile
362 autocmd BufReadPost *.gpg :%!gpg -q -d
363 autocmd BufReadPost *.gpg | redraw
364 autocmd BufWritePre *.gpg :%!gpg --default-recipient-self -q -e -a
365 autocmd BufWritePost *.gpg u
366 autocmd VimLeave *.gpg :!clear
367 " For OpenSSL:
368 " BufReadPost: use "openssl bf -d -a"
369 " BufWritePre: use "openssl bf -salt -a"
370 augroup END
371
372
373 function! SetWrap()
374    setlocal wrap
375    map <Up> gk
376    imap <Up> <C-O>gk
377    map <Down> gj
378    imap <Down> <C-O>gj
379    let b:wrap = 1
380 endfunction
381
382 function! SetNoWrap()
383    setlocal nowrap
384    map <Up> k
385    map <Down> j
386    let b:wrap = 0
387 endfunction
388
389 command! SetWrap call SetWrap()
390 command! SetNoWrap call SetNoWrap()
391
392 " b:wrap can be set by an ftplugin
393 autocmd BufReadPost * if !exists("b:wrap") | call SetWrap() | endif
394
395
396 " MAPPINGS
397
398 " Do not unindent #-comment
399 inoremap # X<C-H>#
400
401 " map <C-A> <Home>
402 " map <C-E> <End>
403 " map <C-Z> :shell<CR>
404
405
406 if version >= 700
407 " WEB BROWSERS
408
409 let s:URL_re="\\v(((https?|ftp|gopher|telnet)://|(mailto|file|news|about|ed2k|irc|sip|magnet):)[^' \t<>\"]+|(www|web|w3)[a-z0-9_-]*\\.[a-z0-9._-]+\\.[^' \t<>\"]+)[a-z0-9/]\\c"
410
411 function! ExtractURL()
412    let line = getline('.')
413    let parts = split(line, s:URL_re . '\zs')
414
415    if len(parts) == 0
416       throw 'ExtractURLCannotFindURL' " No URL found
417    endif
418
419    let length = 0
420    let column = col('.')
421
422    for p in parts
423       let save_length = length
424       let length += len(p)
425       if length >= column
426          break
427       endif
428    endfor
429
430    let pos = match(p, s:URL_re)
431    if pos == -1
432       throw 'ExtractURLCannotFindURL' " No URL found
433    endif
434
435    if save_length + pos >= column " cursor left of the URL
436       throw 'ExtractURLCannotFindURL'
437    endif
438
439    return strpart(p, pos)
440 endfunction
441
442 function! EscapeURL(url)
443    let url = substitute(a:url, ' ', '%20', 'g')
444    return escape(url, '!#$%')
445 endfunction
446
447 function! OpenURL(url, newwin)
448    execute "!webbrowser " . a:newwin . " '" . EscapeURL(a:url) . "'"
449 endfunction
450
451 function! ExtractOpenURL(newwin)
452    try
453       let url = ExtractURL()
454    catch /^ExtractURLCannotFindURL$/
455       echoerr 'No URL found under cursor'
456       return
457    endtry
458
459    call OpenURL(url, a:newwin)
460 endfunction
461
462 function! EncodeOpenURL(url, newwin)
463    execute "!webbrowser-encode-url " . a:newwin . " '" . EscapeURL(a:url) . "'"
464 endfunction
465
466
467 " Send current link to a browser
468 nmap \b :call ExtractOpenURL('')<CR>
469 nmap \w :call ExtractOpenURL('-n')<CR>
470 nmap \t :call ExtractOpenURL('-t')<CR>
471 " Send visual block to a browser
472 vmap \b ""y:call OpenURL('<C-R>"', '')<CR>
473 vmap \w ""y:call OpenURL('<C-R>"', '-n')<CR>
474 vmap \t ""y:call OpenURL('<C-R>"', '-t')<CR>
475 " Encode and send visual block to a browser
476 vmap \B ""y:call EncodeOpenURL('<C-R>"', '')<CR>
477 vmap \W ""y:call EncodeOpenURL('<C-R>"', '-n')<CR>
478 vmap \T ""y:call EncodeOpenURL('<C-R>"', '-t')<CR>
479 " Send current file's name to a browser
480 nmap \B :call EncodeOpenURL('file:' . expand("%:p"), '')<CR>
481 nmap \W :call EncodeOpenURL('file:' . expand("%:p"), '-n')<CR>
482 nmap \T :call EncodeOpenURL('file:' . expand("%:p"), '-t')<CR>
483
484 endif " version >= 700
485
486
487 " SPELLING
488
489 if has("spell") " Works in 7.0+
490    " Use builtin spellchecker
491    nmap \sv :syntax off <BAR> setlocal spell<CR>
492    " Clear
493    nmap \sn :syntax on <BAR> setlocal nospell<CR>
494 endif
495
496
497 " Russian letters mapped in normal mode
498 "if has("keymap")
499 "   set keymap=russian-jcuken
500 "endif
501
502 if has("langmap")
503    if v:version >= 702
504       " langmap in utf-8 mode requires at least Vim 7.2.109
505       scriptencoding utf-8
506       set langmap=ё`Ё~йqцwуeкrеtнyгuшiщoзpх[ъ]фaыsвdаfпgрhоjлkдlж\\;э'
507                  \яzчxсcмvиbтnьmб\\,ю.ЙQЦWУEКRЕTНYГUШIЩOЗPХ{Ъ}
508                  \ФAЫSВDАFПGРHОJЛKДLЖ:Э\\"ЯZЧXСCМVИBТNЬMБ<Ю>
509
510    elseif &encoding != 'utf-8'
511       scriptencoding koi8-r
512       set langmap=ё`Ё~йqцwуeкrеtнyгuшiщoзpх[ъ]фaыsвdаfпgрhоjлkдlж\\;э'
513                  \яzчxсcмvиbтnьmб\\,ю.ЙQЦWУEКRЕTНYГUШIЩOЗPХ{Ъ}
514                  \ФAЫSВDАFПGРHОJЛKДLЖ:Э\\"ЯZЧXСCМVИBТNЬMБ<Ю>
515    endif
516
517    scriptencoding us-ascii
518 endif
519
520
521 if version >= 700
522 function! W()
523    " let encodings=filter(split(&fileencodings, ','), 'v:val != "ucs-bom"')
524    let encodings = ['us-ascii']
525    if $LC_CTYPE =~ 'UTF-8' " UTF-8 or en_US.UTF-8 or ru_RU.UTF-8 or such
526       let encodings += ['utf-8']
527    elseif $LC_CTYPE == 'ru_RU.KOI8-R'
528       let encodings += ['koi8-r', 'utf-8']
529    elseif v:lc_time == 'Russian_Russia.1251'
530       let encodings += ['cp1251', 'utf-8']
531    endif
532
533    for e in encodings
534       try
535          execute 'set fileencoding=' . e
536          w
537          break
538       catch /E513: write error, conversion failed/
539          continue
540       endtry
541    endfor
542
543    if &modified
544       throw '"' . expand('%') . '" E513: write error, conversion failed; tried ' . join(encodings, ',')
545    elseif has("spell")
546       call SetupSpell()
547    endif
548 endfunction
549
550 command! W call W()
551 endif
552
553
554 function! SlowTerm()
555    set laststatus=1
556    set noruler
557    set shortmess=aoOtT
558    set noshowcmd
559    set scrolljump=5 " The minimal number of lines to scroll vertically when the cursor gets of the screen
560    set sidescroll=5
561    set nottyfast
562    set notitle
563    set timeoutlen=5000
564    set nowildmenu
565    set wildmode=list:longest
566    set viminfo=!,h,'10,<100,s5
567    syntax off
568    highlight NonText cterm=NONE ctermfg=NONE
569 endfunction
570
571 if exists("$SLOWTERM")
572    call SlowTerm()
573 endif
574
575
576 if has("python")
577 pyfile ~/.vim/python/virtualenv.py
578 endif
579
580 if has("python3")
581 py3file ~/.vim/python/virtualenv.py
582 endif
583
584
585 " From Tip 212:
586 " http://vim.wikia.com/wiki/Setting_file_attributes_without_reloading_a_buffer
587
588 if executable('chmod')
589    function! SetExecutableBit(x)
590       checktime
591       " Avoid 'Reload Y/N?' question
592       autocmd FileChangedShell <buffer> call _BufChangedCB()
593       let fx = executable(expand("%:p"))
594       if a:x && !fx
595          silent !chmod a+x %
596       elseif !a:x && fx
597          silent !chmod a-x %
598       endif
599       if v:shell_error
600          echoerr 'Error running chmod: ' . v:shell_error
601       endif
602       checktime
603    endfunction
604    function! _BufChangedCB()
605       autocmd! FileChangedShell <buffer>
606    endfunction
607    command! ToggleXbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
608 endif
609
610
611 " ----------
612 " From http://slobin.pp.ru/vim/_vimrc.html
613
614 " These options will be kept between editing sessions
615 " let options = []
616
617 " Called automagically after .viminfo and plugins are loaded, sets
618 " miscellaneous options from persistent global variables
619 " function! VimEnter()
620   " for optname in g:options
621   "   let varname = "g:OPT_" . toupper(optname)
622   "   if exists(varname)
623   "     execute "let &" . optname . " = " . varname
624   "   endif
625   " endfor
626
627   " if has("gui_running") && exists("g:WINPOSX") && exists("g:WINPOSY")
628   "   execute "winpos" g:WINPOSX g:WINPOSY
629   " endif
630 " endfunction
631
632 " Called automagically before .viminfo is saved, saves miscellaneous
633 " options into persistent global variables
634 " function! VimLeavePre()
635   " call filter(g:, 'v:key !~# "^OPT_"')
636   " for optname in g:options
637   "   let varname = "g:OPT_" . toupper(optname)
638   "   execute "let " . varname . " = &g:" . optname
639   " endfor
640
641   " if has("gui_running")
642   "   let g:WINPOSX = getwinposx()
643   "   let g:WINPOSY = getwinposy()
644   " endif
645 " endfunction
646
647 " autocmd VimEnter * call VimEnter()
648 " autocmd VimLeavePre * call VimLeavePre()
649
650
651 " Called automagically after every buffer read, enables fileencoding
652 " setting from modeline (see Tip #911:
653 " http://vim.wikia.com/wiki/How_to_make_fileencoding_work_in_the_modeline)
654 function! AutoEncoding()
655   if &modified && &fileencoding != ""
656     call SetupEncoding(&fileencoding)
657   else
658     redraw
659   endif
660   autocmd! auto-encoding
661   augroup! auto-encoding
662 endfunction
663
664 augroup auto-encoding
665 autocmd!
666 autocmd BufWinEnter * call AutoEncoding()
667 augroup END
668
669
670 let CONVERT=1
671
672 " Value of a character under cursor; better than standard '0x%02B (%b)'
673 function! HexDec()
674   let char = matchstr(getline("."), ".", col(".") - 1)
675   if g:CONVERT
676     let char = iconv(char, &encoding, &fileencoding)
677     let format = "0x%02X <%d>"
678   else
679     let format = "0x%02X (%d)"
680   endif
681   let char = char2nr(char)
682   return printf(format, char, char)
683 endfunction
684
685
686 if has("iconv")
687    " Helper function for :DecodeQP and :DecodeURL commands
688    function! DecodeHex(arg)
689      return iconv(printf("%c", str2nr(submatch(1), 16)), a:arg, &encoding)
690    endfunction
691
692    " Custom completion for encoding names
693    function! EncList(ArgLead, CmdLine, CursorPos)
694      return filter(split(&fileencodings, ','),
695                  \ "strpart(v:val, 0, strlen(a:ArgLead)) == a:ArgLead")
696    endfunction
697
698    if version >= 700
699    " Command for decoding qp-encoded text
700    command! -bar -nargs=? -range -complete=customlist,EncList DecodeQP
701           \ <line1>,<line2>s/=\(\x\x\|\n\)/\=DecodeHex(<q-args>)/eg
702
703    " Command for decoding url-encoded text
704    command! -bar -nargs=? -range -complete=customlist,EncList DecodeURL
705           \ <line1>,<line2>s/%\(\x\x\)/\=DecodeHex(<q-args>)/eg
706    endif
707 endif
708
709
710 if has("spell")
711    function! SetupSpell()
712       if &fileencoding =~ 'ascii'
713          setlocal spelllang=en spellfile=~/.vim/spell/en.ascii.add
714       elseif &fileencoding == 'koi8-r'
715          setlocal spelllang=en,ru spellfile=~/.vim/spell/en.ascii.add,~/.vim/spell/ru.koi8-r.add
716       elseif &fileencoding == 'utf-8'
717          setlocal spelllang=en,ru spellfile=~/.vim/spell/en.ascii.add,~/.vim/spell/ru.utf-8.add
718       else
719          setlocal spelllang= spellfile=
720       endif
721    endfunction
722    autocmd BufReadPost * call SetupSpell()
723 endif
724
725
726 function! SyntaxName()
727   echomsg synIDattr(synID(line("."), col("."), 1), "name")
728 endfunction
729
730
731 if has("python")
732 pyfile ~/.vim/python/completion.py
733
734 " Custom completion for python expressions
735 function! CompList(ArgLead, CmdLine, CursorPos)
736   python vim_comp_list()
737 endfunction
738
739 " Python command line calculator
740 command! -nargs=+ -range -complete=customlist,CompList Calc
741        \ <line1>,<line2> python vim_calc(<q-args>)
742
743 " Python text range filter
744 command! -nargs=+ -range -complete=customlist,CompList Pydo
745        \ <line1>,<line2> python vim_pydo(<q-args>)
746
747 " Display unicode name for the character under cursor
748 command! Uname python vim_unicode_name()
749 endif
750
751 if has("python3")
752 py3file ~/.vim/python/completion.py
753
754 " Custom completion for python expressions
755 function! CompList(ArgLead, CmdLine, CursorPos)
756   python3 vim_comp_list()
757 endfunction
758
759 " Python command line calculator
760 command! -nargs=+ -range -complete=customlist,CompList Calc
761        \ <line1>,<line2> python3 vim_calc(<q-args>)
762
763 " Python text range filter
764 command! -nargs=+ -range -complete=customlist,CompList Pydo
765        \ <line1>,<line2> python3 vim_pydo(<q-args>)
766
767 " Display unicode name for the character under cursor
768 command! Uname python3 vim_unicode_name()
769 endif
770
771 if has("python") || has("python3")
772 command! UName Uname
773 endif
774 " ----------
775
776 " This has to go to the very end of ~/.vimrc to allow reading the .vimrc
777 set secure        " safer working with script files in the current directory