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

Macro won’t repeat when remapping <esc>

I remapped vv to <esc> inoremap vv <esc> "some notes cnoremap vv <esc> When using a macro, it can't be repeated. For example: qaifind^Mvvq,then @a and @@ works fine but 2@@ ...
1
vote
0answers
13 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 ...
4
votes
1answer
72 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 ...
0
votes
0answers
34 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" - "...
0
votes
0answers
27 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=...
0
votes
0answers
20 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 ...
0
votes
1answer
42 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 ...
0
votes
1answer
35 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 ...
0
votes
1answer
33 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 ...
0
votes
0answers
37 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 ...
3
votes
1answer
144 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 ...
1
vote
2answers
66 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 ...
1
vote
1answer
47 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 ...
2
votes
1answer
54 views

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

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>&...
0
votes
1answer
71 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 ...
1
vote
2answers
58 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 ...
0
votes
1answer
23 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 ...
1
vote
2answers
85 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 ...
1
vote
2answers
88 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 ...
1
vote
2answers
67 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 ...
0
votes
2answers
103 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 ...
4
votes
1answer
55 views

How to save a macro which does not shift cursor position

I have to do </^< a whole lot. So I created a macro: let @w = '</^<Enter' (where Enter is entered via Ctrl+V M). But when I run it with @w it shifts the cursor down one line - which is NO ...
1
vote
0answers
35 views

Terminal window interprets quick initial q as macro record

I have a function that opens a terminal window running some program. The program is quit by pressing q. But when I press q in the terminal window shortly after (within 1-2 seconds) of it being opened, ...
1
vote
1answer
49 views

in-place replacement of code in HTML documents with TOhtml?

I'm working on some old HTML documentation, where are multiple code snippets (several lines long). I need to replace this old HTML-ized code with new one using modern styling. What I have now: ... ... ...
3
votes
1answer
67 views

Does ":norm! @q" use mapped keys inside the macro?

The documentation for :norm[al][!] states that "mappings will not be used" when the ! is written. Consider the following setup commands: :nnoremap \c Chello<esc> :let @q = '\cIthis is ...
2
votes
1answer
52 views

Finding where one word is close to another word: parametrized command in vimrc

I asked this question, about how to find where one word is close to another word, and Quasimodo gave the very fine answer: /\vaid(\W+\w+){,3}\W+country Now I want to parametrize this command into ...
0
votes
1answer
93 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 :...
2
votes
1answer
138 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 ...
1
vote
1answer
191 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
328 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
28 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
102 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
530 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
217 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
143 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
32 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
77 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
130 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 | (...
2
votes
1answer
640 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
38 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
44 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 ...
3
votes
4answers
3k 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
208 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
979 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
135 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
290 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
80 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
57 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
857 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
567 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....