]> git.phdru.name Git - dotfiles.git/blob - .vimrc
b25ff63f9d891c1088edfe5d6110d9e1c475dea6
[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 set viminfo=!,h,'50
189 if version < 603
190    set viminfo+=\"1000
191 else
192    set viminfo+=<1000,s10
193 endif
194
195 " c - convert viminfo to the current encoding;
196 if has("iconv")
197    set viminfo+=c
198 endif
199
200 " Removable media paths
201 if has("win32")
202    set viminfo+=ra:,rb:
203 endif
204
205 " ----------
206
207 if has("gui_running")
208    set background=light
209
210    if has("win32")
211       "set guifont=Courier_New:h18:cRUSSIAN
212       set guifont=Lucida_Console:h18:cRUSSIAN
213    else
214       set guifont=Monospace\ 16
215       set toolbar=icons,text " how to show the toolbar
216    endif
217
218    set guicursor+=a:blinkon0 " Stop cursor blinking
219
220    " Make shift-insert work like in Xterm
221    " map <S-Insert> <MiddleMouse>
222    " map! <S-Insert> <MiddleMouse>
223
224    " ----------
225    " From http://slobin.pp.ru/vim/_vimrc.html
226
227    " Arrows should go into wrapped lines, but not while popup menu is visible
228    imap <expr> <Down> pumvisible() ? "<Down>" : "<C-O>gj"
229    imap <expr> <Up> pumvisible() ? "<Up>" : "<C-O>gk"
230
231    " The <CR> key should select from completion menu without adding a newline
232    imap <expr> <CR> pumvisible() ? "<C-Y>" : "<CR>"
233    " ----------
234
235 else
236    if (&term =~ "linux") || ($BACKGROUND == 'DARK') || ($BACKGROUND == 'dark')
237          \ || has("win32")
238       " Background of the terminal is black or dark grey
239       set background=dark
240    else
241       set background=light
242    endif
243
244    if (&term =~ "linux")
245       execute 'set t_kb=' . nr2char(127)
246    endif
247
248    if (&term =~ "rxvt") || (&term =~ "screen") || (&term =~ "term") || (&term =~ "vt100")
249       execute 'set t_kb=' . nr2char(127)
250
251       if has ("terminfo")
252          " set t_Co=256
253          set t_Co=16
254       else
255          set t_Co=8
256          set t_Sf="\e[3%dm"
257          set t_Sb="\e[4%dm"
258       endif
259
260       " 'autoselect' to always put selected text on the clipboard;
261       " 'unnamed' to use the * register like unnamed register '*'
262       " for all yank, delete and put operations;
263       " This allows to use mouse for copy/paste in local xterm,
264       " but prevents to save the unnamed register between sessions.
265       " set clipboard=autoselect,unnamed,exclude:cons\|linux
266
267       " Use xclip to copy/paste to/from X clipboard at remote host
268       " vmap "+y :!xclip -i -sel clip
269       " map "+p :r!xclip -o -sel clip
270       " Enable X11Forwarding and use ssh -X or even -Y
271    endif
272
273    if (&term =~ "screen")
274       set ttymouse=xterm2 " Enable mouse codes under screen/tmux
275       if empty(&t_ts)
276          " Enable window title under screen/tmux
277          let &t_ts = "\e]2;"
278          let &t_fs = "\007"
279       endif
280    endif
281
282    " Automatically set paste mode in Vim when pasting in bracketed paste mode
283    " https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode
284    function! WrapForTmux(s)
285      if !exists('$TMUX')
286        return a:s
287      endif
288
289      let tmux_start = "\<Esc>Ptmux;"
290      let tmux_end = "\<Esc>\\"
291
292      return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
293    endfunction
294
295    let &t_SI .= WrapForTmux("\<Esc>[?2004h")
296    let &t_EI .= WrapForTmux("\<Esc>[?2004l")
297
298    function! XTermPasteBegin()
299      set pastetoggle=<Esc>[201~
300      set paste
301      return ""
302    endfunction
303
304    inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
305 endif
306
307 " Multiline comments often confuse vim syntax highlighting - these maps
308 " allow to resynchronize; the first is faster, the second is more thorough
309 nmap \sc :syntax sync clear<Enter>
310 nmap \ss :syntax sync fromstart<Enter>
311
312
313 " AUTOCOMMANDS
314
315 " Enable filetype detection
316 filetype plugin indent on
317
318 runtime macros/matchit.vim
319
320 " Reread me after editing
321 autocmd BufWritePost ~/.vimrc source ~/.vimrc | syntax on
322
323 if version >= 700
324 " Save all files before running any quickfix command (grep, makeprg, etc.)
325 autocmd QuickFixCmdPre * wall
326 " automatically close quickfix if it's the only window left
327 autocmd WinEnter * if winnr('$') == 1 && 
328    \ index(["nofile", "quickfix"], &buftype) >= 0 | quit | endif
329 endif
330
331 " Syntax highlighting
332 autocmd BufReadPost * syntax on
333
334
335 " Restore last known cursor position
336 function! RestorePosition()
337    if exists('b:position_restored')
338       return
339    endif
340
341    if line("'\"") > 0
342       call cursor(line("'\""), col("'\""))
343    endif
344    let b:position_restored = 1
345 endfunction
346
347 " When editing a file, always jump to the last cursor position (if saved)
348 autocmd BufReadPost * call RestorePosition()
349
350
351 function! SetupEncoding(encoding)
352    if !has("iconv") || exists('b:encoding_set') || strlen(a:encoding) == 0
353       return
354    endif
355
356    call RestorePosition()
357    let b:encoding_set = 1
358    if len(expand('%'))
359       execute "edit ++enc=" . a:encoding
360    endif
361 endfunction
362
363
364 " From http://lwn.net/Articles/226514/
365
366 augroup gpg
367 " Remove ALL autocommands for the current group.
368 autocmd!
369 autocmd BufReadPre,FileReadPre *.gpg set viminfo=
370 autocmd BufReadPre,FileReadPre *.gpg setlocal noswapfile
371 autocmd BufReadPost *.gpg :%!gpg -q -d
372 autocmd BufReadPost *.gpg | redraw
373 autocmd BufWritePre *.gpg :%!gpg --default-recipient-self -q -e -a
374 autocmd BufWritePost *.gpg u
375 autocmd VimLeave *.gpg :!clear
376 " For OpenSSL:
377 " BufReadPost: use "openssl bf -d -a"
378 " BufWritePre: use "openssl bf -salt -a"
379 augroup END
380
381
382 function! SetWrap()
383    setlocal wrap
384    map <Up> gk
385    imap <Up> <C-O>gk
386    map <Down> gj
387    imap <Down> <C-O>gj
388    let b:wrap = 1
389 endfunction
390
391 function! SetNoWrap()
392    setlocal nowrap
393    map <Up> k
394    map <Down> j
395    let b:wrap = 0
396 endfunction
397
398 command! SetWrap call SetWrap()
399 command! SetNoWrap call SetNoWrap()
400
401 " b:wrap can be set by an ftplugin
402 autocmd BufReadPost * if !exists("b:wrap") | call SetWrap() | endif
403
404
405 " MAPPINGS
406
407 " Do not unindent #-comment
408 inoremap # X<C-H>#
409
410 " map <C-A> <Home>
411 " map <C-E> <End>
412 " map <C-Z> :shell<CR>
413
414
415 if version >= 700
416 " WEB BROWSERS
417
418 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"
419
420 function! ExtractURL()
421    let line = getline('.')
422    let parts = split(line, s:URL_re . '\zs')
423
424    if len(parts) == 0
425       throw 'ExtractURLCannotFindURL' " No URL found
426    endif
427
428    let length = 0
429    let column = col('.')
430
431    for p in parts
432       let save_length = length
433       let length += len(p)
434       if length >= column
435          break
436       endif
437    endfor
438
439    let pos = match(p, s:URL_re)
440    if pos == -1
441       throw 'ExtractURLCannotFindURL' " No URL found
442    endif
443
444    if save_length + pos >= column " cursor left of the URL
445       throw 'ExtractURLCannotFindURL'
446    endif
447
448    return strpart(p, pos)
449 endfunction
450
451 function! EscapeURL(url)
452    let url = substitute(a:url, ' ', '%20', 'g')
453    return escape(url, '!#$%')
454 endfunction
455
456 function! OpenURL(url, newwin)
457    execute "!webbrowser " . a:newwin . " '" . EscapeURL(a:url) . "'"
458 endfunction
459
460 function! ExtractOpenURL(newwin)
461    try
462       let url = ExtractURL()
463    catch /^ExtractURLCannotFindURL$/
464       echoerr 'No URL found under cursor'
465       return
466    endtry
467
468    call OpenURL(url, a:newwin)
469 endfunction
470
471 function! EncodeOpenURL(url, newwin)
472    execute "!webbrowser-encode-url " . a:newwin . " '" . EscapeURL(a:url) . "'"
473 endfunction
474
475
476 " Send current link to a browser
477 nmap \b :call ExtractOpenURL('')<CR>
478 nmap \w :call ExtractOpenURL('-n')<CR>
479 nmap \t :call ExtractOpenURL('-t')<CR>
480 " Send visual block to a browser
481 vmap \b ""y:call OpenURL('<C-R>"', '')<CR>
482 vmap \w ""y:call OpenURL('<C-R>"', '-n')<CR>
483 vmap \t ""y:call OpenURL('<C-R>"', '-t')<CR>
484 " Encode and send visual block to a browser
485 vmap \B ""y:call EncodeOpenURL('<C-R>"', '')<CR>
486 vmap \W ""y:call EncodeOpenURL('<C-R>"', '-n')<CR>
487 vmap \T ""y:call EncodeOpenURL('<C-R>"', '-t')<CR>
488 " Send current file's name to a browser
489 nmap \B :call EncodeOpenURL('file:' . expand("%:p"), '')<CR>
490 nmap \W :call EncodeOpenURL('file:' . expand("%:p"), '-n')<CR>
491 nmap \T :call EncodeOpenURL('file:' . expand("%:p"), '-t')<CR>
492
493 endif " version >= 700
494
495
496 " SPELLING
497
498 if has("spell") " Works in 7.0+
499    " Use builtin spellchecker
500    nmap \sv :syntax off <BAR> setlocal spell<CR>
501    " Clear
502    nmap \sn :syntax on <BAR> setlocal nospell<CR>
503 endif
504
505
506 " Russian letters mapped in normal mode
507 "if has("keymap")
508 "   set keymap=russian-jcuken
509 "endif
510
511 if has("langmap")
512    if v:version >= 702
513       " langmap in utf-8 mode requires at least Vim 7.2.109
514       scriptencoding utf-8
515       set langmap=ё`Ё~йqцwуeкrеtнyгuшiщoзpх[ъ]фaыsвdаfпgрhоjлkдlж\\;э'
516                  \яzчxсcмvиbтnьmб\\,ю.ЙQЦWУEКRЕTНYГUШIЩOЗPХ{Ъ}
517                  \ФAЫSВDАFПGРHОJЛKДLЖ:Э\\"ЯZЧXСCМVИBТNЬMБ<Ю>
518
519    elseif &encoding != 'utf-8'
520       scriptencoding koi8-r
521       set langmap=ё`Ё~йqцwуeкrеtнyгuшiщoзpх[ъ]фaыsвdаfпgрhоjлkдlж\\;э'
522                  \яzчxсcмvиbтnьmб\\,ю.ЙQЦWУEКRЕTНYГUШIЩOЗPХ{Ъ}
523                  \ФAЫSВDАFПGРHОJЛKДLЖ:Э\\"ЯZЧXСCМVИBТNЬMБ<Ю>
524    endif
525
526    scriptencoding us-ascii
527 endif
528
529
530 if version >= 700
531 function! W()
532    " let encodings=filter(split(&fileencodings, ','), 'v:val != "ucs-bom"')
533    let encodings = ['us-ascii']
534    if $LC_CTYPE =~ 'UTF-8' " UTF-8 or en_US.UTF-8 or ru_RU.UTF-8 or such
535       let encodings += ['utf-8']
536    elseif $LC_CTYPE == 'ru_RU.KOI8-R'
537       let encodings += ['koi8-r', 'utf-8']
538    elseif v:lc_time == 'Russian_Russia.1251'
539       let encodings += ['cp1251', 'utf-8']
540    endif
541
542    for e in encodings
543       try
544          execute 'set fileencoding=' . e
545          w
546          break
547       catch /E513: write error, conversion failed/
548          continue
549       endtry
550    endfor
551
552    if &modified
553       throw '"' . expand('%') . '" E513: write error, conversion failed; tried ' . join(encodings, ',')
554    elseif has("spell")
555       call SetupSpell()
556    endif
557 endfunction
558
559 command! W call W()
560 endif
561
562
563 function! SlowTerm()
564    set laststatus=1
565    set noruler
566    set shortmess=aoOtT
567    set noshowcmd
568    set scrolljump=5 " The minimal number of lines to scroll vertically when the cursor gets of the screen
569    set sidescroll=5
570    set nottyfast
571    set notitle
572    set timeoutlen=5000
573    set nowildmenu
574    set wildmode=list:longest
575    set viminfo=!,h,'10,<100,s5
576    if has("iconv")
577       set viminfo+=c
578    endif
579    syntax off
580    highlight NonText cterm=NONE ctermfg=NONE
581 endfunction
582
583 if exists("$SLOWTERM")
584    call SlowTerm()
585 endif
586
587
588 if has("python")
589 pyfile ~/.vim/python/virtualenv.py
590 endif
591
592 if has("python3")
593 py3file ~/.vim/python/virtualenv.py
594 endif
595
596
597 " From Tip 212:
598 " http://vim.fandom.com/wiki/Setting_file_attributes_without_reloading_a_buffer
599
600 if executable('chmod')
601    function! SetExecutableBit(x)
602       checktime
603       " Avoid 'Reload Y/N?' question
604       autocmd FileChangedShell <buffer> call _BufChangedCB()
605       let fx = executable(expand("%:p"))
606       if a:x && !fx
607          silent !chmod a+x %
608       elseif !a:x && fx
609          silent !chmod a-x %
610       endif
611       if v:shell_error
612          echoerr 'Error running chmod: ' . v:shell_error
613       endif
614       checktime
615    endfunction
616    function! _BufChangedCB()
617       autocmd! FileChangedShell <buffer>
618    endfunction
619    command! ToggleXbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
620 endif
621
622
623 " ----------
624 " From http://slobin.pp.ru/vim/_vimrc.html
625
626 " These options will be kept between editing sessions
627 " let options = []
628
629 " Called automagically after .viminfo and plugins are loaded, sets
630 " miscellaneous options from persistent global variables
631 " function! VimEnter()
632   " for optname in g:options
633   "   let varname = "g:OPT_" . toupper(optname)
634   "   if exists(varname)
635   "     execute "let &" . optname . " = " . varname
636   "   endif
637   " endfor
638
639   " if has("gui_running") && exists("g:WINPOSX") && exists("g:WINPOSY")
640   "   execute "winpos" g:WINPOSX g:WINPOSY
641   " endif
642 " endfunction
643
644 " Called automagically before .viminfo is saved, saves miscellaneous
645 " options into persistent global variables
646 " function! VimLeavePre()
647   " call filter(g:, 'v:key !~# "^OPT_"')
648   " for optname in g:options
649   "   let varname = "g:OPT_" . toupper(optname)
650   "   execute "let " . varname . " = &g:" . optname
651   " endfor
652
653   " if has("gui_running")
654   "   let g:WINPOSX = getwinposx()
655   "   let g:WINPOSY = getwinposy()
656   " endif
657 " endfunction
658
659 " autocmd VimEnter * call VimEnter()
660 " autocmd VimLeavePre * call VimLeavePre()
661
662
663 " Called automagically after every buffer read, enables fileencoding
664 " setting from modeline (see Tip #911:
665 " http://vim.fandom.com/wiki/How_to_make_fileencoding_work_in_the_modeline)
666 function! AutoEncoding()
667   if &modified && &fileencoding != ""
668     call SetupEncoding(&fileencoding)
669   else
670     redraw
671   endif
672   autocmd! auto-encoding
673   augroup! auto-encoding
674 endfunction
675
676 augroup auto-encoding
677 autocmd!
678 autocmd BufWinEnter * call AutoEncoding()
679 augroup END
680
681
682 let CONVERT=1
683
684 " Value of a character under cursor; better than standard '0x%02B (%b)'
685 function! HexDec()
686   let char = matchstr(getline("."), ".", col(".") - 1)
687   if g:CONVERT
688     let char = iconv(char, &encoding, &fileencoding)
689     let format = "0x%02X <%d>"
690   else
691     let format = "0x%02X (%d)"
692   endif
693   let char = char2nr(char)
694   return printf(format, char, char)
695 endfunction
696
697
698 if has("iconv")
699    " Helper function for :DecodeQP and :DecodeURL commands
700    function! DecodeHex(arg)
701      return iconv(printf("%c", str2nr(submatch(1), 16)), a:arg, &encoding)
702    endfunction
703
704    " Custom completion for encoding names
705    function! EncList(ArgLead, CmdLine, CursorPos)
706      return filter(split(&fileencodings, ','),
707                  \ "strpart(v:val, 0, strlen(a:ArgLead)) == a:ArgLead")
708    endfunction
709
710    if version >= 700
711    " Command for decoding qp-encoded text
712    command! -bar -nargs=? -range -complete=customlist,EncList DecodeQP
713           \ <line1>,<line2>s/=\(\x\x\|\n\)/\=DecodeHex(<q-args>)/eg
714
715    " Command for decoding url-encoded text
716    command! -bar -nargs=? -range -complete=customlist,EncList DecodeURL
717           \ <line1>,<line2>s/%\(\x\x\)/\=DecodeHex(<q-args>)/eg
718    endif
719 endif
720
721
722 if has("spell")
723    function! SetupSpell()
724       if &fileencoding =~ 'ascii'
725          setlocal spelllang=en spellfile=~/.vim/spell/en.ascii.add
726       elseif &fileencoding == 'koi8-r'
727          setlocal spelllang=en,ru spellfile=~/.vim/spell/en.ascii.add,~/.vim/spell/ru.koi8-r.add
728       elseif &fileencoding == 'utf-8'
729          setlocal spelllang=en,ru spellfile=~/.vim/spell/en.ascii.add,~/.vim/spell/ru.utf-8.add
730       else
731          setlocal spelllang= spellfile=
732       endif
733    endfunction
734    autocmd BufReadPost * call SetupSpell()
735 endif
736
737
738 function! SyntaxName()
739   echomsg synIDattr(synID(line("."), col("."), 1), "name")
740 endfunction
741
742
743 if has("python")
744 pyfile ~/.vim/python/completion.py
745
746 " Custom completion for python expressions
747 function! CompList(ArgLead, CmdLine, CursorPos)
748   python vim_comp_list()
749 endfunction
750
751 " Python command line calculator
752 command! -nargs=+ -range -complete=customlist,CompList Calc
753        \ <line1>,<line2> python vim_calc(<q-args>)
754
755 " Python text range filter
756 command! -nargs=+ -range -complete=customlist,CompList Pydo
757        \ <line1>,<line2> python vim_pydo(<q-args>)
758
759 " Display unicode name for the character under cursor
760 command! Uname python vim_unicode_name()
761 endif
762
763 if has("python3")
764 py3file ~/.vim/python/completion.py
765
766 " Custom completion for python expressions
767 function! CompList(ArgLead, CmdLine, CursorPos)
768   python3 vim_comp_list()
769 endfunction
770
771 " Python command line calculator
772 command! -nargs=+ -range -complete=customlist,CompList Calc
773        \ <line1>,<line2> python3 vim_calc(<q-args>)
774
775 " Python text range filter
776 command! -nargs=+ -range -complete=customlist,CompList Pydo
777        \ <line1>,<line2> python3 vim_pydo(<q-args>)
778
779 " Display unicode name for the character under cursor
780 command! Uname python3 vim_unicode_name()
781 endif
782
783 if has("python") || has("python3")
784 command! UName Uname
785 endif
786 " ----------
787
788 if has("iconv")
789 function! SetViminfoEncoding()
790    " Set universal encoding for .viminfo
791    if &encoding != 'utf-8'
792       set encoding=utf-8
793    endif
794 endfunction
795 autocmd VimLeavePre * call SetViminfoEncoding()
796 endif
797
798 " This has to go to the very end of ~/.vimrc to allow reading the .vimrc
799 set secure        " safer working with script files in the current directory