From 2bd37ac201efda3bf93a0eb4c70e45fa952d8fa0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 19 Apr 2018 21:21:23 +0200 Subject: 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. --- autoload/tabs_grep.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3 From da277858f1da1931ac17cbe9f095ea0541051f88 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 19 Apr 2018 21:49:45 +0200 Subject: doc: Update for the change from regex pattern to glob Change past references to "pattern" into "glob". The command no longer accepts regex patterns. Instead it takes a file glob, which is faster to type and potentially more intuitive. --- doc/tabs_grep.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/tabs_grep.txt b/doc/tabs_grep.txt index 988269e..48c7e5e 100644 --- a/doc/tabs_grep.txt +++ b/doc/tabs_grep.txt @@ -7,18 +7,19 @@ Version: 0.0.1 ============================================================================== INTRODUCTION *tabs_grep* -TabsGrep filters the output of |:tabs| using a given search |pattern|. This -makes it easier to find out which tab a file is on. +TabsGrep filters the output of |:tabs| using a given search glob. This makes +it easier to find out which tab a file is on. ============================================================================== COMMANDS *tabs_grep-commands* *TabsGrep* -:TabsGrep {pattern} - Output |:tabs| filtered by {pattern} using |match()|. +:TabsGrep {glob} + Output |:tabs| filtered by {glob}. Example: > - :TabsGrep \V.vim -< This shows a list of tabs and file names containing ".vim". + :TabsGrep tabs*vim +< This shows a list of tabs with file names containing + "*tabs*vim*". ============================================================================== LICENSE *tabs_grep-license* -- cgit v1.2.3