Questions tagged [repeated-commands]

Questions about replaying the same command. This includes the dot command (.), @ macros,  @:  and similar methods.

Filter by
Sorted by
Tagged with
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 ...
58 votes
2 answers
16k 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 ...
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 "...
1 vote
1 answer
40 views

How to repeat an insert at the end of a line?

I'm quite used to the very basic action of inserting some text, entering normal mode, moving to somewhere else I'd like the same text, and hitting . to do so. This doesn't work if the insert needs to ...
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 ...
1 vote
1 answer
33 views

@: does not work to repeat the :qa command

I open the diff files between 2 code revisions using git difftool. I can use :qa to close the current diff and go to the next one. Rather than pressing :qa repeatedly, I would like to use @:, but I ...
2 votes
2 answers
48 views

How could I make this mapping to a function repeatable? [duplicate]

I have a mapping that comments/uncomments lines like 5gc to comment/uncomment five lines, and I would like to make it repeatable with .. Here is my mapping and the function it uses: function! Comment()...
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 ...
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 ...
2 votes
1 answer
46 views

How do you repeat the last ex command in a macro?

If I do qq:diffthis<CR><C-w><C-w>@:q, the macro @q does not work as expected, since the command line history is not updated when ex commands are performed in macros, and ...
0 votes
1 answer
109 views

How to repeat a command in command-line mode

I need to repeat the delete of matching lines in vscode-vim. Unfortunately the g has not been implemented yet, so I'm trying to figure out a way to repeat the same change in command-line mode using ...
1 vote
1 answer
103 views

Repeat a mapping (like a macro) with dot

There seems to be quite a few questions around g@, its quite a confusing topic. And I can't get it to work. I created these two mappings to edit a line from python dictionary form to variable ...
1 vote
2 answers
29 views

Repeat bracket insertion of auto_pairs_gentle with dot commmand

I have auto_pairs_gentle plugin installed and vim-repeat but the bracket insertion automatically generated by auto_pairs_gentle are not repeated by the dot command. e.g.: Suppose I insert f(x) by ...
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 ...
3 votes
1 answer
204 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 ...
2 votes
2 answers
130 views

Change some words into _

I often do ver_w some times to change words into blanks. I am making quiz this way. What I noticed is that this is a bit of a pain. The amount of work is not so heavy as to make it a macro, but cannot ...
1 vote
1 answer
284 views

Mapping repeat last command

Apologies I am probably expressing myself very badly, that's also why 1 hour searching hasn't yielded the result I wanted yet... Assume I want to replace true with false in a buffer. :s/true/false Now,...
3 votes
2 answers
247 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 ...
0 votes
0 answers
83 views

Is there a modification to make the dot command work intuitively in visual mode?

This is a repeat of a question that I asked on the Vim subreddit but didn't receive a helpful answer for. I think that this should be do-able, but I'm not good enough at Vimscript or Lua yet to ...
11 votes
3 answers
939 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 ...
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 ...
1 vote
1 answer
23 views

How to make dot replay embedded normal command? e.g in insert mode: <c-o>ysiw>Some<esc>

