aboutsummaryrefslogtreecommitdiffstats
path: root/escape.vim
diff options
context:
space:
mode:
Diffstat (limited to 'escape.vim')
-rw-r--r--escape.vim26
1 files changed, 26 insertions, 0 deletions
diff --git a/escape.vim b/escape.vim
new file mode 100644
index 0000000..a698ae0
--- /dev/null
+++ b/escape.vim
@@ -0,0 +1,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