aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-25 17:09:47 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-25 17:09:47 +1200
commit745dc4060a75bd0b1ec4f0667a309de61cf1d668 (patch)
treee5c7d90ec6b240a45559e6b63a41895722d84834
parent7414c6e26a04f2901c131cafc9fb9ebe9b543808 (diff)
parent4098465a15331d1be05d514b2cf219e13ee7a5e1 (diff)
downloadvim-regex-escape-745dc4060a75bd0b1ec4f0667a309de61cf1d668.tar.gz
vim-regex-escape-745dc4060a75bd0b1ec4f0667a309de61cf1d668.zip
Merge branch 'release/v1.0.0'v1.0.0
* release/v1.0.0: Switch to escape() method
-rw-r--r--VERSION2
-rw-r--r--autoload/regex_escape.vim19
2 files changed, 10 insertions, 11 deletions
diff --git a/VERSION b/VERSION
index 0ea3a94..3eefcb9 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.2.0
+1.0.0
diff --git a/autoload/regex_escape.vim b/autoload/regex_escape.vim
index 6acff6b..b57392a 100644
--- a/autoload/regex_escape.vim
+++ b/autoload/regex_escape.vim
@@ -1,10 +1,9 @@
-" Define Vim pattern character classes of characters that should have an
-" escape character added before them to make them literal, for use in
-" substitute()
+" Define characters that should be scaped to make them literal, for use as the
+" second parameter to escape()
let s:classes = {
- \ 'bre': '[][\.*?^$]',
- \ 'ere': '[][\.*?^$+{}()/]',
- \ 'vim': '[][\.*^$~]'
+ \ 'bre': '\.[]*^$?',
+ \ 'ere': '\.[]*^$?+{}()/',
+ \ 'vim': '\.[]*^$~'
\ }
" This function does the actual translation, defined as 'operatorfunc' for the
@@ -45,12 +44,12 @@ function! regex_escape#Operatorfunc(type) abort
" Get the corresponding character class
let class = s:classes[flavor]
- " Perform the substitution on the unnamed register's contents, inserting a
+ " Perform the escaping on the unnamed register's contents, inserting a
" backslash before every instance of any character in that class
- let @@ = substitute(@@, class, '\\&', 'g')
+ let @@ = escape(@@, class)
- " Paste our substituted changes back in over the top of the previously
- " selected text, by reselecting it before the paste
+ " Paste our escaped changes back in over the top of the previously selected
+ " text, by reselecting it before the paste
silent normal! gvp
" Restore contents of the unnamed register and the previous values of the