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