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