VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
13.83k stars 1.31k forks source link

saving macros #2380

Open erdult opened 6 years ago

erdult commented 6 years ago

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

Chillee commented 6 years ago

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

erdult commented 6 years ago

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.

ozdy commented 6 years ago

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.

sbbmu commented 6 years ago

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","`","`","`"]
        },               
    ],
sbrow commented 5 years ago

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.

gggin commented 5 years ago

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"
        ]
    }            
  ]
J-Fields commented 5 years ago

@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?

jpoon commented 5 years ago

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

NazarovALAL commented 4 years ago

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".

snackycracky commented 4 years ago

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.

J-Fields commented 4 years ago

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.

fredyonge commented 4 years ago

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

J-Fields commented 4 years ago

@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.

sgtrusty commented 4 years ago

Interested in this

Nishith-Savla commented 3 years ago

@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?

urgenmagger commented 3 years ago

@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)

please-rewrite commented 2 years ago

Probably the greatest shortcoming of VSCodeVim for me right now.

shukurillo0516 commented 2 years ago

Is there any update on this topic?

ingyeoking13 commented 2 years ago

Is there any update? (from 2022..)

erupturatis commented 1 year ago

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

darianmorat commented 1 month ago

Any updates?