ex is a line editor which serves as the foundation of vi. ex commands work on the current line or on a range of lines in a file. ex is invoked using the colon syntax within vi, and can be invoked on its own from the shell.
Questions tagged [ex]
70 questions
35
votes
2 answers
Vim command for "edit a copy of this file"
A pattern I seem to be following right now is:
edit a file until I like it
:w another-file to use it as a starting point for another-file
:e another-file to polish up another-file
Is there an existing ex command to do the latter two steps at once?…
![](../../users/profiles/9859.webp)
rampion
- 82,104
- 41
- 185
- 301
9
votes
1 answer
How to execute multiple global commands in Vim sequentially? (Error: "Cannot do :global recursive")
I want to sort the paragraphs in my text according to their initials with the following global command:
g/_p/,/^$/mo$
This works alone. But when I use several global commands at once, then an error occurs:
g/_p/,/^$/mo$|g/_w/,/^$/mo$
This gives…
![](../../users/profiles/29246.webp)
Mert Nuhoglu
- 8,746
- 13
- 71
- 105
5
votes
2 answers
vim: Run multiple commands based off of one :global command
Apologies if this has been posted already, for I cannot find an answer, even on the vim wiki.
Is there a way I can run multiple commands in vim command-line mode off of a single :g search?
For example,
:%g/foo/ s/bar/\=@a/g | exe "norm…
![](../../users/profiles/2689923.webp)
Miles
- 604
- 6
- 15
5
votes
3 answers
Redirect ex command to STDOUT in vim
I'm trying to craft a command to dump vim's highlighting information to STDOUT. I can write successfully to a file like this:
vim +'redir >outfile' +'hi' +'redir END' +'q'
After this, outfile contains exactly what I want. But I'd rather output to …
![](../../users/profiles/43089.webp)
Triptych
- 188,472
- 32
- 145
- 168
4
votes
1 answer
Differences in running vim via command line vs. running it in the vim editor
I am trying to process a series of files. I have noticed that there are discrepancies in running a particular command from the command line (i.e. ex mode). E.g.
$cat poo.txt
big
red
dog
small
black
cat
$vim -c "2,$g/^dog/d|wq" poo.txt
$cat…
![](../../users/profiles/4021436.webp)
irritable_phd_syndrome
- 3,512
- 2
- 24
- 43
3
votes
4 answers
How can I select part of a line in Vim
I have a line of text that looks like this
foo bar http://www.example.com -> baz
I want yank the url part using ex. Anyone have any ideas on how to do this?
To clarify. I want to do something like this :y/http:.*\.com/ from the command line. But…
![](../../users/profiles/1060176.webp)
Matt Peck
- 43
- 4
3
votes
2 answers
Append to line in vim matching regex
I have a json file that I ran a find and replace in using vim, however I forgot a , at the end of the line.
...
"id":41483
"someName":"someValue",
...
Using vim, how can I append a , to every line matching \"id\"\:[0-9].*$?
![](../../users/profiles/1790644.webp)
Matt Clark
- 24,947
- 16
- 62
- 114
3
votes
1 answer
Vim ex knowing number typed before
I'm making a shortcut that places a # at the front of each line, in the next x lines. x is a number I type before entering the shortcut, like typing 11dd deletes the next eleven lines.
The command is .,+10 s/^/#/g. Here the number ten should really…
![](../../users/profiles/322537.webp)
john-jones
- 6,711
- 17
- 47
- 79
3
votes
1 answer
Vim: Call an ex command (set) from function?
Drawing a blank on this, and google was not helpful.
Want to make a function like this:
function JakPaste()
let tmp = :set paste?
if tmp == "paste"
set nopaste
else
set paste
…
![](../../users/profiles/251589.webp)
sixtyfootersdude
- 23,394
- 39
- 132
- 200
3
votes
8 answers
In VIm, how to remove all lines that are duplicate somewhere?
I have a file that contains lines as follows:
one one
one one
two two two
one one
three three
one one
three three
four
I want to remove all occurrences of the duplicate lines from the file and leave only the non-duplicate lines. So, in the example…
![](../../users/profiles/1806553.webp)
Tem Pora
- 1,913
- 2
- 21
- 29
3
votes
3 answers
vi (vim) to read an exrc file other than ~/.exrc
We would like to be able to start vi (or vim) up with an alternative ex initialisation file. By default this is ~/.exrc.
Unfortunately vim(1), which is also brought up for "man ex" on this system, doesn't mention .exrc.
Any workarounds to provide…
![](../../users/profiles/1501955.webp)
projix
- 211
- 1
- 4
2
votes
1 answer
How to read a excel file with merged cells in php?
I wrote a php script that allows me to read an uploaded excel file and insert all the images contained in a folder by renaming them with the cell values "style" and "color" to have style_color.jpg. The script works fine but if I upload an xlsx file…
![](../../users/profiles/14009600.webp)
Patrick62
- 71
- 7
2
votes
1 answer
How to write an ex script that searches for text and deletes the next n lines?
I want to write an ex script that searches for text and then deletes 23 lines. I created an exscript file that contains:
/block_2/
23d
w
I then tried $ ex - index.html < exscript, but it makes wrong, unpredictable edits.
Those commands work when…
![](../../users/profiles/1365699.webp)
R891
- 2,276
- 3
- 14
- 26
2
votes
1 answer
How to copy command string in the ex mode into clipboard?
How to copy command string in the ex mode into clipboard?
![](../../users/profiles/1982032.webp)
showkey
- 449
- 30
- 101
- 235
2
votes
0 answers
Errors during Autodiscover procedure on Microsoft Exchange 2016
I am working on IP phone software which connects to Microsoft Exchange Server
via autodiscover procedure and works with Exchange data.
I am using Microsoft Exchange Server 2016.
At the present moment I have a problem with figuring out on which URL…
![](../../users/profiles/7461865.webp)
Maxim
- 63
- 6