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
1 vote
2 answers
21 views

Where's the documentation for Ctrl-C while in [Command Line] buffer?

Long ago I discovered that q: opens a [Command Line] buffer where I can enter and edit an ex command line using all the power of Vim. Next, some time ago, I discovered that I can access that mode even ...
user avatar
  • 1,638
4 votes
1 answer
154 views

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

I know it's a dumb question, but I don't find the explicit answer in the docs. Learn Vimscript the Hard Way's chapter 12 is about autocmds. Here are a few examples: :autocmd BufNewFile * :write :...
user avatar
  • 1,638
1 vote
0 answers
45 views

How does .vimrc relate to ~/.config/nvim/init.lua?

When I heard neovim had a "native language client", I wanted to trying moving it. Previously, I was using a language server loaded through vim-plug. This was always problematic. When I ...
user avatar
1 vote
1 answer
73 views

Is the goal of Lua in neovim to replace Ex, and if not what is it?

I am a new user to neovim, and a moderator on this site said You seem to imply that you expect there should be a native way to run [filetype] (and to some extent every Ex command) directly in Lua. ...
user avatar
2 votes
1 answer
27 views

Vimscript - Prevent Column From Moving When Using a Count

When you use a count to a key mapping it goes down count number of times and resets to column 1. Actually it already resets to col 1 when entering the function if there is a count. So I can save the ...
user avatar
3 votes
1 answer
56 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 +&...
user avatar
  • 401
2 votes
1 answer
31 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 ...
user avatar
  • 1,638
1 vote
1 answer
25 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 ...
user avatar
4 votes
1 answer
106 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 ...
user avatar
  • 143
3 votes
3 answers
691 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 ...
user avatar
  • 1,638
0 votes
2 answers
51 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 ...
user avatar
  • 173
0 votes
1 answer
46 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 ...
user avatar
2 votes
2 answers
114 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 ...
user avatar
  • 131
4 votes
1 answer
75 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 ...
user avatar
1 vote
1 answer
55 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: $*'" ...
user avatar
  • 227
2 votes
1 answer
134 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 ...
user avatar
  • 343
0 votes
1 answer
51 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 ...
user avatar
1 vote
0 answers
37 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, ...
user avatar
  • 111
3 votes
1 answer
898 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 ...
user avatar
  • 133
0 votes
1 answer
119 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 ...
user avatar
  • 3,101
1 vote
1 answer
38 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 ...
user avatar
  • 1,065
1 vote
1 answer
157 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 ...
user avatar
  • 1,065
2 votes
2 answers
505 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 ...
user avatar
2 votes
1 answer
128 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?
user avatar
  • 850
6 votes
1 answer
693 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 ...
user avatar
3 votes
0 answers
71 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 ...
user avatar
  • 141
2 votes
2 answers
115 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 ...
user avatar
4 votes
2 answers
155 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 ...
user avatar
  • 1,137
2 votes
2 answers
566 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, ...
user avatar
  • 123
1 vote
0 answers
181 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 ...
user avatar
  • 881
0 votes
1 answer
494 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 ...
user avatar
  • 151
1 vote
4 answers
603 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 (...
user avatar
  • 63
0 votes
2 answers
335 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 $...
user avatar
  • 545
3 votes
1 answer
97 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 ...
user avatar
0 votes
2 answers
167 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 ...
user avatar
0 votes
0 answers
35 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,...
user avatar
  • 1,859
0 votes
1 answer
212 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 ...
user avatar
  • 103
2 votes
1 answer
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 ...
user avatar
1 vote
2 answers
257 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. ...
user avatar
0 votes
2 answers
915 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.
user avatar
  • 850
3 votes
1 answer
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 ...
user avatar
0 votes
1 answer
96 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?
user avatar
  • 103
1 vote
3 answers
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 ...
user avatar
  • 1,859
0 votes
1 answer
233 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: :...
user avatar
  • 1,859
0 votes
1 answer
269 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 ...
user avatar
  • 1,859
2 votes
2 answers
187 views

What is the relationship between command line Ex and Vim?

I have read in various documentation that when Vim is started in Ex mode, it attempts to "act like" Ex, so I gather from this that Ex is a separate program and is not an actual part of the Vim source ...
user avatar
  • 1,859
2 votes
1 answer
895 views

Copy output of bash command to system clipboard?

If I run: :w !node It will take my current buffer and send it to stdin and run the code in node. If I run: :redir @+ | echo "bob" | redir END It ends up on the system clipboard. But if I want to ...
user avatar
  • 3,101
0 votes
2 answers
232 views

Moving highlighted text to another file

I have no idea how to do this, but here's my idea: Highlight some text in visual mode, type an ex command and a file name. It takes that highlighted text, deletes it, and appends it to the file you ...
user avatar
0 votes
1 answer
619 views

How to remove lines where the first "word" is non-unique

I have a large data file of comma separated variables. I need to remove all lines where the first entry (a number up to four digits) is non-unique. A typical example of what I am working with is below ...
user avatar
  • 101
1 vote
1 answer
85 views

How to print only pattern, not a line?

I've got the following shell command: $ ex +'/>\zs\w\+\ze</p' -scq! /dev/stdin <<<$"foo>bar<buzz" foo>bar<buzz however it's matching the whole line, instead of the pattern....
user avatar
  • 16.6k