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