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

Questions tagged [macro]

A macro is a recording of typed commands that can be executed later. Macros are stored in registers; recording a macro can be done with q, and you can run them with @.

Filter by
Sorted by
Tagged with
2 votes
1 answer
77 views

Vim macro to copy paste text

I would like to copy paste everything after a comment into the [] place holder of the next line. E.g.: %This is a comment Target box: [] with some more text The desired output would be: %This is a ...
Hugh's user avatar
  • 23
0 votes
3 answers
103 views

How to map q for saving and quitting?

I was reading the Vi documentation, by Joy and Horton and on section 6, 6.9 Macros they give a way to map q to save and quit: :map q :wq^V^VCR CR When trying that out in Vim it creates a new file ^V^V ...
Miguel Cortes's user avatar
0 votes
1 answer
52 views

How can I write a vanilla function or macro to align characters generally?

Often I want to align code like this // start with someVariable = someValue shorter = anotherValue longerVariable = anotherValue // turn into someVariable = someValue shorter = anotherValue ...
Adam's user avatar
  • 121
1 vote
0 answers
42 views

Run macros in background while doing something else

I have a macro that calls APIs to fetch data based on information in a buffer. Is it possible to have the macro continue execution while I move to another window and work on other buffers?
user22476690's user avatar
0 votes
1 answer
36 views

Macros on lines with different structures

There are occasions where I use macros to re-format multiple lines, where the lines can have a different format. For these tasks, I use appropriate macros, but due to the different formats this can ...
pschulz's user avatar
  • 113
3 votes
1 answer
810 views

Use treesitter to jump to next argument without going into nested function calls

I'm hoping to write a macro that involves jumping to a second argument of a function call and deleting it. The function arguments will sometimes include nested function calls, sometimes not, will ...
Michael's user avatar
  • 131
5 votes
2 answers
708 views

How do I play a macro, but *slowly* (for debugging a macro)

Sometimes I do a repetitive task via a macro, but it ends up too complicated and I make a mistake somewhere. Then when I try to execute the macro, everything happens at once and I can't see where I ...
beyarkay's user avatar
  • 205
0 votes
2 answers
66 views

Delay inside Macro - Is It Possible in Vim Macros to Create a Delay Between Commands?

Does something like this exist?: let @p = "0D:!ping -c1 8.8.8.8\<CR>"<SLEEP 1 SECOND>"\<CR>iJust pinged a DNS Server\<ESC>" And let me read the ping result....
Bog's user avatar
  • 479
-1 votes
1 answer
41 views

Put the highest count into a register and run macro that number of times, plus a contigency

I read books. A lot of books :) When a mate asked how many books I read a week he couldn't believe it was in the 3+ range so I started recording them by author and Month read since 2013. I wrote a ...
Steve's user avatar
  • 276
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
0 votes
0 answers
115 views

How to search for yanked text in a macro?

How do I search for yanked text in a macro properly? I tried the following: qq (start a macro) yi" (yank text inbetween ", let's say the yanked text is foo) / press ctrl + r " (I ...
Sebastian Nielsen's user avatar
2 votes
3 answers
94 views

How to get floating result in expression register?

I want to write a macro to set line height in fraction. font-size: 18px; line-height: 22px; The problem is with expression register. I set 2 variables @f = font-size @h = line-height And =@h/@f - ...
serii 's user avatar
  • 91
0 votes
2 answers
113 views

How to use a variable from register in command mode?

I have a list of cities London Madrid Paris Brasil I want to write a macro, that will add a ul tag and wrap each city in to an li. I think, i need to create a variable like: let i = 4 Than to write ...
serii 's user avatar
  • 91
0 votes
1 answer
46 views

How to prevent an extra newline from being appended to macros ending with a newline? [duplicate]

