-
Notifications
You must be signed in to change notification settings - Fork 4
/
rx.vim
38 lines (34 loc) · 1.03 KB
/
rx.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
" rx.vim
" @Author: Thomas Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-07-20.
" @Last Change: 2007-11-23.
" @Revision: 0.0.15
if &cp || exists("loaded_tlib_rx_autoload")
finish
endif
let loaded_tlib_rx_autoload = 1
" :def: function! tlib#rx#Escape(text, ?magic='m')
" magic can be one of: m, M, v, V
" See :help 'magic'
function! tlib#rx#Escape(text, ...) "{{{3
TVarArg 'magic'
if empty(magic)
let magic = 'm'
endif
if magic ==# 'm'
return escape(a:text, '^$.*\[]~')
elseif magic ==# 'M'
" echoerr 'tlib: Unsupported magic type'
return escape(a:text, '^$\')
elseif magic ==# 'V'
return escape(a:text, '\')
elseif magic ==# 'v'
" let chars = '^$.*+\()|{}[]~'
return substitute(a:text, '[^0-9a-zA-Z_]', '\\&', 'g')
else
echoerr 'tlib: Unsupported magic type'
return a:text
endif
endf