Hot answers tagged

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 ...
user avatar
  • 10.4k
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 ...
user avatar
  • 16.6k
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....
user avatar
  • 16.6k
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 ...
user avatar
  • 8,032
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 ...
user avatar
  • 3,598
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 ...
user avatar
  • 1,037
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 (...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 6,426
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.
user avatar
  • 1,881
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 ...
user avatar
  • 32.8k
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 ...
user avatar
  • 16.7k
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 "...
user avatar
  • 18.3k
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 ...
user avatar
  • 12.6k
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 ...
user avatar
  • 16.6k
9 votes
Accepted

Reusing search pattern in ex mode

Sure, just leave the pattern in the substitution empty: :%s//replacement/
user avatar
  • 5,894
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 ...
user avatar
  • 6,426
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: :/...
user avatar
  • 15.2k
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.
user avatar
  • 559
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 ...
user avatar
  • 32.8k
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 ...
user avatar
  • 1,596
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. ...
user avatar
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 ...
user avatar
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 ...
user avatar
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: :...
user avatar
  • 9,310
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 &....
user avatar
  • 32.8k
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/...
user avatar
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, ...
user avatar
  • 4,075

Only top scored, non community-wiki answers of a minimum length are eligible