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 [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 @.

0
votes
2answers
35 views

Why does this recursive vim macro stop?

I saw an example of a recursive vim macro, and it stops, but I don't quite understand why. My guess is that it stops because it can't find any more :, but I'm unsure if I am correct; does anyone know ...
2
votes
1answer
39 views

In visual mode, how can I select to either the next section or the end of the file?

I'm having trouble selecting sections in a file in a visual mode macro to separately perform some action on each section. Here's an example file: [insert introduction here] ... .... ------ section .....
1
vote
1answer
26 views

Macro “oend^[Ores^[” results in new line “end2es”. How?

I don't usually have this much trouble debugging issues, but I'm starting to get stumped. The line doesn't happen when typing the macro out (running it by hand). In fact, it's part of something I ...
2
votes
1answer
29 views

User Input in a Recording

So I am pretty new to vim, but I have started using it as my Latex editor to help get more efficient. Anyways I have a recording that I would like to prompt a user for input on that will change how ...
0
votes
1answer
26 views

How to start recording a macro, using commandline mode?

If I wanted to start recording a macro using command-line mode, how would I do this? Additionally, if I wanted to bind this action to a key, how would I do that in my .vimrc?
6
votes
2answers
1k views

How do I check if Vim is currently recording a macro?

Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?
1
vote
1answer
27 views

How to insert special keys (like <return>, <m-r>) into macro registers with script?

I tried let @q = '<return>' and it obviously won't work
0
votes
1answer
37 views

Vim Comment Box Macro

I write comments of the form ############# ## Example ## ############# Always one line, always just like that. It's a way of breaking up code more visually. I have lately taken to the following way ...
0
votes
2answers
49 views

Move a column up-/downwards

I was wondering if, out of the box, one can move an entire column up- and downwards. Say, we have the following text: 1 a b c 2 d e f My goal is to convert this into 1 a b c 2 ...
0
votes
1answer
31 views

mapping to enclose symbol under cursor with an expression that contains the symbol (revisited)

@saginaw answered a question I asked a long time ago, in this thread. Here's a code snippit of his suggestions that illustrates my problem: function! s:PadMacro(type) abort if a:type ==# 'char' ...
1
vote
1answer
24 views

Duplicating a row and modifying the duplicate as a macro or regex

Given a file with multiple lines matching this pattern (apologies for the length!) $this->execSQL('INSERT INTO `table_lowercase_and_underscores` (`id`, `field1`, `field2`, `field3`, `field4`, `...
8
votes
2answers
147 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
2answers
73 views

C - Generate .h file from .c file

Is there a good macro or regex expression that I can use in Vim to generate a .h file from a .c file? For example, take the following .c file // temp.c // comment 1 // comment 2 void function1(int a,...
3
votes
1answer
144 views

Remapping Alt key in terminal: problem with macros

I'm using xfce4-terminal. I remapped most Alt+key combinations in a file that is loaded in the .virmc. The file (called alt_bindings.vim, only loaded in vim 8 terminal mode) is like this: set <M-...
0
votes
2answers
79 views

Competitive coding template in vim macro

I want to have a vim register that pastes : #include <iostream> #include <string> #define 1e9 + 7 typedef long long ll; using namespace std; int main(int argc, char ** argv){ return 0;} ...
2
votes
1answer
40 views

How to force macro keep running even pattern is not found?

I have a macro to swap text. For single line, it's running without problem. But if I run this macro many times and one line is empty or different pattern, it will print below error and stop. Is ...
4
votes
3answers
145 views

Reverse a set of paragraphs

Is there a good way to reverse a set of paragraphs (navigable via cursor motion { and })? My practical use case is reversing the order of blocks of latex code (ie, reversing the order of jobs in a ...
0
votes
1answer
33 views

Why .vimrc reports error when adding recorded macro?

I've created a macro to add a piece of code. The macro runs fine. But when added to .vimrc, it reports error. (The macro becomes weird when paste here.) let @p='iprocess (clk, resetn) €kbbegin ...
1
vote
1answer
98 views

How to play recorder macro in SpaceVim?

I managed to record a macro pressing <leader>-q-r-<letter>, but I can't make it play. The documentations says SpaceVim has mapped normal q as smart buffer close, the normal func of q ...
1
vote
0answers
30 views

Creating QuickFixed file to apply QuickFixes via diff

TL;DR I have macros in each %m captured by errorformat after :make. I'd like to have a copy of the file in another split and apply all the macros (so to have a fixed file) and then do a :windo ...
1
vote
0answers
59 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
61 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 ...
0
votes
1answer
38 views

combining two map commands

I'm doing a lot of repetitive copying. Starting out with lines like first line second line I want create a single mapping that produces first line second line \notes{ first line second line } I ...
2
votes
3answers
237 views

How to get around this common multiple-cursors use case?

I have a lot of difficulty doing things like the following in Vim: From 1 'apple' 2 'orange' 3 'pear' 4 $fruit1 = 5 $fruit2 = 6 $fruit3 = To 1 2 3 4 $fruit1 = 'apple'; 5 $fruit2 = 'orange'; 6 $...
3
votes
2answers
201 views

Go forward to first alphabetic character

Is there a way to go forward to the first letter, maybe using f other than specifying the letter itself? In other words I want to skip over whitespace, symbols and digits. The reason I ask is that I ...
0
votes
1answer
47 views

Would you ever want to start recording a macro from the quickfix window?

I'd like to map q to :cclose in the quickfix window, but I wonder if I'd be locking myself out of a world of wonderful macros by doing so. Are there realistic scenarios where you'd want to be able to ...
1
vote
0answers
89 views

Vim function somehow adds Ctrl-j to macro?

I've written a short vim function that allows me to edit the contents of vim registers: fun! RegBuff() let vimstuff = "/tmp/vimstuff" if !isdirectory(vimstuff) call mkdir(vimstuff) ...
2
votes
3answers
84 views

vim run macro multiple messed up

If I have following lines: 1 2 3 I make a macro to insert a new line below current line and type 'x': my macro is: ox^[j now I run this macro to the above three line by visual select the lines and ...
9
votes
1answer
728 views

Save a macro just created in vimrc

Sometimes I create macros. Sometimes I create the the same macro. Sometimes I feel sick of creating the same macro. Can I store macros? Can I load a preset of macros? Can I make a macro and save it ...
1
vote
1answer
173 views

How to convert ISBN-10 to ISBN-13 in Vim?

My file contains ISBN-10 and ISBN-13, e.g.: isbn:0062316095, more text isbn:1847922635, much more text isbn:9780486406510, even more text I want to convert every ISBN-10 to the according ISBN-13 (...
0
votes
3answers
410 views

How to create a macro in .vimrc which automatically uses enter

I want to have a macro in my .vimrc which when activated will enter a command and execute it. I want something like let @r = ':e!' but instead of it just being entered in the command line I want ...
0
votes
1answer
460 views

Repeating multi-lines and increment numbers in specific sections?

I want to create a file that has X number of entries where each entry has incremental numbers for Y. I tried recording a macro that would copy the 3 lines then edit the value but it ended up editing ...
5
votes
2answers
486 views

Insert code snippets?

I'm creating a folder with common code snippets I use. I want to create a quick command in vim to insert them, for example something like: :snippet codeblock1 Ideally it would be a single command ...
6
votes
1answer
98 views

Why does vim add ^J to the end of my macros?

I wrote short macro that helps me grep for the word under the cursor. Here it is in my .vimrc: let @a=":! git grep ^R^W^M" However, when I open vim and run :reg a, I see the following: "a :! git ...
4
votes
1answer
401 views

How to execute a macro in command mode?

The contents of register w are xx. When I try to run the following command: :for i in range(1,10) | if i > 5 | @w | endif | endfor It throws an error saying that E492: Not an editor command xx. ...
3
votes
2answers
363 views

Add a pipe character to the nth character of a line, which is after the end of the line

I need to annotate a text file, so I would like to add a | pipe character to the end of each line to put my annotations relatively close to the original text. Each line is up to 72 characters in ...
12
votes
4answers
913 views

Can I repeat a macro with the “dot operator”?

Can I repeat a macro with the . command? For example, I'd like to be able to type: @q... and have it effectively call @q 4 times. With the default behavior, this works only if 'q' holds a single ...
2
votes
1answer
93 views

How to automate populating Python's class constructor?

I've done some searching with various keywords, but unsuccessfully. Sorry for my English, I'm not a native speaker. I'm new to VIM and to Python, and I'm learning both on the go as much as I can, but ...
7
votes
1answer
75 views

Swap two keys in such a way that works with both `f` and macros

I have swapped my number keys with their symbols, because the symbols occur much more frequently than numbers in many programming languages, like C or Haskell. You can see my key-swap function in my ....
2
votes
3answers
116 views

Run a macro without having it set as last macro (@@)

I have @@ mapped to Space. This can be really convenient. Sometimes I want to combine a macro with another. So maybe I need to record q as @:/jump to run my last regex substitution and move to the ...
4
votes
1answer
96 views

Run macro between buffers

I know there is a possibility to run a macro in multiple buffers using bufdo. However, what I'm not aware, if there is somehow to use a "intercommunicated macro", e.g: File 1: foo bar bun File 2: ...
1
vote
2answers
102 views

How to call a macro as a function in a search replace %s/regex/\=call-macro-as-function/gc

I want to do some edits on each match during a global substitution operation. I found this answer :% s/re\(ge\)xp/\= myfunction(submatch(1))/gc. But I don't have a function, just some keystrokes. ...
4
votes
2answers
550 views

Is there a way that I can identify which window is a terminal after calling the `:term` command in neovim?

Is there way I can identify a window by a number in neovim and then jump to it with a macro ? Or better yet...Is there a way that I can identify which window is a terminal after calling the :term ...
6
votes
2answers
117 views

How to get the count given to a macro?

When executing an ex command I can use the variable v:count to get the count which was given to this command. From :h v:count, if I create this mapping: :map _x :<C-U>echo "the count is " . v:...
2
votes
1answer
164 views

How to turn several commands into a macro without recording?

I have several useful search, search and replace and global commands written in my personal Vim reference. How can I easily turn some of them into one macro without recording (retyping everything)?
1
vote
2answers
78 views

How to execute several macros with one command?

I have three macros that I have created separately over time. a performs a search and replace, b adds tags to every line and c appends text at the beginning and the end of the file. I execute them ...
10
votes
1answer
305 views

How can I use insert mode completion in a macro?

I'm trying to define a macro which quickly generates a list of random-ish words. I want the macro to turn this into a list like a b c d e into this arezzo bywords czars détente eyrie What I have ...
3
votes
3answers
596 views

Leader versus macros

Currently I tend to use macros and have not learned how to use the leader key which seems to provide much the same functionality. Aside from it being easier to type , than @ what is the gestalt of ...
10
votes
3answers
471 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 ...
1
vote
0answers
56 views

Macro fails using arrows [closed]

I want to escape in my file some of the " by \". For example, I want to transform foo"bar"xyz" to foo\"bar\"xyz\". Attempt 1 : search for " (typing /") create my macro (typing qai\, Esc, ...