Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

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
29 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 ...
melvio's user avatar
  • 617
0 votes
0 answers
10 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/...
robertspierre's user avatar
0 votes
4 answers
81 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 ...
Helmut M's user avatar
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: ...
Tom Hale's user avatar
  • 2,691
0 votes
1 answer
78 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 ...
Bog's user avatar
  • 479
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 ...
minseong's user avatar
  • 2,333
1 vote
1 answer
64 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 ...
Codemonkey's user avatar
1 vote
1 answer
54 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 ...
Abhilash's user avatar
  • 113
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()...
geb's user avatar
  • 31
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 ...
Andy Wang's user avatar
0 votes
1 answer
245 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 ...
Antonio Santoro's user avatar
1 vote
1 answer
145 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 ...
run_the_race's user avatar
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 ...
Vivian De Smedt's user avatar
3 votes
1 answer
360 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 ...
Andrew Falanga's user avatar
2 votes
2 answers
179 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 ...
Taro's user avatar
  • 153
2 votes
1 answer
400 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,...
unsafe_where_true's user avatar
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 ...
Jordan Mandel's user avatar
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 ...
Steven Lu's user avatar
  • 2,271
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 ...
Alfa07's user avatar
  • 111
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{...
Vladimir's user avatar
5 votes
1 answer
201 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 ...
Luiz Martins's user avatar
4 votes
0 answers
59 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 ...
Kaz's user avatar
  • 481
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: ...
4amvim's user avatar
  • 43
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. ...
Enlico's user avatar
  • 2,214
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 ...
minseong's user avatar
  • 2,333
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 "...
stephanmg's user avatar
  • 191
-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. ...
Jacob Kopczynski's user avatar
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 ...
Shuzheng's user avatar
  • 1,255
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 ...
M.O. Kitzka's user avatar
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 ...
theprogrammer's user avatar
1 vote
1 answer
144 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 ...
Moberg's user avatar
  • 113
0 votes
1 answer
471 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 ...
SO_fix_the_vote_sorting_bug's user avatar
3 votes
2 answers
206 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 ...
Prgrm.celeritas's user avatar
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 ...
Steven Lu's user avatar
  • 2,271
1 vote
0 answers
59 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 ...
David Savage's user avatar
1 vote
2 answers
204 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 %...
Avi's user avatar
  • 113
3 votes
1 answer
151 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>...
Pak's user avatar
  • 1,114
6 votes
2 answers
153 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 ...
dankilman's user avatar
  • 163
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 ...
ivanjermakov's user avatar
1 vote
0 answers
206 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< ...
ThoseKind's user avatar
  • 219
0 votes
0 answers
112 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 ...
Blasco's user avatar
  • 275
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 ...
Blasco's user avatar
  • 275
2 votes
0 answers
292 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: ...
dedowsdi's user avatar
  • 6,268
5 votes
3 answers
3k 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 ...
Blasco's user avatar
  • 275
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 ...
Max Copley's user avatar
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 ...
Gunnar Thoreson's user avatar
2 votes
0 answers
48 views

make u (undo) also reset . (repeat last command)?

Sometimes I make a change, then in my scramble to move to somewhere else that I want to repeat the change, I accidentally make some edit (e.g. ill). I would normally undo the accidental edit with u, ...
minseong's user avatar
  • 2,333
2 votes
1 answer
898 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 ...
rranjik's user avatar
  • 135
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 ...
eyal karni's user avatar
  • 1,136
1 vote
2 answers
61 views

Valid usecases for `=` macro register

I happen to come across the = register. I checked :h @= and :h recording where it is mentioned. I am not able to understand how to use it. It could be helpful to know a valid usecase for the same.
GGJON's user avatar
  • 145