132
votes
Accepted
Does Ex mode have any practical use?
Q is, as you found, ex mode. It's not entirely useful to use interactively, but it exists because Vim can be used to emulate the old ex binary. In fact, many systems provide the ex command by simply ...
114
votes
Does Ex mode have any practical use?
Vim in Ex mode is useful when:
You're in need of editing (multiple) files non-interactively (as part of the script).
Your connection is very slow or screen is not updated after your actions.
Mappings ...
36
votes
Accepted
How to edit files non-interactively (e.g. in pipeline)?
To edit file non-interactively using ex (vi is the visual mode for ex), you can use +{command} or -c {command} parameters which allows you to execute the vi commands after the first file has been read....
29
votes
Does Ex mode have any practical use?
I rarely use ex-mode, but when I need it I'm grateful for its existance.
I sometimes access systems via ssh over VPN, and these connections can sometimes get slow. Making the problem worse, I ...
19
votes
Accepted
delete lines that match a pattern from a given line to the end of the file
Use the :global command for that:
:3,$g/^#/d
You can apply it to lines not matching a pattern:
:3,$g!/^#/d
You can use the full range mechanism with it (see :help :range):
:.,/#define/+3g/^#/d
And ...
17
votes
Does Ex mode have any practical use?
The command-line window is useful for writing out long complicated commands. Since the command history opens as a window, you can use any vim navigation or editing command/mapping.
Say you want to ...
14
votes
Does Ex mode have any practical use?
I was told by a person with partial sight who is going blind that he is switching to ex, so that's one use of it. I myself am considerably older than vi, and I switched from ed to ex a long time ago (...
14
votes
Accepted
What is the difference between Ex mode and improved Ex mode?
This is actually documented in a somewhat 'hidden' non-obvious way, from :help Ex-mode
Q Switch to "Ex" mode. This is a bit like typing ":"
commands one ...
13
votes
Accepted
How to delete a multi-line match?
The feasibility of deleting parts of lines is elusive and a better vimmer than I will have to explain that. If anyone cares to donate an explanation I'd be happy to add it to this answer.
But it's ...
13
votes
Accepted
Continue an ex mode command after "norm"?
If you have a sequence of keystrokes that you want to execute in normal mode from the command line, you can use the :normal command.
However, by default the :normal command can't be followed by ...
12
votes
Accepted
How do I define a range from the current position to the end of the file in an ex command?
There is. For last line of a file, the address is $:
:.,$s/old/new/
See :help {address} for a fill list of possible addresses.
11
votes
What does :open do in vim?
From An Introduction to Display Editing with Vi:
If you are on a hardcopy terminal or a terminal which does not have a cursor which can move off the bottom line, you can still use the command set ...
11
votes
Accepted
How to use substitution on register?
Ex commands work on the buffer contents; for register (or variable) contents, you need to use a corresponding Vimscript function (if it exists).
For :substitute, the equivalent is substitute() (that ...
11
votes
Accepted
How do I emulate Sed's y command?
Sure it does. In unix there's often a command equivalent to sed y/X/x/ called tr. So...
echo "A1B2C3" | sed 'y/ABC/abc/' # prints "a1b2c3"
...is equivalent to...
echo "...
10
votes
Accepted
vim, vimdiff, ex, view, rvim and rview: How do they start in a different way when they are symlinks to the same binary?
Inside vim's source code, there is a main function roughly like
int main(int argc, char **argv) {
if (!strcmp(argv[0], "ex"))
do_ex_setup();
main_loop();
return 0;
}
This ...
9
votes
Accepted
How to write whole buffer to standard output from the command line?
To print buffer to shell standard output, vim needs to start in Ex mode, otherwise it'll open "normal" way with its own window and clear any output buffers on quit.
Here is the simplest working ...
9
votes
Accepted
Reusing search pattern in ex mode
Sure, just leave the pattern in the substitution empty:
:%s//replacement/
9
votes
Accepted
Append lines of text after pattern using global command
If I understand your post correctly, you had this snippet of C code :
switch (result) {
case CASE_1:
return report("...");
case CASE_2:
return report("...");
}
And you wanted to transform ...
9
votes
Accepted
Executing a command on delimited lines
You can use pattern delimiter for this:
:/first/,/second/norm dd
You can use any search pattern around the ,.
If you want to use only the inside of the matched patterns, use + and - like so:
:/...
9
votes
Accepted
How to copy lines from 4th till 11th and paste it from 15th till 22th line in ex mode?
I'm not sure if I understand you correctly but is this what you're looking for?
:4,11t 15
This will copy lines from 4 to 11 and paste it on line 15.
See :h co for more.
8
votes
Accepted
How can I use consecutive numbers in an Ex-style substitute command?
This command does what you want:
:let i = 1|g/^Do/s/^/\=i/|let i = i + 1
Explanation…
let i = 1 initializes counter i,
g/^Do/s/^/\=i/ prepends i to each line starting with Do,
let i = i + 1 ...
8
votes
Accepted
Case Insensitive Search with g ex command?
There are two ways to achieve this:
One is to set ignorecase, then the pattern regex will ignore the case. Yet, this solution is poor if you are writing a script that may need to be reused by ...
8
votes
How to get line numbers of selected text
The line numbers of the selected text are available in the marks < and >. So you can use e.g. echo getpos("'<") and echo getpos("'>") to get the start and end of the selected text.
...
8
votes
Accepted
Copy output of bash command to system clipboard?
Everything after ! will be a command, including |. So what you're running is:
:redir @+
:w !node | redir END
This makes sense, since using | is shell commands is common to pipe output.
The easiest ...
7
votes
Accepted
Delete text after match in Ex?
There is a better way of accomplishing the task you showed in ex mode, which is by using the :delete command and a basic cmdline-range. To delete all lines between and including the beginning of the ...
7
votes
Accepted
How to get and use the number of each matched line in a global command
One way to do it:
clear the register:
:let @a=''
append search results in it:
:g/TODO/let @A = getpos('.')[1] . ' ' . getline('.') . "\n"
Re: BONUS remove indentation in the global command:
:...
7
votes
Accepted
How can I repeat last Ex-mode command in normal mode?
Use the /c flag at the end of your substitution in order to confirm each substitution:
:%s/foo/bar/gc
See :help s_flags.
Use & to repeat the last substitution without the flags. See :help &....
7
votes
Accepted
Reducing multiple blank lines into single blank line. Exceptional case
Why your command doesn't work
The simple answer is the . as the end range for your :j command will match the space in your offending line. This means that your nearly empty line will not be removed/...
7
votes
Accepted
Replace with hex character
From :help todo:
Substitute with hex/unicode number "\%xff" and "\%uabcd". Just like
"\%uabcd" in search pattern.
In other words, this isn't implemented yet.
You can do it interactively, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ex-mode × 116command-line × 13
substitute × 10
regular-expression × 9
ex-command × 9
normal-mode × 8
external-command × 8
vimscript × 7
key-bindings × 6
search × 6
register × 6
global-command × 6
cursor-motions × 5
invocation × 5
buffers × 4
visual-mode × 4
macro × 4
linux × 4
posix × 4
neovim × 3
cut-copy-paste × 3
functions × 3
line-numbers × 3
range × 3
original-vi × 3