Vim
Vim copied to clipboard
saving macros
Is there a way to save the macros to a file that are stored in registers during the session
You can do do :reg
to show what's in your registers.
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.
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.
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","`","`","`"]
},
],
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.
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"
]
}
]
@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?
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
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".
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.
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.
Hey, this would really benefit me, how is the status on this?
@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.
Interested in this
@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?
@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)
Probably the greatest shortcoming of VSCodeVim for me right now.
Is there any update on this topic?
Is there any update? (from 2022..)
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