Questions tagged [ex-mode]
Vim's ex mode is similar to the command line mode which is designed for Batch processing.
117
questions
0
votes
1
answer
33
views
exim incorrect substitution count?
I'm having strange bevahiour with Vim 9.0
$ ex --version | head -3
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Sep 30 2022 03:09:54)
macOS version - x86_64
Included patches: 1-270
$ VIM_POSIX='...
1
vote
2
answers
34
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 ...
4
votes
1
answer
206
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
:...
1
vote
0
answers
192
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 ...
2
votes
1
answer
441
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. ...
2
votes
1
answer
31
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 ...
3
votes
1
answer
73
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 +&...
3
votes
1
answer
82
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
1
answer
31
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
1
answer
203
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
3
answers
745
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
2
answers
59
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
1
answer
84
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
2
answers
165
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
1
answer
81
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 ...
1
vote
1
answer
71
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
1
answer
165
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
1
answer
83
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 ...
1
vote
0
answers
38
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
1
answer
1k
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 ...
1
vote
1
answer
181
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
1
answer
53
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
1
answer
217
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 ...
2
votes
2
answers
723
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 ...
2
votes
1
answer
218
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
1
answer
744
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 ...
4
votes
0
answers
91
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 ...
2
votes
2
answers
145
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 ...
4
votes
2
answers
279
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 ...
3
votes
2
answers
860
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, ...
1
vote
0
answers
216
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 ...
0
votes
2
answers
725
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
4
answers
743
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
2
answers
384
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
1
answer
103
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
2
answers
193
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
0
answers
36
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,...
0
votes
1
answer
254
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 ...
3
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 ...
1
vote
2
answers
288
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. ...
1
vote
2
answers
1k
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.
3
votes
1
answer
2k
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 ...
0
votes
1
answer
102
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
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 ...
0
votes
1
answer
271
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
1
answer
298
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 ...
2
votes
2
answers
218
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 ...
2
votes
1
answer
922
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 ...
0
votes
2
answers
295
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 ...
0
votes
1
answer
627
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
...