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