Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [ex-mode]

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

1
vote
4answers
152 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
69 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 $...
2
votes
1answer
29 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
0answers
37 views

Why does not Vi buffer operation "n (double quote) work in Vim?

I have read from a book that, vi allows the following commands: "ayy, which means yank the current line into buffer named a. "dP, which means paste the content in buffer named d before the cursor. ...
0
votes
2answers
29 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
29 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
1answer
41 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 ...
1
vote
1answer
190 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
87 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
356 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.
2
votes
1answer
198 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
1answer
55 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
407 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
63 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
141 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 ...
3
votes
2answers
116 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 ...
3
votes
1answer
608 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
2answers
83 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
1answer
560 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 ...
1
vote
1answer
60 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....
0
votes
1answer
254 views

Pipe the content of the current buffer into an external command and then read the output into a new empty buffer?

I've established that it's possible to take the contents of a buffer (even one that isn't saved anywhere) and pipe it to a command. like so: :w ! petit --wordcount But! Is it possible to take the ...
0
votes
4answers
198 views

redirect exmode command to variable

This is perhaps a beginner question, but I'm unable to (intuitively) figure out how to redirect the output of an ex command to a variable for further processing. Some background: I'm trying to create ...
3
votes
1answer
676 views

How to set the vim path to your bash PATH?

I'd like my $PATH to be available to vim when running commands with !. How do I set vim's set path= to my environment variable $PATH?
2
votes
1answer
225 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 ...
0
votes
1answer
651 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
1answer
265 views

Issue with using ex commands

I asked a question a few days ago in the Linux/Unix SE about how to copy a block of text from one file to another in a way that I could use for a script of many similar files. I thought I came up with ...
1
vote
1answer
118 views

How to feed visual selection into ex?

Is it possible to select the text of a command from a buffer in visual mode and then feed it to ex? Like so I can modify the text of the command in the buffer and then after I press some keys have it ...
0
votes
1answer
350 views

Is it possible to chain multiple ex commands together with a single range?

I often want to move and indent code at the same time. Is it possible to do the following. Original text: 1: var x = foo(); 2: bar(x); Desired text: 1: setTimeout(function(){ 2: var x = foo(); ...
1
vote
1answer
498 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 ...
2
votes
1answer
69 views

Prepare a range for an ex command without visual mode or line numbers

Background: I can pipe a paragraph through an external command using !ip and the cursor goes to the end of the following prompt: :.,.+5! If I want to use the built-in sort or center functions I ...
2
votes
1answer
104 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 ...
2
votes
1answer
593 views

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

I'm somewhat new to vim (read: really new). I'm used to vi-keys for moving and I understand the concept of operators vs motions vs commands and whatnot, but I'm still learning the commands. When I ...
1
vote
1answer
134 views

Automatically set the 'number' option in Vim when entering Ex mode, set 'nonumber' in visual mode

I have previously asked this in StackOverflow (May 2015), but without getting any replies that I was completely happy with. This ought to be simple: I want to configure Vim to set number whenever ...
4
votes
1answer
60 views

How to get particular time format inside the text file

I want to paste particular date format (mm--dd-yyyy) using following terminal command in ex command mode: :r !echo $(date +"%d-%m-%Y") Its print the current file name instead of printing date, ...
3
votes
1answer
48 views

How to insert data from another file's particular lines

I want to insert data from another file , especially particular lines[10-23] from the file. I tried the following :r filename 10-23 But It returns the following error E172: Only one file name ...
6
votes
3answers
2k 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 ...
1
vote
2answers
89 views

Joining consecutive commas using ex-mode

I have a large list of scores that looks likes this: Michelle ,46419 ,32413 Frank ,46412 ,33810 Steve ,28333 ,17830 ,37 Joe ,136 ,93 Alicia ,121300 ,84146 How can I move my list in Vim so it is re-...
1
vote
2answers
531 views

Case Insensitive Search with g ex command?

How can you do a case insensitive search with line contexts displayed in vim while using the :g ex command? I tried the following but it doesn't seem to work... g/pattern/z#.1i|echo "================...
1
vote
0answers
143 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....
4
votes
2answers
132 views

Can I run -c in batch mode (without opening the curses display)?

I find myself performing a small shell loop (involving vim) to transform files into the correct line endings for my system. It looks as follows: for i in *; do vim -c 'set ff=dos' -c 'wq' $i; done ...
5
votes
1answer
113 views

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

So Lets say I have a list \Summit \SummitSign \sun \ProgrammingOnABoat \SunCloud \SunshineOpenCircled \sup \supdsub \supdsub \supedot \suphsol \suphsub \Summit \SummitSign \sun \Summit \...
5
votes
1answer
101 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&...
3
votes
2answers
80 views

Break long comments

Given the file alfa.c: // Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his, soluta salutandi persequeris vel ne, facete impedit contentiones te eam. Ut utamur habemus qualisque ...
15
votes
1answer
10k views

How do I exit ex input mode?

I got stuck in ex input mode by typing :i. Now I cannot use any commands. All there is just a string of text. Pressing escape does not get me out of it, typing :visual does not get me out of it, and ...
3
votes
1answer
402 views

How do I map a key to search for a pattern and replace it with newline in ex/vi?

I am trying to map q in vi (not Vim) to find a pattern and replace it with newline: Name1 Name2 Name3 Name4 to Name1 Name2 Name3 Name4 When I try ([Ctrl-V] and [Enter] are actual keystrokes) :map ...
7
votes
2answers
177 views

Executing a command on delimited lines

How can I run a command on all lines delimited, say by \begin{otherlanguage} and \end{otherlanguage}? For example, 1 This line should not be affected, 2 \begin{otherlanguage} 3 but ...
1
vote
1answer
547 views

Replace every other line

Given file alfa.txt: 10 11 12 13 I can remove every other line: $ ex -sc 'g/^/+d' -cx alfa.txt $ cat alfa.txt 10 12 However I cannot replace every other line: $ ex -sc 'g/^/+s//> /' -cx alfa....
2
votes
1answer
293 views

Global append lines

Given file alfa.txt: 10 11 12 13 I would like to append a line of text after every line. This is simple enough with sed: $ sed aBRAVO alfa.txt 10 BRAVO 11 BRAVO 12 BRAVO 13 BRAVO However I am ...
5
votes
2answers
250 views

Invert range selection

I can remove the last 10 lines like this: ex -sc '-9,d|x' f.txt However, I would like to invert the selection, or remove all lines except the last 10. Is this possible?
2
votes
2answers
593 views

Insert blank line after different lines

Given file alfa.txt: foxtrot golf hotel india juliet I would like to insert a newline after lines 2 and 4. I have this command: ex -sc '2pu_|4pu_|x' alfa.txt However it is inserting lines after ...