Skip to main content
17 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 (...
John Cowan's user avatar
12 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.
dkns's user avatar
  • 599
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 "...
B Layer's user avatar
  • 20k
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 ...
Mass's user avatar
  • 14.2k
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: :/...
nobe4's user avatar
  • 16.1k
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 ...
grochmal's user avatar
  • 1,656
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. ...
Christian Brabandt's 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 ...
Martin Tournoij's user avatar
8 votes
Accepted

How do I use vim within a Unix pipe-line?

Move the special filename - before -e: cat test.md | vim -e -c'g/foo/p' -cq -s - ^ ✘ cat test.md | vim - -e -c'g/foo/p' ...
user938271's user avatar
  • 5,987
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, ...
Wildcard's user avatar
  • 4,429
7 votes

Does Ex mode have any practical use?

Apart from the usages already mentioned here, ex is also a way to edit files on the linux console if that happens to be on the S/390 platform and the console happens to be line-oriented instead of ...
Thomas's user avatar
  • 71
7 votes
Accepted

How to set the vim path to your bash PATH?

&path has nothing to do with $PATH. Also $PATH is set and used. See :echo $PATH. You should also be able to change its value with :let $PATH = $PATH.':some/path' -- there are a few write only ...
Luc Hermitte's user avatar
  • 17.5k
6 votes

Insert blank line after different lines

The commands are executed serially, which means that before the 4pu_ command is executed, a newline has already been added and your previous line 4 is now line 5. There are at least three ways to ...
Karl Yngve Lervåg's user avatar
6 votes
Accepted

Joining consecutive commas using ex-mode

You can do this with a simple substitute command. Try this: :%s/\n,/, This removes a newline from every line containing a newline followed by a comma. You could also do it like this: :%s/\n\ze, ...
DJMcMayhem's user avatar
  • 17.7k
6 votes
Accepted

How to get particular time format inside the text file

This should work: :r !date +"\%d-\%m-\%Y" But preferred way to do this would be to use strftime(). Here's a link for more info
grodzik's user avatar
  • 4,658
6 votes
Accepted

Call vim command from shell, and suppress output while it operates

I successfully used this command in a non-interactive way, but you have to specify the file containing the Plug calls: vim -E -s -u "$HOME/.vimrc" +PlugInstall +qall You might want to read more on ...
LEI's user avatar
  • 1,636
6 votes
Accepted

g/pattern/d but check first

One way to achieve what you want to do is to use the :s command inside your :g command: We know that we can delete a line, with a confirmation using the following substitution: :s/.*\n//c This will ...
statox's user avatar
  • 50.1k
6 votes

How do I emulate Sed's y command?

BLayer’s answer nicely covers the vimscript equivalent for programming. For completeness, you can also perform these operations on a buffer: on a *nix, :[range]!sed … or :[range]!tr … (this is often ...
D. Ben Knoble's user avatar
  • 26.6k
6 votes

Inserting the content of a register where a macro is recorded results in control characters becoming unicode characters

The ^[<80><fd>a sequence is a <Nop>, which means Vim recognizes this key sequence as valid, but it produces no action at all. The reason why Vim will insert a <Nop> right after ...
filbranden's user avatar
  • 29k
5 votes
Accepted

In Vim, how can you delete following identical rows in a visual selection, without sorting?

If you don't care about removing the first occurrence (leaving the last one), you can use the following global command: g/^\(.*\)\n\_.*\(^\1$\)/d Decomposing: g/ /d " the ...
nobe4's user avatar
  • 16.1k
5 votes

Executing a command on delimited lines

A more specific answer (since you seem to be editing a TeX file): if you use the vimtex plugin (although LaTeX-Box also has this IIRC), you can easily select the whole environment (without the \begin ...
VanLaser's user avatar
  • 9,770
5 votes
Accepted

What's the difference between :open, :visual, and :edit?

So first things first, what is this "ex-mode"? Ex is an ancient text editor written by Bill Joy (the original author of vi). It is very primitive. Ex is a lot like vim, but without normal or insert ...
DJMcMayhem's user avatar
  • 17.7k
5 votes
Accepted

How to feed visual selection into ex?

First select some text visually. Then yank it (y). Then enter ex-mode (:). Finally insert the yanked text (<CTRL-R>0).
XPlatformer's user avatar
5 votes
Accepted

Using the ex mode command line (-c), how would I insert text?

The documentation for -s in Ex mode :help -s-ex states: To be used when Vim is used to execute Ex commands from a file instead of a terminal. So it seems the correct approach is to save your ...
Rich's user avatar
  • 32.2k
5 votes
Accepted

redirect exmode command to variable

I managed to figure this one out. neovim and modern versions of vim provide an execute function that can be used to do just this. let list3 = execute(":oldfiles") does the trick.
Mahmoud Al-Qudsi's user avatar
5 votes
Accepted

How to use normal mode commands in ex mode?

Based on a comment by @statox, I found a solution: echo 'Élève' | ex -sc 'norm! g~w' -c '%p|q!' /dev/stdin éLÈVE The norm command allows executing Normal mode commands. And I had to use two -c ...
Sylvain Leroux's user avatar
5 votes
Accepted

Does vim's ex command line support (readline-like) motions?

I have found two workarounds: This plugin adds some readline motions to command mode As outlined here, one can press Ctrl-f in command mode to make the current command editable like in normal mode. ...
oarfish's user avatar
  • 1,287
5 votes
Accepted

How to reference a register in an ex command

By putting @a and @b inside the quotes you're preventing Vim from evaluating them so you're really just passing the literal strings "@a" and "@b". Pull them out of the quotes and ...
B Layer's user avatar
  • 20k
5 votes
Accepted

Is the colon of the {cmd} argument to autocmd optional?

The last argument to autocmd is an ex command and the leading : is optional in all ex commands, in cmdline and in vim script, though it works a bit differently in vim9script. In documentation a colon ...
Mass's user avatar
  • 14.2k
4 votes
Accepted

Why substitute doesn't work in silent mode?

What happens here is, that the bufdo and argdo command iterate over all buffers themselves. However without writing your changes, vim will refuse to load the next buffer, unless the 'hidden' option is ...
Christian Brabandt's user avatar

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