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
5
votes
2answers
179 views

Efficient ruby line splitting

I never made any plugins but I would like to get some advice for a specific case. I'm writing a lot of ruby. Sometimes I have very long lines that I want to split. Example: MyModel.first_method....
1
vote
3answers
322 views

Conversion from XML to KML

I have an XML file with this format (there could be some leading spaces): <Latitude>23.1138</Latitude> <Longitude>8.2898</Longitude> ... <Latitude>19....
6
votes
2answers
107 views

Swap register key from @ to another more accessible key

I used many macros assigned to registers, for instance I have this line in my .vimrc: let @p='^[O</p>^[0jj' I just type @p and it closes the tag, very convenient. PROBLEM: On my new keyboard @...
11
votes
2answers
455 views

Is there a way to detect if I'm recording in vimscript?

Is there anything like eval("is_recording()") that I can call in my vimscript to find out if I am currently recording a macro? I would have thought this works: eval("mode(1)") but that just ...
8
votes
1answer
648 views

Continue an ex mode command after “norm”?

I often use extremely long macros when handling repetitive editing and refactoring. Whenever possible I write these as ex-mode commands rather than recording them as macros, because they are easier ...
4
votes
2answers
102 views

Make a frequent RSpec edit easy & repeatable

Writing unit tests in RSpec, I frequently change something like this, it 'eats pizza' do pizza = build(:pizza) expect(subject.eats?(pizza)).to be_true end to this, let(:pizza) { build(:pizza) } ...
8
votes
5answers
1k views

Can Vim write incremental lines? i.e. on each line A becomes B, and 1 becomes 2

I wanted to write this: A = mapping[0] B = mapping[1] C = mapping[2] D = mapping[3] E = mapping[4] F = mapping[5] G = mapping[6] H = mapping[7] I = mapping[8] J = mapping[9] K = mapping[10] L = ...
14
votes
2answers
2k views

How do I stop a recursive macro at the end of the line?

How can I create a recursive macro so that it only runs until the end of the line? Or how to run a recursive macro until the end of the line only?
3
votes
1answer
2k views

Delete all recordings?

I don't want to disable recording entirely, but I'm not happy with vim keeping my recordings between sessions, and occasionally I fat finger the @ key and end up with a bunch of garbage in the active ...
2
votes
0answers
192 views

Esc from insert in macro prints ê^ instead of running Esc

Here's a sample macro. 2Ea,^[j^ (Jump to the end of the second word, append a "," escape visual mode, and go to the next line.) Instead of 99 The, I get 99 The,ê^ and it stays stuck in insert mode. ...
2
votes
1answer
150 views

What is the fastest way to perform this change?

