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
2 answers
82 views

Ex global command is silenced, why is execution still stopped on error (Neovim)?

I have a sample text: 123 456 If I delete the first line, why does :silent! execute 'g/123/d' | execute 'g/456/d' work while :silent! g/123/d | g/456/d doesn't work, unless I bring back the first ...
danko's user avatar
  • 11
0 votes
2 answers
79 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 ...
Quasímodo's user avatar
  • 2,416
0 votes
0 answers
60 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 ...
Paul CyberCitizen's user avatar
0 votes
1 answer
53 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 ...
LukaszBielsko's user avatar
2 votes
1 answer
47 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? ...
Quasímodo's user avatar
  • 2,416
2 votes
1 answer
150 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 ...
Quasímodo's user avatar
  • 2,416
4 votes
4 answers
2k 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 ...
Dafta's user avatar
  • 59
2 votes
1 answer
133 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 ...
SangminKim's user avatar
0 votes
1 answer
46 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 ...
Sunny Pun's user avatar
  • 472
1 vote
0 answers
101 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 ...
Ivan's user avatar
  • 336
9 votes
1 answer
2k 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 ...
Yanevski's user avatar
  • 193
3 votes
1 answer
1k 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 ...
kenorb's user avatar
  • 18.2k
1 vote
2 answers
101 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 ...
René Nyffenegger's user avatar
2 votes
1 answer
466 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: ...
Wildcard's user avatar
  • 4,364
7 votes
4 answers
7k 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 ...
Zombo's user avatar
  • 1
14 votes
3 answers
5k 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 ...
MaikoID's user avatar
  • 293
1 vote
2 answers
263 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....
Zombo's user avatar
  • 1
3 votes
2 answers
95 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 ...
Zombo's user avatar
  • 1
0 votes
1 answer
58 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! ...
user1685095's user avatar
  • 1,141
1 vote
1 answer
1k 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....
Zombo's user avatar
  • 1
2 votes
1 answer
524 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 ...
Zombo's user avatar
  • 1
2 votes
1 answer
286 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 '...
Zombo's user avatar
  • 1
6 votes
2 answers
690 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?
Zombo's user avatar
  • 1
3 votes
2 answers
936 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 ...
Zombo's user avatar
  • 1
5 votes
2 answers
974 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 ...
kenorb's user avatar
  • 18.2k
9 votes
2 answers
562 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 ...
Wildcard's user avatar
  • 4,364
2 votes
3 answers
107 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 ...
kenorb's user avatar
  • 18.2k
5 votes
2 answers
4k 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} {...
DevSolar's user avatar
  • 789
1 vote
0 answers
70 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 ...
Leo Simon's user avatar
  • 715
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=~/....
kenorb's user avatar
  • 18.2k
4 votes
1 answer
517 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 ...
kenorb's user avatar
  • 18.2k
2 votes
1 answer
762 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 /&...
kenorb's user avatar
  • 18.2k