ack.vim
ack.vim copied to clipboard
Automatically escape special chars
Not sure if this is a bug so please close if I'm wrong.
Are we supposed to escape all special characters? Example below.
Works
:Ack! "\\-\\>confirm" src/
=> will search for "->confirm" which is ok.
Does not work
:Ack! "->confirm" src/
=> drops error:
1 || Unknown option: >
1 || Value "src/" invalid for option m (number expected)
2 || ack: Invalid option on command line
Info
$ ack --version
ack --version
ack 2.12
Running under Perl 5.16.3 at /usr/bin/perl
$ nvim --version
NVIM v0.2.2
Build type: Debug
Thanks!
Hi @duraki
:Ack! "\-\>confirm" src/
works as well.
even -Q --literal Don't parse PATTERN as a regular expression
doesn't help in this case.
I think the escaping is required by ack, grep or ag. Ack.vim is just a wrapper here.
I propose something like:
:Ack!! "->confirm" src/
# => !! equals literal
To be eligible for literal search and not regex matching one could use this flag. If user wants to combine "do not open" with this feature, he would add another exclamation like: Ack!!!
(don't open + literal search).
Regarding the last point, as far as I know, you are supposed to escape only quotes (at least in grep):
$ grep "this have \" quote in the middle"
...
Cheers
It looks like ack
thinks of >
as a switch because there's a dash before it. To solve the problem, you must add --
before the query pattern. To make Ack work straight from visual mode selection:
function! AckClipboard()
execute printf('Ack! -Q -- "%s"', substitute(@", '\([%"\\]\)', '\\\1', 'g'))
endfunction
vnoremap <A-f> y:call AckClipboard()<CR>
Yes, you're correct. -Q
will turn off all metacharacters, and --
tells ack that it is at the end of the command line options.
@siikamiika yup, that makes sense. Will close until further discussed. Thanks eryn. (btw would love above proposal to be impl in the future)