How to do search & replace with ack in vim? -


i using ack plugin in vim, helps me search strings in project. however, want replace or occurrences of found strings. can kind of global search , replace using vim arglist (source) :

:args app/views/*/* :argdo %s/, :expire.*)/)/ge | update 

but instead of using args, prefer search via ack , replace in files have been found. there way similar argdo command?

i've decided use ack , perl solve problem outside of vim use more powerful perl regular expressions instead of gnu subset. map key stroke in vimrc.

ack -l 'pattern' | xargs perl -pi -e 's/pattern/replacement/g' 

explanation

ack

ack awesome command line tool mix of grep, find, , full perl regular expressions (not gnu subset). written in pure perl, it's fast, has match highlighting, works on windows , it's friendlier programmers traditional command line tools. install on ubuntu sudo apt-get install ack-grep.

xargs

xargs old unix command line tool. reads items standard input , executes command specified followed items read standard input. list of files generated ack being appended end of perl -pi -e 's/pattern/replacemnt/g' command.

perl -pi

perl programming language. -p option causes perl create loop around program iterates on filename arguments. -i option causes perl edit file in place. can modify create backups. -e option causes perl execute 1 line of code specified program. in our case program perl regex substitution. more information on perl command line options perldoc perlrun. more information on perl see http://www.perl.org/.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -