Questions tagged [ex-mode]

Vim's ex mode is similar to the command line mode which is designed for Batch processing.

Filter by
Sorted by
Tagged with
3
votes
1answer
50 views

How to input <CR> into ex command from script or commandline?

I recorded a macro, that has an enter in it ggd/{<CR>Gdd but of course is ^M. What I want to do is run this on a bunch of files from the commandline which I guess would be something like ex +&...
2
votes
1answer
20 views

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

If I hit Ctrl+V and then Escape while in insert or ex mode, I get ^[ as a single character. If I hit qqEscapeq and then go see :registers, I see that q contains ^[<80><fd>a, which are ...
1
vote
1answer
23 views

Find definition of ex command

Normally when I try to trace back a setting to where it was set in my vim config (or plugins) I use something like: :verbose set undodir undodir=~/.vimundo Last set from ~/.vimrc line 62 To ...
4
votes
1answer
82 views

How to reference a register in an ex command

I'm trying to write what I thought would be a simple macro to take some values that have been yanked into some registers (a & b) and use bc to do some addition with those values. Here is the ...
3
votes
3answers
660 views

How do I emulate Sed's y command?

For the very first time I find myself in need for the y command Sed has. For those who don't know what y does, here's an example: $ echo x1 x2 x3 | sed 'y/123/234/' x2 x3 x4 Apparently Vim has no way ...
0
votes
2answers
46 views

How to execute a shell script from a line in a file with `%` in it

I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use Y:!^R", but this particular script has % in it, which is ...
0
votes
1answer
32 views

au VimLeave ex mode command not returning output

I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer). I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I ...
2
votes
2answers
86 views

Why "normal n" does not work in Ex mode?

For example, if I want to find all bar lines and print them. $ cat file line foo line bar 1 line bar 2 $ cat cmd norm gg /bar p norm n p $ cat cmd | vim -u NONE -es file line bar 1 line bar 1 $ As it ...
4
votes
1answer
69 views

Why do some Ex commands not need a white space before a path argument?

For example, why does this work: edit/home/foo/bar.txt (I had to enter visual to see the changes) I was expecting a whitespace after edit, like: edit /home/foo/bar.txt I couldn't find a reference in ...
14
votes
1answer
3k views

delete lines that match a pattern from a given line to the end of the file

If I have a file with a lot of comments in it and I want to delete all of the comments from say, line 3 to the end of the file, what's the best way to do it? I'm stuck, since what I first tried doesn'...
1
vote
1answer
50 views

Expansion of cmdline-special vs `=

Reading (and re-reading) the Vim docs on when :h cmdline-special expansion happens versus :h `= expansion, the :grep example below has me stumped: :let &grepprg = "echo 'grep: $*'" ...
2
votes
1answer
116 views

How do I find the ex/vimscript equivalent of a normal-mode command?

Some operations can be done with either normal-mode commands or ex/vimscript commands. For example, :resize 1 does the same thing as 1 <C-W> _. In scripts, it's possible to simulate normal-mode ...
0
votes
1answer
31 views

Conversion of Ex command to mapping not always working

Here, I'm using a mapping from this post. Edited it to my liking like so: nnoremap <F3> :execute 'help' expand('<cWORD>')<CR> that works. Problem is, i wanted to add | only so that ...
4
votes
2answers
806 views

How to get line numbers of selected text

Is it possible to get the line numbers of selected text to pass to an external command? Context: I'd like to integrate pyfmt into vim. Ideally, I'd like to be able to select some text and type some ...
1
vote
0answers
34 views

Is there a way to use ex mode similar to ed, with append only lines and all curses like features disabled?

I'd like to use ex similar to how ed behaves on an old teleprinter, so without ANSI Control sequences and CRT manipulations. This way it would be easier to interact with it from a Braille terminal, ...
3
votes
1answer
656 views

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

I can use vim / ex to grep a file using the following invocation: ex -c'g/foo/p' -cq -s afile.txt I'd really like to use a similar command to grep some text from stdin. I thought the following command ...
0
votes
1answer
96 views

How to escape a single quote when passing an ex-mode command from the command line, back to the command line?

Here is the command I'm trying to escape a ' from bash, to vis' to ex-mode, and then back to bash so it can be read into the buffer again: vi -c 'sp | enew | read ! echo "Use to jump between ...
1
vote
0answers
157 views

Can I use feedkeys() inside of a keyloop implemented by getchar()

I implemented a fuzzy filter, which accept a list argument, open a window with a scratch buffer whose content set to the list, then waiting for use input and do filtering. Here is why I ask this ...
1
vote
1answer
37 views

Is it possible to use word completion (e.g. `Ctrl-N`) in Ex mode?

I want to use word completion in Ex mode, similar to using Ctrl-N in Insert mode to complete the current word. Suppose, I want to do a substitution: :%s/<pattern>/<replacement>/gc. If the ...
1
vote
1answer
118 views

Is it possible to view a history of commands (per mode) executed in Vim?

I sometimes execute commands in Vim by mistake, either in normal-, visual-, or ex-mode and have no idea what was executed. Is it possible to see a history of executed command per mode in Vim? I know ...
5
votes
1answer
2k views

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

I am interested in mastering the art of using ex from the command line (vi -esc <commands> / ex -sc <commands>). I got the basics worked out, but one thing eludes me: How do I add text ...
2
votes
2answers
358 views

g/pattern/d but check first

I'd like to use Ex mode :g/pattern/d to delete most (but not all) of the rows containing pattern, but I want to see each one first and confirm before deleting, similar to :s/pattern/foo/gc. Is there a ...
3
votes
1answer
1k views

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

I'm setting up a vim environment install script. I'm using vim-plug for plugin management. What I'd like to do is, from the install.sh, run vim and call PlugInstall to trigger plugin download and ...
1
vote
1answer
92 views

How to paste copied character in ex mode?

Pressing yl I can copy the character where cursor locates. Now I press : to enter into last line mode, I enter %s/. Now I want to paste the character copied by yl. How can I do that?
6
votes
1answer
675 views

vim, vimdiff, ex, view, rvim and rview: How do they start in a different way when they are symlinks to the same binary?

I just installed version 8 of Vim and notice in the bin directory of the install location that all the above mentioned programs point to the same binary – vim. Then, how does it know when I invoke ex ...
2
votes
2answers
431 views

vim ex mode write to stdout

I am trying to output the contents of a file opened in vim ex mode to stdout. vi -es +'%write !tee' +'q' ./testfile Unfortunately, it does not write anything, although if I open the file in ex mode, ...
3
votes
0answers
60 views

Why does vim ex mode 'print' command insert a space on empty lines?

Take the following example: $ printf "a\n\nb\n" | vim -E -c "%p" -c 'q!' /dev/stdin | hexdump -C 00000000 61 0a 20 0a 62 0a |a. .b.| 00000006 I would not expect that ...
1
vote
2answers
256 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....
173
votes
9answers
64k views

Does Ex mode have any practical use?

Vim has an Ex mode that can be entered by entering Q, and a command line mode that can be entered with q:. A common complaint amongst new vim users is that they enter these modes accidentally when ...
2
votes
2answers
100 views

How to replay ex commands in order?

I often have a situation where I will direct some output to a file then open it in vim and use ex commands (substitution, keep lines, delete lines, etc) to massage the output to a form I want. However ...
3
votes
2answers
114 views

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

tldr Moving in ex command line is slow because common readline motions (like in bash) are not supported. Are there any improvements for this? I often find myself with an ex command in the command ...
7
votes
4answers
5k 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 ...
2
votes
2answers
300 views

Is it possible to use the :put Ex command using column numbers?

The documentation for :put says that the command accepts a line. That is, it puts the content after the line specified. Is it possible to put the content at a particular mark? For example, say I am ...
5
votes
2answers
212 views

Equivalent of !n in bash in vim for ex commands?

I'd like to be able to view the last n commands, similar to the history command in bash, and then be able to execute the nth command similar to the way it is done in bash by using !<command number&...
4
votes
1answer
506 views

Why substitute doesn't work in silent mode?

I'm playing with ex and I've found that removing trailing spaces for multiple files in silent mode doesn't work as expected. The following examples doesn't work as expected (whatever I use argdo or ...
0
votes
1answer
422 views

Add a line after 1 line after match in Ex mode

I need to search for a string in a file, then I need to some text after one line following the first match. I need to perform this for a number of files in a script. I am trying to use vim ex mode ...
1
vote
4answers
557 views

In Vim ex mode how to re-use a string from the default buffer in the command

I'm trying to modify this file, by extracting the very first line in the file and prepend it to each of the consecutive lines until end of the file black widow card Friday berry I used ex command (...
0
votes
2answers
315 views

Why is `vim -E` always exiting with non-zero exit code when using here-doc?

see the following session in dash: $ printf "foo\nbar\n" > testfile $ cat testfile foo bar $ vim -E testfile <<-EOS > 1 > s/foo/baz/ > x > EOS $ echo $? 1 $ cat testfile baz bar $...
3
votes
1answer
95 views

Why does colon in shell command read the wrong file?

I write ruby test files in vim, and regularly run tests from the file I'm editing by running :!rspec %:N or something similar (to execute the test at line N). The problem is that when the first ...
0
votes
2answers
152 views

How to yank a specified amount of lines in vim -E mode?

This is my first-post and question here so please be gentle (but also tell me if, it I wasn't specific enough etc...) So my questions seems rather simple to me, but still blocks me and I can't find ...
0
votes
0answers
34 views

How do you end the command when using :c?

When using the ex command change (c), carriage returns become part of the input, so how do you indicate that you are done entering text? (I notice that if I hit the backspace, it finishes the command,...
3
votes
1answer
2k views

How to copy lines from 4th till 11th and paste it from 15th till 22th line in ex mode?

To move cursor on the 4th line,toggle into normal mode,input 8yy. To move cursor to 15th line,and toggle into normal mode,press p . Now the lines from 4th till 11th was pasted from 15th till 22th ...
0
votes
1answer
200 views

Transform lines: prepend with incrementing number and string and append with string for each line in one step

I have the following lines: abc07 bca08 xyz17 And I would like to transform it to: [0]="abc07" \ [1]="bca08" \ [2]="xyz17" \ Based on this question, I can do the first part and the end ...
2
votes
1answer
1k views

How to use normal mode commands in ex mode?

When I start vi/vim as ex, I can use the -c option to provide the set of ex commands to apply to a file: echo Yes | ex -sc 's/Y/y/|%p|q!' /dev/stdin yes But how can I use normal mode commands like ...
1
vote
2answers
241 views

Overwrite buffer with system clipboard by ex command

I'm trying to find the right ex command to overwrite the current vim buffer with the system clipboard. The relevant system clipboard register is "+ in this case. My first guess was to use :%+p; i.e. ...
0
votes
2answers
870 views

How to write the output of scriptnames into a file? [duplicate]

:scriptnames can list all plugins installed in my vim. How to write the output of scriptnames into a file? :scriptnames > names.txt It can't do the trick.
0
votes
1answer
88 views

Discrete line numbers specified individually not as range

I was trying to find out if it is possible to give an ex command a list of lines instead of a range?
1
vote
3answers
1k views

Execute() is not returning a value

I am apparently not getting a return value from execute(): function! Example() return 5 endfunction :echo execute("call Example()") Just results in a blank line. The 5 is not printed. Why is ...
0
votes
1answer
214 views

What does execute() return?

In the function-list, it gives execute() as running an ex command, but it does not seem to be returning a string as I expect. For example, if I run this on a file that has 'abc' in it somewhere: :...
0
votes
1answer
258 views

How do I get a numeric return value from an Ex command?

How can I get a numeric return value from an Ex command. For example, if I want to set a variable to the number of times a pattern occurs in a buffer. I tried this: :let answer=exe('%s/xyz//n') but ...