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
4
votes
1answer
217 views

indent command does not indent matched lines

I have file where I would like to indent all the lines between curly braces: html { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; } body { line-height: 1....
5
votes
1answer
715 views

How to write each line into separate file?

I'd like to write content of the file into separate files each for each line. For example: Lorem ipsum dolor sit amet consectetur adipiscing elit I'd like to write 1st line into line1.txt, 2nd ...
3
votes
1answer
679 views

Run global with range from within function

I have a function somewhat like this: function! MyFunction() g/\v.(\n\n|\n*%$)/execute "normal! v{:call AnotherFunction()\<cr>" endfunction Now I want to be able to pass a range to that ...
4
votes
3answers
731 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
4k views

How to delete searched line and next

I have a file containing special comments in the following forms: // SPECIAL // Some stuff // Some other stuff // Last line of other stuff So I need to be able to delete the line containing SPECIAL ...
2
votes
3answers
252 views

Replace current line with filtered lines

For example, to replace current line with all lines starting with '# ' , I use :.! grep '^\# ' % I know about the :g command that can filter lines to perform operations like :g/call/d :g/cat/ s/...
4
votes
1answer
250 views

How to simulate Return and Escape for global command without using Control-V?

I've the following sample content which I want to edit: <table> <tr><td title="Title 1">col1</td><td>col2</td><td>col3</td></tr> <tr><td ...
10
votes
5answers
4k views

How to replace content between two patterns from the file?

I've the following format of the file: <common> fitnes=0 genetic=1 method=0 </common> <inputs> foo=bar bar=foo </inputs> <limits> balance=200.00 </limits> and I ...
4
votes
1answer
582 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? ...
2
votes
3answers
98 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 ...
3
votes
1answer
94 views

How to surround all headlines with empty new lines in a markdown file?

I have the markdown file that uses # for headlines, like this one. #H1 Text one one ##h2 more Text #more H1s Even more text No I have the problem that some interpreters of markdown don't accept a ...
4
votes
1answer
289 views

Indenting lines in each paragraph except the first one using global command

I want to indent lines in each paragraph except the first one. By paragraph, I mean a group of lines that are separated from other groups of lines by at least one blank line. For example, here we ...
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 ...
9
votes
2answers
4k views

Append lines of text after pattern using global command

I'm reworking a section of logic in some C code to avoid a memory leak that looks like this: switch (result) { case CASE_1: return report(...); case CASE_2: return report(...); /* * More ...
8
votes
1answer
138 views

How can I use consecutive numbers in an Ex-style substitute command?

For example, let's say I want to put a number before every line that starts with the word "Do". The command would look something like :%s/^(Do )/1. \1/, but what can I do so it will apply numbers ...

1
2