Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take 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
3 votes
1 answer
121 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 ...
user avatar
2 votes
2 answers
58 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 ...
user avatar
  • 153
1 vote
1 answer
72 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,...
user avatar
0 votes
0 answers
34 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 ...
user avatar
3 votes
2 answers
86 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 ...
user avatar
  • 2,081
1 vote
1 answer
19 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 ...
user avatar
  • 111
2 votes
2 answers
735 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{...
user avatar
  • 133
4 votes
1 answer
69 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 ...
user avatar
3 votes
0 answers
46 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 ...
user avatar
  • 351
1 vote
0 answers
35 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: ...
user avatar
  • 43
0 votes
1 answer
35 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. ...
user avatar
  • 1,572
1 vote
3 answers
1k 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 ...
user avatar
  • 1,689
4 votes
3 answers
2k views

Execute command for multiple files

I find myself often in the situation in which I want to run multiple vim commands on a multiple files. Consider file1.txt, file2.txt, file3.txt I would need to run :retab and then some :%s/ /, / for ...
user avatar
  • 161
-2 votes
1 answer
57 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. ...
user avatar
1 vote
0 answers
29 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 ...
user avatar
  • 995
0 votes
3 answers
464 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 ...
user avatar
1 vote
3 answers
106 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 ...
user avatar
1 vote
1 answer
98 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 ...
user avatar
  • 103
0 votes
1 answer
184 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 ...
user avatar
2 votes
2 answers
112 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 ...
user avatar
2 votes
1 answer
76 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 ...
user avatar
  • 2,081
1 vote
0 answers
31 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 ...
user avatar
1 vote
2 answers
135 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 %...
user avatar
  • 113
3 votes
1 answer
100 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>...
user avatar
  • 1,050
6 votes
2 answers
133 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 ...
user avatar
  • 163
1 vote
1 answer
425 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 ...
user avatar
1 vote
0 answers
83 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< ...
user avatar
  • 209
0 votes
0 answers
76 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 ...
user avatar
  • 205
0 votes
2 answers
158 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 ...
user avatar
  • 205
2 votes
0 answers
206 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: ...
user avatar
  • 5,868
2 votes
3 answers
1k 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 ...
user avatar
  • 205
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 ...
user avatar
5 votes
5 answers
1k 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 recieve the following result instead: apple apple apple apple banana banana peach ...
user avatar
2 votes
0 answers
43 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, ...
user avatar
  • 1,689
2 votes
1 answer
510 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 ...
user avatar
  • 135
2 votes
1 answer
776 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 ...
user avatar
  • 1,114
1 vote
2 answers
54 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.
user avatar
  • 145
0 votes
1 answer
42 views

Running previous run command that was run in normal mode using colon

Recently I had to compile a latex file a few times, :!pdflatex filename.tex did the trick. But is there a way in normal mode to repeat commands like these which are in the recent history,but used ...
user avatar
  • 145
0 votes
2 answers
59 views

prepend word before every function argument

accidentally just wrote void foo(bar, baz, que) { and forgot to specify type, I want to convert the above to void foo(String bar, String baz, String que) { How can I do that quickly?
user avatar
  • 1,689
1 vote
0 answers
118 views

Repeat Emmet commands in vim with dot operator

Is there a way i can repeat an emmet command in vim. Below is the sample text file <h1>Hello World</h1> <h1>Hello World</h1> So i use emmet to wrap the the first line inside ...
user avatar
1 vote
0 answers
54 views

Repeat previous square bracket command [duplicate]

I am using the ] commands (e.g. ]]) a lot and have a bunch of custom ones too. Is there a command that repeats the last such command, similar to how . repeats the last edit?
user avatar
  • 464
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 (...
user avatar
3 votes
2 answers
309 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 ...
user avatar
  • 1,114
4 votes
1 answer
451 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 ...
user avatar
  • 175
0 votes
2 answers
69 views

how to replace N characters without having to press <esc>, is it possible?

In command mode, r replaces the character under the cursor by the one pressed right after typing r without going into insert mode, so there's no esc to press. 5r replaces the 5 characters starting ...
user avatar
11 votes
2 answers
991 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 ...
user avatar
0 votes
1 answer
1k views

How to format csv with regex

I have a csv that looks like this: 1,wer123,name,address1,age,2,cde789,name,address1,address2,age,3,529owq,name,address1,age and so on. I want this csv to be formatted as 1, wer123, name, ...
user avatar
  • 103
3 votes
1 answer
100 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?
user avatar
  • 512
1 vote
0 answers
89 views

Macros behaving unexpectedly (not executing commands)

I have the following macro let @f='ivoid function (void param^[o {^M^M^[3kwi' where ^[ represents ESC and ^M new line. for some reason it does not execute anything after the 3k, I tried replacing ...
user avatar
  • 121
1 vote
1 answer
117 views

Quickly creating JSON entries in an Avro schema

Is there a quicker way to create more entries of form { "name": FIELD_NAME, "type": "string" } from a list of words down below, than recording a macro to process each word and then pasting the result ...
user avatar