Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
1 vote
1 answer
101 views

Can I map the number of search matches to a key?

I'd like to map 0 to whatever number of matches I currently have. For example: This here has 5 matches. If I wanted to perform a macro on every instance, i'd like to be able to simply type: 0Q (Q is ...
1 vote
1 answer
1k 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
1 answer
31 views

How to make an user-defined command that is repeatable with . operator

I've been trying to make a dot-repeatable (.) command that should work in both visual and normal mode. The command in question searches for a [] on a line and turns it into a [x], and vise versa. It ...
0 votes
0 answers
11 views

Make vim.execute function dot repeatable

I made the following keybinding to substitute "a/b" with "\frac{a}{b}". -- convert / to \frac{}{} -- (dot repeatable) _G.div_to_latex = function() vim.cmd('execute "normal f/...
0 votes
4 answers
82 views

How to paste Vim (normal mode) commands?

I need to copy a sequence of (normal mode) commands and then paste it to be executed in Vim. When I try that now though it inserts it for me into the document. How can I paste sequence of Vim (normal ...
19 votes
6 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 ...
19 votes
4 answers
12k 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 ...
10 votes
3 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 ...
4 votes
3 answers
516 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
1 answer
24 views

Call Lua functions from repmo-vim

Repmo lets me repeat a motion, eg after typing 3j I can press ; to move another 3 lines down, or press , to move 3 lines up. I can map a new key with its forward and backward counterparts like so: ...
0 votes
1 answer
80 views

NeoVim - Single Redo my mapping containing an <Escape>

Well I know it doesn't work because of the <Esc>, but is there any way to do it so that .(vim single redo) repeats the whole mapping and not only the part after the first <Esc> (without ...
0 votes
1 answer
44 views

Repeat many times without macro?

Is there a way to repeat a normal mode sequence n times without making a macro for it? I thought 5:norm would be able to do that, but that actually runs the normal mode sequence once for each line of ...
11 votes
6 answers
3k 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 ...
63 votes
2 answers
20k 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 ...
6 votes
4 answers
4k 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
65 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 ...
5 votes
1 answer
3k 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
55 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
53 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()...
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
56 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
249 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
146 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
30 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
362 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
181 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 ...
2 votes
1 answer
405 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
408 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
164 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
982 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
204 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
27 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
4k 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
60 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
41 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
62 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. ...
1 vote
3 answers
3k 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
84 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
34 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
167 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
1k 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
121 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
145 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
473 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
238 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 ...
3 votes
2 answers
207 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
133 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
60 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 ...