If I save a macro by typing: :let @s='/{<C-v><C-m>'<Enter> which looks like: :let @s='/{^M' the macro that is actually saved is /{^M^M, with an extra linebreak (that I did not type)...
ban_javascript's user avatar
1 vote
1 answer
42 views

Update the display when :normal is busy

The [n]vim manual on :normal says "The display is not updated while ":normal" is busy". Is there a way to have it do so? If not, is there a plugin that defines its own version of :...
typecasto's user avatar
1 vote
1 answer
94 views

Individual macros function but combined macros do not

I am trying to brute-force the Caesar shift cipher in vim. I have recorded three macros f, a, and d where f copies the line and a applies a Caesar shift to all elements on the line by calling macro d ...
Progamer's user avatar
1 vote
2 answers
574 views

What is @q doing?

I accidentally typed @q instead of :q and the file closed. I checked if I have a macro defined by using :reg q. It shows a long string of jibberish. Is it possible to find out exactly what function @q ...
neverdimed's user avatar
3 votes
2 answers
126 views

is there something like `%` but for matching double quotes

I'm working on some HTML files that are formatted weirdly. Each individual class is on a separate line which makes the file (imo) difficult to read. Something like: <div class=" classA ...
Enermis's user avatar
  • 161
2 votes
1 answer
491 views

Break line after the n-th comma

Suppose I have the next line 1,0,10,10,9,7,7,5,41,3,57,7,1,9 I want to split it into several lines, each containing n commands for example, for n = 4 1,0,10,10, 9,7,7,5, 41,3,57,7, 1,9
juaninf's user avatar
  • 153
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
1 vote
1 answer
44 views

How does recording a macro differ from defining a macro directly?

In my Vim configuration, I have mapped the <C-j> key to <cmd>bn<CR>, but because the C-j key corresponds to the null character in Vim, this causes some strange issues when defining ...
Andy Wang's user avatar
0 votes
1 answer
176 views

How to join multiple lines which doesn't include space at the end

I'm working on a subtitle document (.srt) which has thousand of lines. But this issue is not about the subtitle documents, I going to export as plain text to read after. To see the dialogs line by ...
Pascowl's user avatar
4 votes
0 answers
69 views

How to Make Macros Stop with Custom Motion?

I am writing a custom Vim motion. The problem is that when used in a macro (especially at the end of a macro), the macro does not automatically stop when the motion no longer applies. For example, if ...
Jesse's user avatar
  • 41
2 votes
0 answers
217 views

How to split view all buffers in vim with equal distribution vertical horizontal

How can I split view all buffers in vim with a distribution between vertical and horizontal? Is there a plugin? I know how to make all buffers appear in either horizontal or vertical splits: :ball :...
Polo's user avatar
  • 41
0 votes
2 answers
30 views

How do I create a macro (q<letter>) which goes to the end of a line and deletes one or two characters?

I'm refactoring the logger code in my software. The old log message ends with either ); or just ; at the end of a line and I want to remove those characters and add a new line with some additional ...
Alexis Wilke's user avatar
0 votes
1 answer
71 views

Run macro on visual selection only. [Evaluate an Iterator to consecutive numbers]

How can we run the macro on only the visual selection? The macro that we want to run is / id: 1,^Mf1s^R=i^M<C-c>:let i += 1^M (where (as given in this SO answer) ^M happens to be the way vim ...
HarshvardhanSharma's user avatar
3 votes
1 answer
181 views

How to save a macro (for quickly printing a variable)?

I'm trying to create a macro for an action that I very frequently use in Python: printing a variable in a bright color so it can easily be found in the traces while debugging. So lets say there's ...
Opifex's user avatar
  • 227
3 votes
1 answer
179 views

Inserting the content of a register where a macro is recorded results in control characters becoming unicode characters

If I hit Ctrl+V and then Escape while in insert or ex mode, I get ^[ as a single character. If I hit qqEscapeq and then go see :registers, I see that q contains ^[<80><fd>a, which are ...
Enlico's user avatar
  • 2,214
0 votes
2 answers
159 views

g[lobal] with a s[ubstitution]

I would like to add a dot after the first number in a line. I tried using the command below. :g/\v^\d/exe "norm!:s/\v(\d)/\1\./^M" The command above does not work. I recorded the macro @q=':...
Root's user avatar
  • 1
1 vote
0 answers
110 views

Macro doesn't run properly when executed with :bufdo or :argdo

I have a macro that looks like: :reg a Type Name Content c "a /^where^MkV%yGo^M-- Some typing...:^[pVG:!/tmp/t.sh^M It works fine from any starting position in the file when I replay it ...
jberryman's user avatar
  • 133
4 votes
1 answer
325 views

How to reference a register in an ex command

I'm trying to write what I thought would be a simple macro to take some values that have been yanked into some registers (a & b) and use bc to do some addition with those values. Here is the ...
cewood's user avatar
  • 143
0 votes
0 answers
539 views

Macro not working as expected

I have a list such as follows apple banana cherry I am trying to write a macro that will get it in this format (I am writing a .yaml file) - "apple" - "banana" - "...
Saul Alarcon's user avatar
0 votes
0 answers
30 views

Trouble running Ex commands after normal mode commands in a macro

I have the following macro: ggdG"+p :try|%s/\V${NodeName}/${N=SwisEntity;M=DisplayName}/|catch||endtry :try|%s/\V${IP}/${N=SwisEntity;M=IP_Address}/|catch||endtry :try|%s/\V${IP_Address}/${N=...
Justus Grunow's user avatar
0 votes
0 answers
127 views

Is there a way to disable plugins during macro recording and execution?

Is there a way I can disable specific (or all) plugins when recording a macro and then when playing back the macro? I've had an issue where a plugin that automatches ( with ) that stops a macro that ...
triplej's user avatar
  • 103
0 votes
1 answer
160 views

Problem with vim macros. Limitation to letters In the alphabet

Hello I like vim but their seems to be a limited macro system from what I understand. The documentation I have says to specify a letter to define the macro. Does this mean that I a restricted to the ...
M.R.P.'s user avatar
  • 1
0 votes
1 answer
75 views

Macro inserts wrong and weird text

I have a data that looks like :stuff #object[java.time.Instant 0x4ddb2473 "2016-03-04T00:00:00Z"], :stuff2 #object[java.time.Instant 0x62bc763e "2046-04-01T00:00:00Z"], I want to ...
triplej's user avatar
  • 103
0 votes
1 answer
193 views

How to execute a macro until we encounter a character

How can I repeat the execution of a macro until a character is encountered? For example (just an example, it's not the original problem I want you to solve) I want to convert a CAPITAL_CAMEL_CASE to ...
CodeTalker's user avatar
1 vote
0 answers
227 views

Function call in macro

I have a function (from here) that requires an argument enclosed in quotes. if !exists('*Preserve') function! Preserve(command) try " Preparation: save last search, and ...
Tom's user avatar
  • 67
3 votes
1 answer
866 views

Can macros be edited? [duplicate]

I want to end up in insert mode after a macro. Is there a way to do that? A real life example: Given "foo", I'm wanting to convert it into "$123" where the number is something I ...
4amvim's user avatar
  • 43
2 votes
2 answers
1k views

Vim - Yanking a set/number/block of lines, and inserting/appending them before/after another set/number/block of lines?

If I have two 'sets' of lines, each consisting of X number of lines (but the lines differing in their individual lengths), can I yank one set and insert (or append) it to the other? To illustrate, can ...
Chris's user avatar
  • 253
1 vote
1 answer
301 views

Escaping ' (apostrophe) in \\' (leader leader apostrophe) in a @let statement inside .vimrc

I have mapping \\' (leader leader apostrophe) within my .vimrc. The mapping works just fine. I have recorded a macro to key e using this mapping. qe ... steps ... q The macro works just fine. then I ...
Kes's user avatar
  • 663
4 votes
1 answer
432 views

Escape key adds extra bytes into the register when recording a macro [duplicate]

When I try to record a macro that involves hitting Esc the following bytes are added to the register <80><fd>a for example if I type qq<Esc>q when I :echo @q I get back ^[<80>&...
Kasper-34's user avatar
0 votes
1 answer
431 views

vim-surround not working properly in macro (ideavim)

vim-surround not working properly in macro: I want to change all li's <li><a href="/">home</a></li> <li><a href="/stuff">...
Sebastian Nielsen's user avatar
0 votes
1 answer
344 views

Increment number for every 10 lines

The file consists of 2 columns (code and percentage). We need to add 2 more columns with increasing number for 4th column (Xcols) and increment 3rd column (Ycols) only for every 10 lines with reset of ...
canabady web's user avatar
1 vote
2 answers
124 views

Replace " ... " strings of various length with strings that all end at same column but start at different columns for each row

I have the following text Plan based ................................. 32 Iron based in Compound .............................. 34 Gallium Arsnide based III-V ............ 36 ... Indium ...
Kes's user avatar
  • 663
0 votes
1 answer
166 views

Regex macro to remove only lines NOT containing specific content

Given a word list, I would like to delete all lines that do not have a specific content. For illustration, In the following list, I would like to delete all lines that do not end in s. bird chairs ...
BrianWilson's user avatar
1 vote
2 answers
869 views

How to copy a Vim macro to another Vim instance without clipboard support (i.e., no `+` register)?

Cross-posting from Stackoverflow because I keep forgetting about this site... Have a macro where a visually selected text will be made a markdown link and once the macro executes it leaves Vim in ...
toraritte's user avatar
  • 400
1 vote
2 answers
188 views

Is it possible to generate a list of increasing numbers from a list of fixed numbers on vim?

Let's say I have a file that contains a specific number that is always the same, something like the following: 1 1000 10 1000 100 1000 1000 1000 10000 1000 100000 1000 1000000 1000 10000000 1000 ...
raylight's user avatar
  • 535
4 votes
2 answers
445 views

Is there any way of copying a macro inside a register to a different register?

I've discovered I can execute vim macros from the command line using the following command: vim myfile -c "argdo norm @aZZ" This command executed from the command line will execute a macro ...
raylight's user avatar
  • 535
0 votes
2 answers
718 views

Append a line after matched multiline pattern

i want to run this global command : /3)\(.*\n\?.*\)\{1,10\};;/ which matches multlines. I want to append a line after the matched block(of lines) across multiple buffers. I don't know where to begin ...
Just Khaithang's user avatar