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 @.
139
questions
3
votes
1answer
102 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
180 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
44 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
262 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 ...
1
vote
2answers
331 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
46 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
83 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`, `...
10
votes
2answers
802 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
178 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
690 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
281 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
223 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
284 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
42 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
960 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
35 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
83 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
104 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
109 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 ...
3
votes
4answers
434 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 $...
5
votes
2answers
1k 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
58 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 ...
3
votes
1answer
222 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)
...
3
votes
3answers
264 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 ...
18
votes
1answer
4k views
Save a macro just created in vimrc
Sometimes I create macros. Sometimes I create the same macro multiple times.
Sometimes I get tired of creating the same macro over again. Can I store macros? Can I load a preset of macros? Can I make ...
1
vote
1answer
178 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 (...
3
votes
3answers
2k 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 ...
1
vote
1answer
2k 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 ...
8
votes
2answers
2k 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 ...
7
votes
1answer
338 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
1k 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.
...
2
votes
2answers
603 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 ...
17
votes
5answers
3k 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
243 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 ...
6
votes
1answer
129 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
2answers
161 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 ...
3
votes
1answer
263 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
837 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
2k 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
234 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
240 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)?
3
votes
2answers
319 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 ...
11
votes
1answer
807 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 ...
2
votes
3answers
1k 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 ...
11
votes
3answers
769 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
65 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, ...
6
votes
1answer
775 views
How do I ignore regex failure while running a macro?
If I have a regex in a recorded macro and then run it over a line that the regex fails to match the macro stops. For example, I have a list of files.
family-reunion-2015.webm
road-festival-20150607....
3
votes
1answer
819 views
insert register contents on a macro
How can I include the contents of a register when recording a macro?
If I use Ctrl+R x I get a "pointer" to register x, i.e., my macro will contain ^Rx instead of the register contents.
Motivation:
...