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
0
votes
0answers
17 views

in vimscript how to write the code a CTRL-C to be executed

I run a sourced vimscript like this: exec 'g#' . WE_var_searchmode . ' ' . WE_var_pattertosearch . '#exec " A | B | C | make_CTRL-C | ... | LAST " ' The outer execute '...' is needed to ...
8
votes
5answers
789 views

Is there a simple equivalent of :g/PATTERN/m0 that doesn't reverse the matched lines?

Occasionally I want to move all lines in a file to the top of that file. :g/PATTERN/m0 almost does what I want, but because :g operates one line at a time in order, it will also reverse the affected ...
1
vote
1answer
197 views

Why does this vim command fail?

I'm trying to process large error logs and part of that is filtering out lines I don't need to see. Here's what I'm running in vim: :g/.*rsync: stat.*/d | %s/\(.*mkstemp "\)\(.* \/\)\(.*$\)/\2/ | ...
0
votes
1answer
42 views

How to execute multiple global commands in Vim not sequentially?

Using following test input: *********** aaa bbb ccc *********** ddd eee fff ----------- ggg hhh iii ----------- jjj kkk lll ----------- *********** aaa bbb ccc *********** ddd eee fff ----------- ...
0
votes
1answer
54 views

Something like :g/re/p - but only print the matches instead of whole lines?

Say we have the following code: Lorem ipsum. <input name="test1"> <input name="test2"> Lorem ipsum some long text possibly so long you lose your overview. <input ...
2
votes
3answers
56 views

How to delete a range of lines not up to N lines under a lines matching a pattern?

Say I have a document cat dog xxx 1 2 3 cow xxx a b c horse I would like to be able to run a command that will end up with xxx 1 2 3 xxx a b c whereby the transformation is defined by matching all ...
7
votes
2answers
281 views

Deleting lines matching a pattern and put them into the buffer

I am trying to do this: deleting lines matching a pattern and then copy these lines into some other place in the file. :g/PATTERN/d does delete the lines but when I use p or P, only the last line is ...
3
votes
1answer
234 views

Join multiple lines based on pattern

I have text bounded by quotes as follows "This is an example of some text" I want to join these into one line. e.g. "This is an example of some text" I have tried commands like ...
1
vote
2answers
49 views

Why is my global command coupled with a range command matching more lines than expected?

I have this file over here. <ul class="social-icons"> <li><a href=""><span class="social_linkedin_square"></span></a></...
1
vote
1answer
21 views

Why does this pattern make :global work only on the first line of the highligted match?

\/\*.*\(\n\s\*.*\)*\n\s\*\/ is a pattern which I cooked up to match some multi-line C comments, i.e., in the format of: /* Comment Text * Comment Text * Comment Text */ Searching for the pattern ...
1
vote
1answer
155 views

How do I delete matching lines in multiple files at once?

I want to delete lines containing a search term from multiple files. I used bufdo or argdo for similar tasks such performing a replacement with s over multiple files. However, bufdo g/SearchString/d | ...
0
votes
1answer
87 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 ...
2
votes
2answers
260 views

g/pattern/d but check first

I'd like to use Ex mode :g/pattern/d to delete most (but not all) of the rows containing pattern, but I want to see each one first and confirm before deleting, similar to :s/pattern/foo/gc. Is there a ...
2
votes
1answer
256 views

How do I append to the unnamed register?

In particular, I'd like to append to the unnamed register with the :global command.
3
votes
2answers
43 views

Syntax clarification on a global sort command

I was looking at a global command that I saved from long time ago. I did not understand how it was a valid syntax, but apparently the syntax was valid because the command worked. The command: :g/\v\{/...
3
votes
2answers
606 views

Delete blank lines within range

Suppose I have the file: begin asdf asdf end begin asdf end begin asdfasdf end How can I use something like the global command to delete every empty line in between 'begin' and 'end'? :/begin/,...
3
votes
3answers
260 views

Using :g to yank in quotes across multiple lines

I was reading through the vim wiki about the power of g https://vim.fandom.com/wiki/Power_of_g and would like to do something similar to :g/pattern/y A but a little bit different. I have an html file ...
2
votes
1answer
1k views

How to truncate all lines at a certain length?

Much like this question, I've failed to put this together successfully on my own. I want to truncate lines in my file so that no line is over 100 characters in length. I can go to position 100 on ...
2
votes
0answers
214 views

neovim hlsearch not working

I'm testing neovim and for many thing it is working way faster than vim (I use many plugins ~80, and I can really tell the difference with neovim). All the same config files worked out of the box, but ...
2
votes
2answers
162 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
1answer
156 views

function to search for a pattern

I just recently found a very nice command to search for a pattern in a document, and display all hits: :g/pattern/z#.1 Since the command is a bit cumbersome to type, I would like to make a shortcut, ...
0
votes
2answers
128 views

How can I delete lines fit a pattern to a register or a new file?

I can use the powerful :g command to delete lines that contain a certain pattern like this: :g/^\va pattern/d I thought I should paste the deleted content to a new place but I cannot find all ...
3
votes
1answer
146 views

Unmapping the global mappings on a per-buffer basis

I have the following mapping in tnoremap <Esc> <C-\><C-n> init.conf to exit insert mode while in the terminal. In certain terminal buffers I would like to not have that global ...
0
votes
2answers
199 views

What's the simplest way of inlining a variable?

I've recently refactored vim-colors-solarized and I've stumbled on a code like this let s:foo = s:bar " used in multiple places " ... many lines let s:goo = s:boo " used in multiple places How can I ...
0
votes
2answers
174 views

How to ignore a failed :g (global) command in a macro?

Part of a macro I'm writing deletes any blank lines, and then does some more work (joining the expected two remaining lines and then appending to them). Simplified version: let @m=':g/^$/d^MggJA ^[' ...
3
votes
1answer
116 views

replace or operate within regex match

underlying question: Is there a way to operate on text within a regex match? I.e. is there an analog to the 'g' command that operates on match substrings instead of lines usecases: One example of ...
0
votes
1answer
190 views

Transform lines: prepend with incrementing number and string and append with string for each line in one step

I have the following lines: abc07 bca08 xyz17 And I would like to transform it to: [0]="abc07" \ [1]="bca08" \ [2]="xyz17" \ Based on this question, I can do the first part and the end ...
3
votes
4answers
406 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
93 views

Insert text including capture group from search using global command

I would like to search for a pattern in a range of lines and append additional text on another line that would include part of the search pattern. Something like this: [range]g/\(foo \)\(\w\{-}\)/...
1
vote
0answers
116 views

surround plug-in within global command

I've been unable to use surround within a global command, For example: g/^/ norm! yss" seems to do nothing or replaces the entire line by the contents of the clipboard. This is consistent with ...
2
votes
1answer
58 views

:global, how to use matched pattern in the cmd of :g/pat/cmd?

Give a buffer each line contain a filename. how to use r! cmd on the filename, within a :g command? eg, BEFORE PROCESSING: file1.txt file2.txt AFTER PROCESSING (with wc -l): file1.txt 12 ...
0
votes
2answers
54 views

limiting global search&replace to matches that occur immediately to the right of the cursor

If I have this line: a{word} a{20] a{word} a{20] and type :g/a{.\{-}\]/s/{/\[/gc vi prompts me to change all four occurrences of { to [. I want it to prompt me to replace only the matches ...
2
votes
2answers
221 views

How to remove lines which have lower numbers than before, and keep only the sequential?

In order to parse certain log file and make a plot of sequential numbers, I need to filter out the lines with numbers which appearing lower than in the previous lines. For example, given the list of ...
1
vote
0answers
56 views

indenting with ':g' command not working from the command line

When I need to work with some scrambled javascript/json code, one of my first steps is to introduce proper line breaks, followed by proper brace based indentation. For the later, I found the following ...
2
votes
1answer
3k views

Differences between local & global

From :h 'ar': ...If this option has a local value, use this command to switch back to using the global value: :set autoread< What do local & global value exactly mean? I ...
0
votes
2answers
110 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: ...
1
vote
1answer
60 views

Converting from A to B using mapped key

I've posted a number of times to try and get closer to what I'm trying to do. My problem is I have got the commands I need to make the conversion happen, however I cannot successfully map it to a key. ...
1
vote
1answer
358 views

How to remove all words which doesn't match the pattern?

I've the following content: a1a foo bar buzz foo b2b bar buzz foo bar c3c buzz foo bar buzz d4d where I can match all words consisting only alpha characters by the following pattern: /\<[a-zA-Z]*...
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
1answer
3k views

How to use :g to insert?

Let's say I have these lines: a # c b ## d and i want to insert # on a line starting with a # so that I get this: a ## c b ### d I was not able to find anything in the vim help, but I was able to ...
3
votes
1answer
1k views

Duplicate line and replace part of line multiple times

Considering this type of Json structure : [ { "id": "0000000000001", "en-US": "String 1" }, { "id": "0000000000002", "en-US": "String 2" } ... ] I ...
2
votes
2answers
274 views

Substitute text on one line with capture group from previous line?

Suppose I've copied a bunch of lines of boilerplate code that I need to copy multiple times over, and then change in two separate places, in the same way: it 'includes sessions#new' do expect(...
4
votes
2answers
3k views

vim comment out every line of text containing a pattern using the 'global' command

In my file containing LaTeX source code, I wish to comment out all the lines matching a pattern (specifically, the pattern that I am interested in is \draw, including the \ character). I have magic ...
2
votes
2answers
1k views

How to filter text matched by global command?

I have a log file full of arbitrary lines, interspersed with some lines which are a proper xml sequence, with all the tags on a single line (for each sequence). I want to simply process this so that ...
0
votes
2answers
143 views

How to execute global/substitution command asynchronously?

With the release of vim 8, I was wondering if there is a way to execute :s or :g asynchronously.
2
votes
1answer
661 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="****" &...
1
vote
2answers
167 views

Joining consecutive commas using ex-mode

I have a large list of scores that looks likes this: Michelle ,46419 ,32413 Frank ,46412 ,33810 Steve ,28333 ,17830 ,37 Joe ,136 ,93 Alicia ,121300 ,84146 How can I move my list in Vim so it is re-...
4
votes
1answer
223 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....
3
votes
1answer
689 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 ...