It would be useful to be able to chain global commands. In that way, you could quickly execute multiple commands on multiple lines. Perhaps it could be accessed in the following fashion:
:g/pattern/cmd1;cmd2;cmd3
This command would find each line matching to "pattern" and sequentially execute cmd1, cmd2, and cm3. Should be relatively easy to implement.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
Vim's command separator is the pipe symbol |
. Have you tried
:g/pattern/ cmd1 | cmd2 | cmd3
?
I've tried that and it, unfortunately, doesn't work. I was browsing the source code and I think this is the function for global commands:
and this is the end of that function:
I guess you could do something in the following fashion if you assume cmd is the g/pattern/cmd:
if (*cmd* contains ";")
{
var cmds = cmd.split(";");
foreach (var cmd in cmds)
{
global_exe(cmd);
}
}
else
{
global_exe(cmd);
}
Do you think that would be sufficient?
I guess it would make the most sense to use a pipe symbol. Replace "global_exe(cmd);" in original code with something like this?
const char delimeter[2] = "|"; // Multiple commands if (strstr((char *)cmd, delimeter) != NULL) { char *token; token = strtok(cmd, delimiter); // Split and execute each command while(token != NULL ) { global_exe(cmd); token = strtok(NULL, s); } } else { global_exe(cmd); }
I've tried that and it, unfortunately, doesn't work. I was browsing the source code and I think this is the function for global commands:
What was the command you actually tried? Did you get an error message? If yes, what did it say?
Actually, it seems to work. I don't know what I did to fuck it up. This can be closed. You can achieve this with:
:g/pattern/ cmd1 | cmd2 | cmd3
As you wrote.
Closed #9063.