Vim icon indicating copy to clipboard operation
Vim copied to clipboard

saving macros

Open erdult opened this issue 7 years ago • 21 comments

Is there a way to save the macros to a file that are stored in registers during the session

erdult avatar Feb 12 '18 21:02 erdult

You can do do :reg to show what's in your registers.

Chillee avatar Feb 14 '18 06:02 Chillee

I want them to be available next time I start the visual studio code. reg will just display them. With vim one can do this in vimrc file.

erdult avatar Feb 14 '18 08:02 erdult

Is this solved yet? Would be too cool, as I currently make translations from one language to another and have like ten %s/ replace commands i'd like to save as a macro and do each time, saved between sessions.

ozdy avatar Aug 02 '18 13:08 ozdy

macros can't be saved now. But you can use key bindings get around with it. I use this to surround a code section in R markdown. Annoyingly enough, you have to put in single char each time :(

"vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["<leader>","q"],
            "after": ["{","j", "O","`","`","`","{","r","}",
                "<Esc>","}","k","o","`","`","`"]
        },               
    ],

sbbmu avatar Aug 25 '18 00:08 sbbmu

You can also use the above method to "load" your macros like a .vimrc:

"vim.normalModeKeyBindingsNonRecursive": [
    {    
        "before": ["<leader>", "q"],
        "after": [
            // let @a="f.r,@a"
            "q", "a", "f", ".", "r", ",", "@", "a", "q",
            // let @b="f,r.@b"
            "q", "b", "f", ",", "r", ".", "@", "b", "q"
        ]
    }            
]

You still have to run it every time you start Code, but at least your commands get mapped properly.

sbrow avatar Feb 11 '19 16:02 sbrow

I want to copy visual rect and LOG(INFO) << ..., but I must split LOG.. It's so ugly? A more friendly way to do this?

"vim.normalModeKeyBindingsNonRecursive": [
    {    
        "before": ["<leader>", "q"],
        "after": [
            // let @a="f.r,@a"
            // "q", "a", "y", "o", "LOG(INFO) << \" \" << __FUNCTION__ << \"", ",", ",@", ",a", ",q",
            "q", "x", "y", "o", 
"L", "O", "G", "(", "I", "N", "F", "O", ")", " ", "<", "<", " ", "_", "_", "F", "U", "N", "C", "T", "I", "O", "N", "_", "_", " ", "<", "<", " ", "\"", ",", " ", "\"", " ", "<", "<", " ", "\"", 
            // "LOG(INFO) << __FUNCTION__ << \", \", << \",", 
            "<Esc>", "p", "a",
":", "\"", " ", "<", "<", " ", "\"", ",", " ", "\"", " ", "<", "<", " ", "(", 
            "<Esc>", "<Esc>", "p", "a", ")", ";", "<Esc>", "q"
            // let @b="f,r.@b"
        ]
    }            
  ]

gggin avatar Feb 26 '19 02:02 gggin

@jpoon It seems this could be done with another subclass of HistoryFile or even just ctx.globalState. I'm happy to do this feature, but what approach do you think is best?

J-Fields avatar Mar 20 '19 23:03 J-Fields

Wow, when did they add all that stuff to the extensioncontext? Extending HistoryFile seems like a good fit.

We should probably have the history files written to the path defined by extensioncontext.storagePath

jpoon avatar Mar 21 '19 04:03 jpoon

I will try to explain examples with normalModeKeyBindingsNonRecursive above, because "before": ["<leader>", "q"] is not working for me I am using this expression is my settings.json.

"vim.normalModeKeyBindingsNonRecursive": [
    {    
        "before": ["q", "q"],
        "after": [
            "q", "t", "/", "<", "t", "e", "m", "p", "l", "a", "t", "e", ">", "<ENTER>", "q"
        ]
    }            
  ]

This mean, when you are starting VScode you have to press "qq" to force vscode to press some buttons for you, in my case this is sequence of "q", "t", "/", "<", "t", "e", "m", "p", "l", "a", "t", "e", ">", "<ENTER>", "q"(you can set more then one macros). After this "ritual", I can use my macros by clicking "@t".

NazarovALAL avatar Oct 25 '19 22:10 NazarovALAL

the solution from @sbrow worked fine for me BUT it's a clumsy workaround. Hope to see an elegant solution to this like @J-Fields is mentioning.

snackycracky avatar May 11 '20 08:05 snackycracky

I do plan on getting back to this, but just to give a quick update: when I attempted to implement this some months ago, it turned out to be more complicated than I'd anticipated because we store normal register contents as flat text, and macros as complex objects which weren't easily serializable.

J-Fields avatar May 11 '20 15:05 J-Fields

Hey, this would really benefit me, how is the status on this?

fredyonge avatar Sep 01 '20 09:09 fredyonge

@fredyonge In the next version you'll be able to save registers across sessions, but there are still some major issues that need to be figured out before it'll work for macros as well.

J-Fields avatar Sep 01 '20 17:09 J-Fields

Interested in this

sgtrusty avatar Oct 02 '20 03:10 sgtrusty

@fredyonge In the next version you'll be able to save registers across sessions, but there are still some major issues that need to be figured out before it'll work for macros as well.

Any update?

Nishith-Savla avatar Mar 12 '21 11:03 Nishith-Savla

@fredyonge In the next version you'll be able to save registers across sessions, but there are still some major issues that need to be figured out before it'll work for macros as well.

Any update?

Unfortunately this does not work yet (v 1.54.3)

urgenmagger avatar Mar 29 '21 05:03 urgenmagger

Probably the greatest shortcoming of VSCodeVim for me right now.

please-rewrite avatar Feb 07 '22 18:02 please-rewrite

Is there any update on this topic?

shukurillo0516 avatar Apr 18 '22 11:04 shukurillo0516

Is there any update? (from 2022..)

ingyeoking13 avatar Jul 08 '22 00:07 ingyeoking13

You can switch to https://github.com/vscode-neovim/vscode-neovim#-getting-started, pretty easy to set up and macros will be saved between sessions without any workaround

erupturatis avatar Feb 16 '23 07:02 erupturatis