Questions tagged [ex-command]

ex is an advanced version of the standard Unix editor ed. It is the direct predecessor of vi.

Filter by
Sorted by
Tagged with
1
vote
1answer
56 views

What is the meaning of “#” in “:g/pattern/z#.5”

Like the title, What is the meaning of # in :g/pattern/z#.5. :g/pattern/z#.5 and :g/pattern/z.5return the same output for me. In addition, If I want to help description of # with :h command, how to ...
0
votes
1answer
38 views

How may I create an excmd that has a signature like g, s, v commands? (`:cmd/str1/str2/options`)

A g command can find the lines globally and then apply actions, like the following would find lines that contain foo and delete those lines: :g/foo/d An s command is more well-known for its ...
0
votes
0answers
69 views

Is it possible to copy block (given by range) multiple times in a single command?

Is there a way to copy a few times a given block from command-line mode, e.g. with the :t command? For example, how to copy the two lines (block) above the cursor -2,-1 to the current position ., 3 ...
3
votes
1answer
476 views

How to go back to beginning of the line in (ex) command mode?

The standard CTRL-E works to go to the end of the line but CTRL-A doesn't seem to work to go to the beginnig. It would obviously be useful to quickly go to the beginning of line for example if one ...
3
votes
1answer
287 views

How to negate substitution pattern?

I've the following sample INI file: Foo=1 Bar=1 Baz=1 Qux=1 and my goal is to set all options to 0 except Foo. To disable one selected line, I know that I can run: %s/Foo=\zs.*$/0/ Test command ...
1
vote
2answers
83 views

Using more than two line specifiers in an ex-range

Under :help [range] it states: Some Ex commands accept a line range in front of them. This is noted as [range]. It consists of one or more line specifiers, separated with ',' or ';'. I am ...
2
votes
1answer
205 views

Print current line number to stdout using ex

I often use ex in scripted edits. I can run several editing commands, and then save the changed file, with no danger of hanging if an ex command encounters an error, by running commands like so: ...
5
votes
3answers
2k views

Replace with hex character

Given this file: printf 'hello\x19world\n' > hello.txt I can replace a hex character: $ ex -sc '%s/\%x19/ /|x' hello.txt $ od -c hello.txt 0000000 h e l l o w o r l d \n ...
4
votes
2answers
895 views

How can I change the default grep call (grepprg) to exclude directories?

Hey guys I'm trying to change the default grep call to avoid unnecessary plugin installation. What I want from vim is to call the external search using the builtin command :grep with custom arguments, ...
1
vote
0answers
146 views

File emptied when command not found

Given this command: ex -sc '%!alfa' -cx file I get this result: sh: alfa: command not found which is to be expected. However an unintended side effect of this is that the file is emptied and saved....
3
votes
2answers
80 views

Break long comments

Given the file alfa.c: // Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his, soluta salutandi persequeris vel ne, facete impedit contentiones te eam. Ut utamur habemus qualisque ...
0
votes
1answer
44 views

Save view after execute command?

I'm mostly developing with python. I'm using pdbpp as python debugger so I'm contantly adding import pdb;pdb.set_trace() or import pdb pdb.set_trace() So I wrote couple of functions. function! ...
1
vote
1answer
562 views

Replace every other line

Given file alfa.txt: 10 11 12 13 I can remove every other line: $ ex -sc 'g/^/+d' -cx alfa.txt $ cat alfa.txt 10 12 However I cannot replace every other line: $ ex -sc 'g/^/+s//> /' -cx alfa....
2
votes
1answer
331 views

Global append lines

Given file alfa.txt: 10 11 12 13 I would like to append a line of text after every line. This is simple enough with sed: $ sed aBRAVO alfa.txt 10 BRAVO 11 BRAVO 12 BRAVO 13 BRAVO However I am ...
2
votes
1answer
145 views

argdo command hanging

I am interested in editing multiple files. Using this answer: How to edit files non-interactively (e.g. in pipeline)? I came up with my own test case: seq 10 14 | tee pa.txt > qu.txt ex -sc '...
5
votes
2answers
258 views

Invert range selection

I can remove the last 10 lines like this: ex -sc '-9,d|x' f.txt However, I would like to invert the selection, or remove all lines except the last 10. Is this possible?
2
votes
2answers
625 views

Insert blank line after different lines

Given file alfa.txt: foxtrot golf hotel india juliet I would like to insert a newline after lines 2 and 4. I have this command: ex -sc '2pu_|4pu_|x' alfa.txt However it is inserting lines after ...
5
votes
2answers
417 views

How to repeat the last command in Ex?

I've the file, like: name = foo # unknown number of lines ... features_exclude[rules_config][] = rule1 features_exclude[rules_config][] = rule2 features_exclude[rules_config][] = rule3 ...
9
votes
2answers
219 views

Use ex-command to check whether two lines are identical?

I was looking at this question and then wondered how I might implement my answer which uses sed using purely POSIX ex. The trick is that while in sed I can compare the hold space with the pattern ...
2
votes
3answers
83 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
2answers
1k views

How to use “-c” command line option?

Fully realizing the heritage of vi, I know that its predecessor (ex) could be, and was, used for command line processing of files ("sed-style", if you like). The manpage says: -c {command} {...
0
votes
0answers
61 views

using ex with perl support

I've just learnt how to run perl commands within vi, but I had to install vim.gtk in order to have perl support. But I want to incorporate these perl commands into bash scripts that call ex. Is ...
10
votes
6answers
1k views

How to append some line at the end of the file only if it's not there yet?

I'd like to edit a file in-place by appending a line, only if doesn't exist yet to make my script bullet-proof. Normally I'd do something like: cat >> ~/.bashrc <<EOF export PATH=~/....
4
votes
1answer
204 views

Delete text after match in Ex?

I've sample file like: aa bb cc dd ee ff and I'd like to remove everything till the matched line dd. Normally in Vim I type: d/dd then Enter and it works. When using in ex, it doesn't work as ...
2
votes
1answer
464 views

How to remove inner content of html tag conditionally?

I've html file (e.g. curl -o page.html http://example.com/) where I would like to remove inner html block for given html tag. I've the following code which works: $ ex -V1 page.html <<-EOF /&...