aboutsummaryrefslogtreecommitdiffstats
path: root/escape.vim
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2011-03-15 23:00:55 +0100
committerPeter Odding <peter@peterodding.com>2011-03-15 23:00:55 +0100
commita205f918f5797d9183f7f479360ed91bbce2b388 (patch)
treed2cf19205d9cd875a463b6835cd249cd183f9d28 /escape.vim
downloadvim-easytags-a205f918f5797d9183f7f479360ed91bbce2b388.tar.gz
Initial commit
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