Questions tagged [repeated-commands]
Questions about replaying the same command. This includes the dot command (.), @ macros, @: and similar methods.
103
questions
58
votes
2
answers
17k
views
How can I view and edit my recording (i.e. recorded macro)?
I'm using complex repeats to record my operations (qq to record, some operations, q to stop) and I did a mistake.
It is possible to see what I've recorded and correct the mistake, instead of doing it ...
19
votes
4
answers
1k
views
Can I repeat the last UI command?
I know that I can use . to repeat the last editing command.
Is there a way to repeat the last UI manipulation command?
For example, I can write 10<C-W>- to shrink a window by ten rows.
It'd be ...
17
votes
3
answers
11k
views
How to replace more than one character without entering insert mode?
I have a file with a line that looks like this:
foofoo.xy.barbar
I want to change the xy to gh. I tried to do 2r -> gh, but obviously that didn't work, as it replaced the xy with gg and then moved ...
17
votes
1
answer
29k
views
Execute normal command over range
For a file looking like this:
2 AD,42.546245,1.601554,Andorra,376
3 AE,23.424076,53.847818,United Arab Emirates,971
4 AF,33.93911,67.709953,Afghanistan,93
5 AG,17.060816,-61.796428,...
12
votes
6
answers
8k
views
How to copy first four characters of every line to the end of that same line?
Given a series of lines that look similar to this:
2001 "Some Kind of Title," Author's Name, Publication Name, 1 Mar.
2002 "Some Kind of Title," Author's Name, Publication Name, 12 Oct.
2003 "Some ...
12
votes
2
answers
1k
views
Save last action (.) in a macro
Use Case
I'm in normal mode. I've not explicitly thought about recording a macro, but I make a single command change. I can now repeat this action by using dot.
I now realize it's a useful action to ...
11
votes
2
answers
4k
views
How can I insert a character repeatedly until even with next line?
Say I have a comment like this:
//This is a comment
And I want to make it like this:
//*****************
//This is a comment
//*****************
Is there an easy way to insert a character ...
11
votes
3
answers
940
views
How to insert repetitive text with minor difference in vim?
I want to insert text like this:
similar text wordA similar text ...
similar text wordB similar text ...
similar text wordC similar text ...
I know I can paste the text many times then use the ...
11
votes
4
answers
952
views
Bundling command sequences together for repeat (.)
Consider:
apple
pear
Put your cursor on the first line and type Yp, producing:
apple
apple
pear
Put your cursor on the pear line and type . to repeat the last command. This repeats only the p (...
10
votes
6
answers
2k
views
Delete n lines skip 1 line script
I want to create a basic Vim script that simply deletes n lines, skips 1 line and repeats until the end of the document. I don't care about specific matches, I just want to delete the line. For ...
9
votes
2
answers
6k
views
Repeat motion easily
Sometimes I'll guess a count for a cursor movement, say 4b but it was actually 7 words away. If I'd performed an edit I could press . to repeat; I could have done @: to repeat a command line.
It ...
9
votes
1
answer
149
views
Is there a way to repeat the pænultimate (or older) change?
The . command is super useful for quickly doing the last primitive action again. However, any other modification I do in between will override this.
Is there a way to recall&repeat older changes ...
9
votes
1
answer
187
views
How can I prevent (or at least prompt to confirm) absurdly large numbers from being used to prefix commands?
It doesn't happen as often as you'd think, but it happens occasionally, and I don't even own a cat.
Basically if you mash the number row or numpad and then happen to hit a keycombo that triggers a ...
8
votes
4
answers
2k
views
Replace . with -> in specific places
Sometimes I need to replace . with -> when fixing code.
Usually search and replace cannot be used because there will be many (hundreds of) dots (.) and only a few ones of them must be changed.
...
8
votes
1
answer
2k
views
Understanding line reference differences through :g/^/norm and through :%norm
Let's say that I have the following very simple file
a
b
c
d
e
and I've decided that I want to add empty lines after each line. Several different methods immediately jump to my mind. We might just ...
8
votes
1
answer
325
views
Delete multiple lines by address
I was looking at this vimgolf challenge, and I thought it would be nice to delete specific lines by address. I know I can do this with :<line_number>d, but is there a way to list multiple line ...
7
votes
1
answer
1k
views
Repeat last yank
I'm appending text to "a" register with:"AyW.
If I wanted to repeat last change I would use:. But in this case I would like to repeat the last yank command.
Is there a command to repeat the last yank (...
7
votes
2
answers
5k
views
How to repeat last action with movement?
Assume the content:
foo fnord bar;" >> /tmp/foo/derp
gnarf foo fnord bar;" >> /tmp/foo/derp
I want to jump to the " and delete to end of line and repeat that over the rest of lines.
Yet ...
7
votes
1
answer
2k
views
How can I repeat last Ex-mode command in normal mode?
I'm looking for something like . or @@ that will work in normal mode for repeating the last Ex-mode command.
As per the rule of the XY problem, I'll also state the broader goal:
I have a fancy regex ...
7
votes
1
answer
214
views
Is it possible to make a numerically-prefixed hotkey run a function that many times?
I find that if you enter a numeric prefix prior to executing an ex command, the convention that it applies is to set up the command to prep an operation across a line range. It is explained in the ...
6
votes
2
answers
143
views
Unexpected behavior using "<count>J" to join multiple lines
When I prefix the J ("join") command with a count, Vim is joining one fewer line than I expect. For example, with the cursor at the first column, first line of the following,
one
two
three
four
five
...
6
votes
2
answers
146
views
Should the output of the -w {scriptout} flag work to replay actions using the -s {scriptin} flag?
According to the :help startup-options, this is -w's behviour
-w {scriptout} All the characters that you type are recorded in the file
"scriptout", until you exit Vim. This is ...
6
votes
1
answer
291
views
Why copying from named register cannot be repeated using dot operator?
I am copying a word with: viwy (visual, inner, word, yank)
Now I would like to replace some other word: viwp.
This works only once, because each word is replaced by the last removed word.
Ok, so I ...
5
votes
4
answers
5k
views
repeat insert at beginning of line
When I repeatedly inserting at the beginning of a line it is problematic because the cursor ends up in the middle of the line so I have to move back to the beginning of the line each time. So, for ...
5
votes
3
answers
5k
views
How can I add a prefix to a few lines? [duplicate]
I find it sometimes useful to add a certain string to the beginning of a line, and sometimes I would like to do this to a few lines, and I don't like moving to each line and change it. Assuming I know ...
5
votes
4
answers
3k
views
Execute command for multiple files
I often want to run multiple vim commands on multiple files.
Consider the files file1.txt, file2.txt, and file3.txt: I might want to run :retab and then some :%s/ /, / for instance.
How can I "...
5
votes
5
answers
2k
views
How to apply a register to a command?
I have the given file
4 apples
2 bananas
6 peaches
3 grapes
1 pineapple
5 pears
3 tomatoes
What I want to do is to receive the following result instead:
apple apple apple apple
banana banana
peach ...
5
votes
2
answers
918
views
How to repeat the last command in Ex?
I've the file, like:
name = foo
# unknown number of lines ...
features_exclude[rules_config][] = rule1
features_exclude[rules_config][] = rule2
features_exclude[rules_config][] = rule3
...
5
votes
2
answers
699
views
Repeating the last move using . (w followed by .)
I read that . is used for repeating the last command in Normal Mode. So if I used the command 2w move forward two words and then press . then I would expect to move two words more however this does ...
5
votes
1
answer
687
views
Repeat replace one character (r) for next occurence
I'm using r a lot (e.g. for replacing " with ' when refactoring code). Is there an easy way to do something like this:
For text: values = ["a", "b", "c"].
Place cursor on first ", press r' to change ...
5
votes
1
answer
119
views
Register for your last action (.)
Vim has a lot of useful registers from which you can access the contents of various actions. There's ": for the last command in the command line, "/ for the last search, ". for the last ...
4
votes
1
answer
522
views
How do I run a shell command periodically and silently from within Vi?
Before I came here, I went to executing command from within Vim and learned it can be done using:
:!command
Then I went to executing it silently and figured how that I need to run:
:silent exec ...
4
votes
2
answers
111
views
Make a frequent RSpec edit easy & repeatable
Writing unit tests in RSpec, I frequently change something like this,
it 'eats pizza' do
pizza = build(:pizza)
expect(subject.eats?(pizza)).to be_true
end
to this,
let(:pizza) { build(:pizza) }
...
4
votes
0
answers
54
views
Vim: is there a way to persist the last edit?
When you make a change, like ifooESC to insert the text foo, this can, of course, be repeated using ..
However, if you quit Vim, in spite of Vim saving all sorts of state, including the contents of ...
3
votes
3
answers
2k
views
How to apply a macro for every single matching pattern
Macros can be repeated for every line matching a pattern with the global command as explained in this answer.
This applies to every single line, but is it possible to do it for every single match? so ...
3
votes
2
answers
3k
views
Down and . X times?
Say I perform a combination of keys and now they are registered in .
Now I want to go down X lines and run . on each one.
For example say I have:
{colorComponentId: 0, value: (value.warmWhite * 255)...
3
votes
2
answers
194
views
Is there a way to encapsulate a variable with a method with a repeatable action?
I am trying to encapsulate variables with a method. For example, I am converting this:
return variable1;
To this:
return verify(variable1);
Is there a way to quickly repeat this action (ideally ...
3
votes
1
answer
629
views
How to delete blocks of text which contain a specific string?
I have a file which has the following structure
From: foo@example.org
Subject: Bar
Date: 2017-06-27
Mailbox: /some/dire/ctory
<CR>
Such a block always contains of four lines followed by an ...
3
votes
1
answer
2k
views
Repeat last normal command
Well, there is ; to repeat the last move in some cases.
There is the . to repeat last change.
But if I just did za or @a, is there a way to repeat it? I guess such a mechanism should ignore plain ...
3
votes
1
answer
2k
views
How to disable key repeat in vim?
I am currently try to break inefficient habits, and one bad habit is to keep a button pressed, e.g. keep pressing j to move down approximately 10 lines instead of moving exactly 10 lines down with 10j,...
3
votes
3
answers
238
views
How can I use the `global` command to prepend 'document headers' to 'document lines'?
I am trying to change a text file with data in 'document' form into unnormalized csv. The data are a list of hymn authors ('document header') and for each author a list of one or more hymns they have ...
3
votes
1
answer
205
views
Understanding the use of ., in the global command
While doing some updates to my .vimrc file today, I stumbled across this for condensing blank lines (really empty lines) into a single empty line.
:map ;b GoZ<Esc>:g/^$/.,/./-j<CR>Gdd
...
3
votes
2
answers
248
views
Is it possible to properly repeat a visual replacement?
It is possible in vanilla vim to:
visual select some number of characters, e.g. a variable name in code
type c to begin replacing selection in insert mode
type a replacement (variable name)
exit ...
3
votes
2
answers
404
views
Repeat complicated motions
I know that similar things were asked here several times. I know that to repeat a motion ; works. Unless it doesn't(in case there is count for example), but then repmo.vim usually works. And I know ...
3
votes
3
answers
125
views
remap ':' to maintain last command, and erase all char if any key other than <CR> was pressed
As the title stated, remap ':' to maintain last command, and erase all char if any key other than <CR> was pressed.
possible use cases:
I have typed a long command, and I may or may not ...
3
votes
1
answer
108
views
Repeat not only last command
The repeat command . is awesome. Is it possible to cycle through the last few commands, instead of only being able to repeat the last command? Something like yankring for repeat?
3
votes
1
answer
158
views
Repeat works reuses unnamed register. Bug or a feature?
Suppose I want to get from this a,b to this 'a','b'
Yeah, yeah, yeah, I know about surround plugin. The cursor is on the start of line
I'm doing cw<bsp>'<C-r>". I have delimitMate plugin, ...
3
votes
1
answer
132
views
Repeat last "change inside text object" command without the inserted text
Is there some way to repeat something like cit and be left in insert mode instead of automatically repeating the previously entered text?
For example, suppose I have the following lines:
<th>...
3
votes
0
answers
436
views
How to repeat last mapping/action?
I know that I can repeat last change with ., last command with @: and last motion with repmo plugin. What about other actions such as switching to the previous/next tab (gT/gt)? Is there a command for ...
2
votes
2
answers
2k
views
Repeat complex actions over a number of lines (in Vim)
I am editing a LaTeX document and I wanted to figure out the most efficient way to convert itemize environment to tabular environment. Here is an example of what I want to accomplish:
Change
\begin{...