For example: OpRef ^- cursor I press <c-o>ysiw>Option<esc> in insert mode to get: Option<OpRef> I want to repeat this command with dot operator, but when I press dot it only ...
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{...
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 ...
1 vote
0 answers
36 views

How to do a motion without leaving history (in .)?

Often, you do a complicated motion, which you want to repeat soon by pressing . but carry out a simpler motion overwrites that one. Can I keep that complicated motion in . itself ? Concrete example: ...
0 votes
1 answer
45 views

Why does cw followed by ctrl-r register consist of two edits?

I did cwCtrl-Ra at the beginning of a word to paste the content of register a in its place. And this, I thought, is done entering insert mode only once; or at least, never going back to normal mode. ...
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 ...
1 vote
3 answers
2k views

Repeat a command line multiple times

I want to turn one two three four into 'one' 'two' 'three' 'four' (I have surround.vim) I can do: ysiW', then do W. repeatedly until I've surrounded all words in the line But I would like to repeat ...
-2 votes
1 answer
83 views

Vim: Append to each line in a "[I" query

I have a large config file, where many different instances of a particular config format appear. I would like to take every line where a particular word appears and add some text after it. ...
1 vote
0 answers
31 views

How can I repeat a custom function mapped using `vnoremap` using something similar to the dot (`.`) operator?

I have this custom function in my ~/.vimrc mapped to Visual mode using vnoremap. After having executed the function using <leader><space>, how execute it again using something similar to ...
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, ...
0 votes
3 answers
825 views

Conditional search and replace using repeated macro or commands

I want to search for a keyword, and replace a word in the line that is not a search word. I thought macros may be a good way to do it, but I am open to any methods. I have something like, blah blah ...
1 vote
3 answers
114 views

How to use macros or any other way to add @Column and turn the below code into snake_case from camelCase?

Say that I have a java class with these fields(included only few fields, but the idea is that there could many more fields). public class Entity { private String firstName; private String ...
1 vote
1 answer
127 views

Repeating a combination of commands mapped to a single key

I have a mapping to "Stamp" text over the current word that cursor is on: nnoremap S "_diwP. When I do S and then try to repeat it with dot . only the last command will be repeated: P. Is it possible ...
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 ...
0 votes
1 answer
296 views

How to repeat short sequences of characters

I want to replace a sequence of 6 hex digits (hex RGB) with new values, but I want to repeat a 2-tuple 3 times. For example: Start: #ea9081 (with the cursor on 'e') Desired: #f0f0f0 I know I can ...
0 votes
2 answers
214 views

Making operator insert and append repeatable

Is there an insert and append operation that can be followed by a text-object? I've found this plugins: https://github.com/deris/vim-operator-insert https://github.com/mwgkgk/vim-operator-insert ...
2 votes
2 answers
148 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 ...
2 votes
1 answer
108 views

Is it possible to prevent a mapping from being repeated with a prefix number (vim range)?

Sometimes it is possible to accidentally hit some numeric keys. I have a lot of binds and for most of them there is nothing to be gained by allowing them to repeat with a prefix. Let's suppose that ...
1 vote
0 answers
45 views

Save & recall favourite vim :commands

I often find myself using the up arrow at the vim command prompt : Is there a way to 'favourite' some? Or at least an easy way to search through previous commands? For example, I couldn't remember ...
1 vote
2 answers
181 views

Preventing an autocmd from overriding last cmd - :<bang><bang> (:!!)

I have an autocmd set up like this: au BufWritePost *.sh,*.zsh,.zshrc silent exec "!ctags --language-force=sh %" When I run :!!<cr> after saving a file, the command !ctags --language-force=sh %...
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>...
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
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 ...
2 votes
1 answer
726 views

Reduce size of undo file

I had a very large (14 digit) decimal number in my (Windows) clipboard. I had vim open in normal mode on the command line at the time. Accidentally, I pressed some key/mouse combination that caused ...
1 vote
1 answer
850 views

Replay a vim macro until specified line number

Suppose caret is on the line 10 and I've recorded macros @d. I need to replay macros until line 25. If I know that macros move caret one line per execution, I can calculate that it should be executed ...
1 vote
0 answers
135 views

Repeat <Leader> mapping without having to press/release full combination

Similar to this question, I want to be able to resize my splits in a repeatable manner, but without having to use a plugin. I currently use the mapping: nnoremap <Leader>q <C-w>10< ...
0 votes
0 answers
99 views

Find out last used text object

I'm trying to figure out a way to make a repeatable operator insert. To do so I'm trying to make use of tpope/repeat. My idea is to set a repeatable call that repeats the last operation, repeating the ...
2 votes
0 answers
265 views

What happens when error occurs during cdo?

:h :cdo says: When an error is detected execution stops. The last buffer (or where an error occurred) becomes the current buffer. Let's see what really happens: ...
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 ...