In my codes, I often have to do this kind of text editing: u(:,:,:) = 0._dp v(:,:,:) = 0._dp temp(:,:,:) = 0._dp To: grid%u(0:nx,0:ny,0:nz) = 0._dp grid%v(0:nx,0:ny,0:nz) = 0._dp grid%temp(0:nx,0:...
2
votes
1answer
1k views

Macro won't exit insert mode with Esc

I record this macro: ia^[sb^[ It should open insert mode, write a, exit, replace with b, then exit insert mode again. you can bind it to @w with: :let @w='ia^[sb^[' For whatever reason instead of ...
2
votes
2answers
91 views

Convert outline to .csv macro

I am taking notes in an outline format that looks like this: * Micro topic 1 ** Microbes are small ** You can't see them! *** Isn't that something? * Micro topic 2 ** I hope I like the teacher *** ...
1
vote
1answer
382 views

Macro fail with E488: Trailing characters: i:

I have something like this : neckbeard: "https://appa.com/emoji/neckbeard/c8ec7bf188.png", metal: "https://appa.com/emoji/metal/9f936a4278.png", fu: "https://appa.com/emoji/fu/2f615de37f.png", ...
7
votes
3answers
163 views

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

Have been reading vim scripting posts for an hour, but I'm afraid I don't have the skills to apply these posts to my problem. Editing math in latex documents, I'm frequently wanting to replace math ...
2
votes
3answers
81 views

How to move to the next matching string and then hit delete twice in a macro?

I have a rather long chat transcript that I copied out of a window, and when I pasted it into vim, it put two line breaks after every username, and then what the user typing said. I'd like to: ...
4
votes
2answers
551 views

Apply macro to every `n`-th line

I would like to apply macro a to a set of lines. For consecutive lines, this can be done by :5,10norm! @a (https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines)....
0
votes
2answers
1k views

auto number counting with macro

I want to record a macro, which generates a formatted text that includes a number. I want the number to be counted up whenever the macro is invoked. For example: abc 1 def abc 2 def abc 3 def Can I ...
13
votes
6answers
3k views

Delete all consecutive duplicates

I have a file that looks like this. Move to 230.00 Hold Hold Hold Hold Hold Hold Move to 00.00 Hold Hold Hold Hold Hold FooBar Hold Spam Hold I would like it to look like this: Move to 230.00 ...
3
votes
1answer
103 views

Is there any possibility of making Vim UI show which register a macro is currently being recorded to?

Vim users, tell me how many times you remember looking down at your status bar and unexpectedly seeing recording in bold green. It's been recording your keystrokes since you-dont-know-when. This has ...
1
vote
1answer
49 views

Is there a way to perform more than one Ex-mode action on the current visual selection?

This would be particularly useful for macros, i.e., select visually the exact lines I want to perform the macro on, and then run the macro. But currently when it finishes the first action, the visual ...
14
votes
3answers
938 views

How do I apply a set of keystrokes to every occurrence of a word?

If I want to delete every word, that is easy, because I would do something like this: :s%/WORD//g But what if I want to do xyz to every occurrence of "WORD"? For example, let's say I want to delete ...
12
votes
2answers
1k views

How can I record a nested macro?

I want to record a macro within a macro, like so: qa [ first macro ... ] qb [ second macro ... ] q [ some more stuff, involving @b ... ] q However, the second q is ...
28
votes
3answers
56k views

How do I stop recording while in command line?

When I am recording a macro with q and I am done, I can type: q to stop recording if I am in normal or visual mode. <c-o>q to stop recording if I am in insert mode. .. How do I stop recording ...
3
votes
1answer
150 views

Is it safe to do other stuff on a system while a macro runs?

If I'm running a complex macro on a large file that I expect to take a few minutes, is it OK to do other stuff on the system (e.g. opening another application, typing in a different text editor, etc?) ...
13
votes
1answer
2k views

Improve macro replay speed?

I recorded a simple macro and replayed it on following lines, but it seems replay speed is very slow (handle a very few lines per second). Is this expected and is there a way to improve such speed?
3
votes
2answers
337 views

Copy a word in macro without using a register

I want to create a macro that will take a word logThis, which is selected in visual mode, and turn it into this: console.log 'printing logThis' console.log JSON.stringify(logThis, undefined, 2) I ...
6
votes
3answers
4k views

Multiple search-replace operations on a selection

I have a LaTeX file with a bunch of commands of the form \label{<word>} where the <word> represents a string that contains special characters, namely á é í ó ú ý ð þ æ ö. I'm looking for a ...
11
votes
3answers
10k views

Insert an incrementing number to each line in either a selection or a match

I have a problem I can think of two general approaches for solving, but I don't know specifics for either approach. ... Level 1: cũng also Level 1: và and Level 1: như like; such ...
3
votes
3answers
3k views

Run macro over a visual selection with line movements

I can find an answer to a similar problem here, however although I can get that example to function I can't get what I want to do to work. Here is the example text to be edited, a partial section of ...
3
votes
0answers
150 views

How can I work around the inability to save macros in ViEmu? [closed]

I would like to be able to save my ViEmu macros between sessions of Visual Studio 2013. This feature was requested in 2010 and apparently almost made the cut for ViEmu 2.5: I was wondering if ...
3
votes
0answers
136 views

How to convert lines to numbered list? [duplicate]

I've few lines (or paragraph if easier - {, }) which I would like to convert to numbered/ordered list, in example: Item one Item two Item three into: 1. Item one 2. Item two 3. Item three I would ...
50
votes
2answers
12k views

How can I view and edit my recording (i.e. recorded macro)?

I'm using complex repeats to record my operations (qq to record, some operations, q to stop) and I did a mistake. It is possible to see what I've recorded and correct the mistake, instead of doing it ...
23
votes
8answers
7k views

How to add permanent line numbers to a file?

I have a text file like this (using gVim on Windows) foo bar baz quux corge grault garply waldo fred plugh [...150 more lines...] xyzzy thud I want to add a number to each line in the file. Not ...
24
votes
2answers
4k views

Swap function arguments

When refactoring code it would be useful to be able to swap function arguments. Changing for eg: func(foo[0], bar(), baz.spam) into func(baz.spam, foo[0], bar()) Is there some way to swap ...
4
votes
1answer
79 views

Can the command-line window be entered without interrupting macro recording?

I'm having a problem using the command-line window (help cmdwin), which is extremely useful, but it doesn't play well with macros. cmdwin is invoked with q:, so if there is a macro being recorded, ...
1
vote
2answers
54 views

Created a formatted list of percentages efficiently

Let's say we wanted to produce the following text in a very "vim" way: Row 1 { 33.33%; } Row 2 { 66.66%; } Row 3 { 100%; } This isn't too complicated, but I think of it as a standin for ...
16
votes
2answers
5k views

How can I run a function or macro across a folder of files?

Let's say I have a function, named StripWhitespace. I can run it on a single file by opening the file and running :StripWhitespace. How can I automatically run that function against a folder of ...
24
votes
1answer
3k views

After pressing qq, the status line says “recording”. How do I get out of this mode?

I accidentally pressed qq, and now the status line says recording. What does that mean? How do I get out of this "recording" mode? Pressing Esc doesn't work.

1 2
3