Questions tagged [global-command]

Questions about the usage of the global command `:g` which executes an Ex command (default ":p") on the lines within a range a where a pattern matches.

Filter by
Sorted by
Tagged with
14
votes
6answers
3k views

Delete all consecutive duplicates

I have a file that looks like this. Move to 230.00 Hold Hold Hold Hold Hold Hold Move to 00.00 Hold Hold Hold Hold Hold FooBar Hold Spam Hold I would like it to look like this: Move to 230.00 ...
6
votes
3answers
4k views

How to execute command on every matching pattern, not just lines?

I know in vim I can use :global to execute commands on the matching lines. But I'm wondering if it's possible to execute those commands on every matching pattern, not just lines, consider following ...
4
votes
3answers
721 views

Run a function once on every paragraph

I'm trying to write a plugin that highlights overused words. After much effort I managed to write a function (and a command, :Ditto) that will highlight the most used word in the file or in a ...
2
votes
3answers
96 views

Why aren't :g/X/d changes saved in Ex?

I've the following file (which is a simplification of the hosts file): 126.0.0.1 127.0.0.1 128.0.0.1 and I'm trying to invoke the following command: ex +g/127/d -cwq file which is supposed to ...
4
votes
1answer
576 views

Substitute all except the last asterisk in groups of two or more asterisks

How can I substitute all except the last asterisk in groups of two or more asterisks with two spaces? E.g. * Micro topic 1 ** Microbes are small ** You can't see them! *** Isn't that something? ...
3
votes
4answers
381 views

How to run a python command based on a matched group of a pattern?

Let say I want to run a command that uses a matched group of a pattern for each line matching the pattern. The natural choice is :g. With the command :s, there is no problem. If i would do :g/aaa\(....
3
votes
2answers
1k views

Using global command on Quickfix entries [duplicate]

I find and replace a pattern in all the files in my project (which is a big one). After the search is done, quickfix window is opened with the matches. The matches are in different files in different ...
2
votes
1answer
641 views

Run a command on every match of a search (not on the line)

I am trying to run a command on every occurrence of a search match. So, If i have some thing like this where a search match matches only these two anchor tags, .................. <a src="****" &...
2
votes
2answers
134 views

Is it possible to use a reverse range in global search

I have an error report where often the known errors are in the top few thousand lines, formatting issue rather than quantity unfortunately. I want to run :g/pattern/ from the end of the file. I know ...
0
votes
2answers
108 views

Using -c command line option for Vim 7.4 on Windows produces errors

The following commands work fine when I issue them from the command mode in Vim: :%s/\(^\s\+\)\(\S\+.*)\s*\){$/\1\2\r\1{/g :g/^\s*\/\/$/d But when I run the above commands as a script as below: ...
0
votes
1answer
79 views

:command to abort sequence?

To be honest upfront, I wanted to use global to find the first non-matching line, as in v,/usr/lib/, abort (having slashes in the search pattern is the reason for using g instead of / — I'm editing a ...