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
24 views

Use normal command output as variable

I want to be able to use some normal commands I tend to use in the day to day as an input for another function, for example 4X, I would like 4X to be expanded to XXXX and then use it in a function as :...
1
vote
1answer
24 views

Undo <count> macro instances

Often I would record a macro and run it till end of file like 200@q. However, there may be a few lines/instances at the bottom I don't want to run the macro on (like 5 lines). Pressing u would undo ...
0
votes
1answer
41 views

How to paste/merge 2 blocks of text in vim

I search a way to paste/merge 2 block of text block A apple pear banana block B tomato beans potato to this apple tomato pear beans banana potato I'm looking for an easy way to do this using macros....
0
votes
3answers
29 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 ...
1
vote
1answer
23 views

How do I, in a macro, yank a word which might be just one letter long?

I am writing a macro a part of which is supposed to extract verse numbers from a string such as 11.1, standing for "verse one in canto eleven". I search /11\.\zs. The cursor now is in the right place. ...
1
vote
3answers
86 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 ...
3
votes
5answers
406 views

How do I get my signature with a date inserted in my changelog?

Whenever I make an update to the changelog of a Debian package, I have to update the signature with the correct date (well, it's not mandatory, but it's really nice to have). The signature looks like ...
1
vote
1answer
54 views

How to clear a vim register (vi/ex buffer)?

In the ex linage of editors, one can append to a register(vim)/buffer(ex,vi) by specifying the register name in uppercase. As an example g/pat/y A will append every line match pat to register a. But ...
2
votes
1answer
69 views

Why doesn't this macro work? (expression register)

According to this: nnoremap Q @='n.'<CR>: The @ key tells Vim to execute a macro. Rather than using a named register we use the expression register, which lets us specify the contents in ...
1
vote
1answer
24 views

Retrograde sorting

I am looking for a way how to transfer this (and similar) block of text: dollar_value: str = field(init=False) dollar_symbol: str = field(init=False) dollar_unit: str = field(init=False) euro_value: ...
1
vote
2answers
40 views

Embed <Return> within register

I want to have predefined register that will jump to the location matched by regular expression, i.e. in vimrc I add: let @a="/=\"" That will be useful for me when I want to navigate to the next ...
1
vote
2answers
30 views

Why doesn't this Vim macro work?

I recorded this macro to register a in Neovim by first pressing qa: Macro --- Registers --- "a f1F1i-^[la0^[j Then I pressed q and my cursor was left in normal mode at the position marked by | (...
1
vote
1answer
61 views

How to put quotation marks (') in the content of a vim macro?

I use :%s/'/"/g to replace all single quotes ' with double quotes " in a plain-text file but when I want to put this command in a vim macro in .vimrc let @r=':%s/'/"/g' opening vim will ...
1
vote
1answer
30 views

How can I auto-complete a few letters then navigate to a fixed location within them?

I was wondering whether to autocomplete e.g. jj to print('') and then navigate within those ticks: is it better to have a macro, or a remap, or neither? Obviously a remap doesn't allow moving after ...
1
vote
1answer
38 views

Search and Replace - How do you change a specific string across syntactically similar files?

I'm attempting to write a Vim macro that will allow me to replace a single variable of a single service across multiple Icinga configuration files. Services are syntactically very similar so I ...
2
votes
1answer
270 views

How to run Vim on a Chromebook?

I am working on a Chromebook. Mostly I code in an online IDE, which supports Vim mode, but from time to time I need full Vim support. For example, I need it to be able to use macros and filter content ...
3
votes
1answer
73 views

newline in macro recording

Let's say I record a macro n that generates the following text: 1 2 When I ask for the content with "np it outputs: i1^M2^M^[ So I append in .vimrc file: let @n = 'i1^M2^M^[' if I save .vimrc ...
2
votes
2answers
577 views

How can I do calculations with vim Macros?

I like using vim to edit csv files. But I often have to resort to localc when doing actual maths on them. Is there a way to use Math inside a vim Macro? Basicly adding 2 cells together and outputting ...
6
votes
1answer
114 views

How to prevent stopping a macro on unsuccessful substitution?

I've been trying to record a rather simple macro with two substitutions. The whole macro is: dd"+pkdd:%s/\t/, /g :%s/ \(kb\d\+\),/ \1.0,/g "+y$ However, the second substitution is there to reformat ...
1
vote
1answer
119 views

Why can't I remap q [closed]

I have many key mappings in my vimrc but for some reason no matter what I do q remains mapped to recording macros. I will post my full vimrc below, but the relevant part is that even if the last line ...
1
vote
1answer
44 views

How to add a certain word before the names of methods in Javascript?

I am working with react. First I had a component with state I created methods and all that. Now I want to convert it into stateless component. I have add the word function before each method name. ...
2
votes
1answer
51 views

How do you read the contents of a macro into your buffer?

I know that you can use let @x = @w to copy the contents of a macro from one register to another, but how do you read the contents of your macro register into the buffer?
2
votes
3answers
352 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 ...
2
votes
3answers
479 views

How to create a vimrc macro using :sort?

I tried creating the following macro: search an empty line above my location go down one line shift-v find an empty line down go up one line :sort This should sort the entire section I'm pointing at....
4
votes
4answers
407 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 ...
1
vote
1answer
49 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 \...
7
votes
3answers
682 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
44 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
69 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 ...
2
votes
1answer
65 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 ...
1
vote
2answers
112 views

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

I used to store macros in insert mode as <c-r><c-r>q, but that fails if the macro contains a special character such as <C-Right> If I record a macro as qq<C-Right>q. the ...
1
vote
1answer
53 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
50 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
85 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
2answers
24 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
316 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
34 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
66 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 ...
2
votes
1answer
188 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
99 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 ^[' ...
5
votes
1answer
139 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
82 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
129 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
52 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
78 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
136 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
41 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
3
votes
1answer
212 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 ...