From a205f918f5797d9183f7f479360ed91bbce2b388 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Tue, 15 Mar 2011 23:00:55 +0100 Subject: Initial commit --- escape.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 escape.vim (limited to 'escape.vim') 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 +" 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 -- cgit v1.2.3