Text editor with multi-pattern search and replace at once?
...why not use a script? Check xclip
(sudo apt-get install xclip
)
xclip -o -selection clipboard
will send the clipboard to standard output, and with -i
you can replace the clipboard.
So
xclip -o -selection clipboard | sed "s/change this/to this/" | xclip -i -selection clipboard
will apply the change to the selection, and now you can paste it.
If you want a graphical thing, you can embed the script with yad:
#! /bin/bash
#
yad --title Choose --button One:1 --button Two:2 --button Three:3
choice=$?
case $choice in
1)
xclip -o -selection clipboard |
sed "s/one/uno/" |
xclip -i -selection clipboard
xclip -o selection clipboard
;;
2)
xclip -o -selection clipboard |
sed "s/two/dos/" |
xclip -i -selection clipboard
xclip -o selection clipboard
;;
3)
echo "executing 3 --- well, you got the idea"
;;
esac
That will show you a dialog like this:
Notice that the script will both modify the clipboard (paste) buffer and print it.
To embed this in an editor, for example vim
, you can do the following:
-
Add to your
.vimrc
:nmap <F4> :r ! /path/to/the/script <CR>
run for example gvim.
Now you copy the text, go the the editor, press F4. Choose the change you want to apply.
The text will appear in the editor. If it's ok as is, you can paste it. Otherwise
Edit the text and copy it again. (In
gvim
, you can select the text with the mouse and simply choose paste --- or learn thevim
commands, whatever).
It could be optimized for sure (you probably can easily define another key to select and paste the modified text so that you have even less keypress to use)
You can do this all on the command line still using something like xsel
or xclip
to retrieve the current clipboard and then stuff the result back into it. Here's a little example that shows sed
being used to do multiple replacements.
echo -n abc | xsel -bi # write to clipboard
xsel -bo | sed 's/abc/def/;s/def/123/' | xsel -bi # process it
echo $(xsel -bo) # output it for testing
Returns 123