aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-04-19 21:21:23 +0200
committerTeddy Wing2018-04-19 21:21:23 +0200
commit2bd37ac201efda3bf93a0eb4c70e45fa952d8fa0 (patch)
tree27851e1c06153b39a60e0f978729ad1dab300a9a
parent044835706eb9e4053dc750b4b9403e6e5173006b (diff)
downloadvim-tabs-grep-2bd37ac201efda3bf93a0eb4c70e45fa952d8fa0.tar.bz2
Take a glob instead of a regex pattern
Globs make it easier to match file and directory names. For example, instead of writing: :TabsGrep utol.*grep we can write: :TabsGrep utol*grep Discovered `glob2regpat()` in the help while searching for a way to take a glob in my command and it ended up being the perfect thing, yay. Needed to slice the regex returned by the function to discard the first and last characters, as it automatically adds `^$` delimiters around the generated regex pattern. This doesn't make sense for our use case because we want to be able to start writing from anywhere in the middle of the path, and not have to add `*`s to the beginning and end.
-rw-r--r--autoload/tabs_grep.vim5
1 files changed, 4 insertions, 1 deletions
diff --git a/autoload/tabs_grep.vim b/autoload/tabs_grep.vim
index c307aee..b189433 100644
--- a/autoload/tabs_grep.vim
+++ b/autoload/tabs_grep.vim
@@ -3,9 +3,12 @@ function! tabs_grep#TabsGrep(search)
silent tabs
redir END
+ " Slice to get rid of `^$` delimiters
+ let pattern = glob2regpat(a:search)[1:-2]
+
let tabs = split(tabs_output, '\n')
- call filter(tabs, function('s:MatchString', [a:search]))
+ call filter(tabs, function('s:MatchString', [pattern]))
let tabs = s:FilterTabPageElements(tabs)