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

Print lines between the first "sta" and last "end" (boundaries included); fallback to file boundaries if missing

Requirements In a batch manner, i.e., with ex, vim -e or vim -E, I want to print all lines between line b1 and line b2, boundaries included. b1 is: The first line with a "sta" match, if ...
user avatar
  • 2,238
0 votes
0 answers
35 views

Ex - silent mode won't read commands from a file when stdin is redirected

I'm starting vim in Ex mode, silent mode, on Windows 10, in a standard command prompt window. I'm trying to re-direct stdin from a file. I'm using the terminal version of vim 8.2.2824. It doesn't ...
user avatar
0 votes
1 answer
49 views

How to pass argument to a ex command after chaining it with <bar>?

I'm trying to make my life easier with vim fugitive and ex command line, by creating an abbreviation to a frequent task, which is switching to develop, pulling it and creating new branch. That's my ...
user avatar
2 votes
1 answer
40 views

Leading colons and whitespaces in Ex commands

Apparently, multiple colons are simply ignored when executing Ex commands. For example, :set number! :::set number! : : :set number! all toggle line numbers. Is this really a consolidated rule? ...
user avatar
  • 2,238
2 votes
1 answer
106 views

Use cases of ":rewind"? How does it differ from ":b1"?

After reading :help :rewind :rew[ind] [++opt] [+cmd] Start editing the first file in the argument list. This fails when changes have been made and Vim does not want to |abandon| the ...
user avatar
  • 2,238
4 votes
4 answers
1k views

Filter specific lines matching a pattern through external command

I'm trying to filter specific lines through external command. I think knowing how to do this would be extremely beneficial to me, so I'm trying to find a way to do this. As an example, I wanted to ...
user avatar
  • 59
2 votes
1 answer
114 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 ...
user avatar
0 votes
1 answer
43 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 ...
user avatar
  • 442
0 votes
0 answers
96 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 ...
user avatar
  • 316
9 votes
1 answer
1k 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 ...
user avatar
  • 193
3 votes
1 answer
841 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 ...
user avatar
  • 16.8k
1 vote
2 answers
96 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 ...
user avatar
2 votes
1 answer
378 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: ...
user avatar
  • 4,085
7 votes
4 answers
6k 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 ...
user avatar
  • 756
11 votes
3 answers
4k views

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

I am 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, this is ...
user avatar
  • 263
1 vote
2 answers
259 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....
user avatar
  • 756
3 votes
2 answers
94 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 ...
user avatar
  • 756
0 votes
1 answer
54 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! ...
user avatar
  • 1,071
1 vote
1 answer
928 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....
user avatar
  • 756
2 votes
1 answer
510 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 ...
user avatar
  • 756
2 votes
1 answer
247 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 '...
user avatar
  • 756
6 votes
2 answers
601 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?
user avatar
  • 756
3 votes
2 answers
900 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 ...
user avatar
  • 756
5 votes
2 answers
819 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 ...
user avatar
  • 16.8k
9 votes
2 answers
474 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 ...
user avatar
  • 4,085
2 votes
3 answers
102 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 ...
user avatar
  • 16.8k
5 votes
2 answers
3k 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} {...
user avatar
  • 769
0 votes
0 answers
68 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 ...
user avatar
  • 645
11 votes
6 answers
2k 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=~/....
user avatar
  • 16.8k
4 votes
1 answer
452 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 ...
user avatar
  • 16.8k
2 votes
1 answer
696 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 /&...
user avatar
  • 16.8k