aboutsummaryrefslogtreecommitdiffstats
path: root/escape.vim
blob: a698ae03cea120f29e27ba546d6e340564d2d18e (plain)
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
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: March 15, 2011
" URL: http://peterodding.com/code/vim/misc/

" Convert a string into a :substitute pattern that matches the string literally.

function! xolox#misc#escape#pattern(string)
  if type(a:string) == type('')
    let string = escape(a:string, '^$.*\~[]')
    return substitute(string, '\n', '\\n', 'g')
  endif
  return ''
endfunction

" Convert a string into a :substitute replacement that inserts the string literally.

function! xolox#misc#escape#substitute(string)
  if type(a:string) == type('')
    let string = escape(a:string, '\&~%')
    return substitute(string, '\n', '\\r', 'g')
  endif
  return ''
endfunction

" vim: ts=2 sw=2 et