Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [repeated-commands]

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

2
votes
1answer
53 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 ...
0
votes
2answers
53 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 ...
0
votes
0answers
28 views

Save last command for next time vim is run?

I'm editing a file. I do a string search (EG /sometext). I then save the file and exit Vim. I then start Vim on another file. I press / and Vim finds the next instance of sometext. How can I do ...
8
votes
2answers
182 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 ...
0
votes
1answer
100 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, ...
2
votes
1answer
51 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?
1
vote
0answers
62 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 ...
1
vote
1answer
64 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 ...
1
vote
1answer
69 views

Vim - edit last action before using (.)

Related to but not duplicate¹ of Bundling command sequences together for repeat (.). The point (.) command is really useful to redo the last action (insertion, replacement, etc.). Sometimes I find ...
0
votes
1answer
66 views

how to accept count for visual block ctrl+a remap?

I have created a vmap but I can't figure out how to apply a count to it. In this case, the mapping is on <C-a> and 4<C-a> is an example of a command with a count failing to be applied. We ...
0
votes
0answers
79 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 ...
1
vote
2answers
451 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
1answer
341 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 ...
5
votes
2answers
63 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 ...
4
votes
3answers
101 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 ...
1
vote
1answer
65 views

How to repeat a certain operation across lines of code? [duplicate]

I need to repeat a certain operation across several lines of code spread through out the code base. For instance, x = y; needs to be replaced with EQUATE(x,y); However each instance needs to be ...
2
votes
3answers
260 views

Expand visual selection of surrounding code blocks

Given the following code in visual mode : { { some text ^ cursor } } if I type a{ this will be selected : { { < selection start some text } < selection end } I'd like to ...
3
votes
1answer
84 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 ...
2
votes
1answer
78 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 ...
0
votes
1answer
122 views

. (dot) command and backspace

Say I want to turn this: find(vec_a.begin(), vec_a.end(), c) into this: find(vec_b->begin(), vec_b->end(), c) That's what I just wanted to do, so I tried this (commands separated by commas): ...
2
votes
2answers
1k 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 ...
1
vote
1answer
95 views

Make mapping repeatable with repeat.vim

I'm trying to make a mapping that inserts an empty line below without moving the cursor and to make this repeatable with repeat.vim. I have modeled this from vimcasts. To get back to the original ...
9
votes
2answers
160 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
4answers
151 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 (...
3
votes
1answer
108 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
1answer
214 views

Run a command on every match of a search (not on the line)

I am trying to run a command on every occurrence of a search match. So, If i have some thing like this where a search match matches only these two anchor tags, .................. <a src="****" &...
1
vote
2answers
199 views

repeat indent-to-previous-position in vim?

I very often want to do the following or similar: indent all lines from previous position to current position inclusive repeat, repeat, repeat (to further indent the same lines) I feel I should be ...
7
votes
4answers
969 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. ...
10
votes
3answers
491 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 ...
8
votes
1answer
118 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 ...
1
vote
2answers
313 views

Call function on several lines

I have a function that changes the 6th caracter of a line to a dollar symbol ($). I want it to be performed on several lines, so I naively did a "while" loop using a counter (as shown under). But ...
8
votes
6answers
3k 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 ...
3
votes
2answers
132 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 ...
4
votes
2answers
275 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 ...
2
votes
4answers
1k 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 ...
4
votes
2answers
102 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 ...
4
votes
2answers
89 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) } ...
6
votes
1answer
1k 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 ...
3
votes
1answer
132 views

What is the fastest way to perform this change?

In my codes, I often have to do this kind of text editing: u(:,:,:) = 0._dp v(:,:,:) = 0._dp temp(:,:,:) = 0._dp To: grid%u(0:nx,0:ny,0:nz) = 0._dp grid%v(0:nx,0:ny,0:nz) = 0._dp grid%temp(0:nx,0:...
5
votes
1answer
220 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 ...
3
votes
1answer
841 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,...
9
votes
1answer
176 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 ...
0
votes
0answers
26 views

Cycle through edit command history [duplicate]

In Vim, i can cycle through edit locations with g, and g;, and jump to locations with Ctrl-I and Ctrl-O. Is there any way to similarly cycle through edit commands? This would be something similar to ...
5
votes
1answer
663 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 ...
2
votes
2answers
61 views

Deleting a Latex command multiple times

Indexing a Latex document, I added a lot of \index[]{} commands in \footcite prenotes. It's stupid! Anyway, in my code I have a lot of : \footcite[blabla blabla\index[n]{something} blabla.][postnote]{...
4
votes
1answer
9k 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,...
4
votes
3answers
172 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 ...
15
votes
4answers
415 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 ...
9
votes
1answer
384 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 ...
9
votes
1answer
149 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 ...