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
0
votes
1answer
29 views

Yank both sides of equation

While writing in latex I often want to copy a math equation's right hand side or left hand side. For example I have something like this \begin{gather*} 5 \cdot \left( A A 3 \right) + 50 \cdot \...
5
votes
3answers
202 views

Visual Block Mode edit with sequential number [duplicate]

Suppose I'd like to create a list - "1" - "2" - "3" what Is the smartest way to create such? My attempt would be to i- "1"ESCyypp to get - "1" - "1" - "1" and then jump to the second line's 1 ...
0
votes
1answer
33 views

restrict shell command to only part of a line

In a file I'd like to replace some occurrences of triplets of 0 with F, 1 with E, ..., F with 0. Only some, so I can't just pipe the whole file through a bash tr filter; I need a text editor to ...
1
vote
2answers
57 views

Can I record a macro that accepts the first spelling suggestion?

I'm trying to bulk correct some OCR formatting issues. I tried recording a macro that would: ]s (advance to the next spelling error) z= (view the suggested corrections) 1 (choose the first suggested ...
1
vote
1answer
49 views

Substituting (*x).y with x->y

I am coding a C project and as I am unexperienced, everytime I needed to access the element of a pointer to a struct I typed (*x).y (where x is a struct and y an item), which I just realized could be ...
0
votes
0answers
28 views

Is there a way to load the contents a macro I recorded the next time I open vim? [duplicate]

Say after I recorded a macro the following is in register e: Is there a way to set this register contents on demand? For instance let @e=' ' ?
0
votes
1answer
40 views

What's the difference between "qp and <c-r><c-r>q when you store a macro?

I used to store macro in insert mode as <c-r><c-r>q, but it failed if the macro contains special character such as <C-Right> If i record a macro as qq<C-Right>q. result of &...
1
vote
1answer
43 views

Vimscript or macro to “rotate” column 20 (or n) vertically?

Given an integer n and a block of text, rotate every character or element in the n-th column up or down to the next position that exists. A line with more than k characters. A longer line with more ...
1
vote
2answers
46 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.
2
votes
2answers
34 views

Mapping space and backspace for “pager mode”

I used to have some simple map macros that implemented a "pager mode" for vi. When I was reading through a very long file, I would activate pager mode. This would make two key maps: <Space> ...
0
votes
0answers
42 views

For VIM in visual selection mode, how can I simultaneously apply multiple macros via cli to the selection?

The case for applying a single macro is already obvious and well documented, but what of multiple macros? Is such acceptable? :'<,'>norm! @a @b @c... If it is, what's the limit, if any, to the ...
0
votes
2answers
20 views

How to let a register contain exactly one ^M without an extra newline?

I'm trying to programmatically record a macro (using :let @m= rather than qm). In vim, I executed: :let @m = ':retab^M' where ^M is typed as ctrl+V, Enter. I expect the buffer to contain exactly ...
2
votes
0answers
77 views

How can I record a macro across multiple files

I have two code files open and I'm trying to write a macro for moving code from one file to the other. I start recording the macro in file A. After I enter all of the commands I need in file A, I ...
-1
votes
1answer
27 views

how to move to the end of a string / beginning of string for a macro

i want to write a makro and need to know how i can move to the end and to the beginning of a string, respektively i want to visually select the link so that i can surround it with brackets. my line ...
0
votes
1answer
36 views

cmap macros not working as expected

I have been trying to make a macro to allow me to check in/out files via the vim command line. Currently what I have which "sort of" works is this: nmap :checkout :! cleartool checkout -nc % As you ...
1
vote
1answer
109 views

`q` does not record tab completion correctly

Whenever I want to record complex macro between qa and q, I have to remember that, for instance, I can't use Tab-completion while type some ex command, otherwise the macro will not work. Have I ...
0
votes
2answers
53 views

How to ignore a failed :g (global) command in a macro?

Part of a macro I'm writing deletes any blank lines, and then does some more work (joining the expected two remaining lines and then appending to them). Simplified version: let @m=':g/^$/d^MggJA ^[' ...
4
votes
1answer
44 views

Weird behaviour when repeating macro

I wanted to delete every 2 lines and then skip one, so I tried recording a macro. I did q1 then d2dj to delete 2 lines and go one down, then q and @1 to execute it. The first time it worked well. ...
0
votes
1answer
67 views

Function Unable to Fail: Breaks Macros

Vim functions do not seem to be able to fail without spitting out 3 unnecessary lines. For example, take this set of functions and maps: " NEXT / PREVIOUS " ~~~~~~~~~~~~~~~ " n and N always search ...
0
votes
2answers
57 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
48 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 .....
2
votes
1answer
45 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
91 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
37 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
32 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
58 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
67 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
40 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
27 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
384 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
101 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
316 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
163 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;} ...
5
votes
3answers
84 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
187 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
37 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
286 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
32 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
67 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
88 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
61 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
296 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 $...
4
votes
2answers
425 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
51 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 ...
2
votes
0answers
131 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
145 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 ...
12
votes
1answer
2k 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
175 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 (...
2
votes
3answers
1k 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 ...