-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export Macros Plain Text #14732
Comments
What about |
This translates a literal |
Strongly agree! When I am recording a complex long macro, it's very disturbing when I misspell just single word and has to redo this complex macro. |
You can just paste from the register, modify the macro and load it back. See https://thoughtbot.com/blog/how-to-edit-an-existing-vim-macro. This works fine when quickly editing a macro, but as you may notice, special characters (like escape) are stored literally, which works fine inside Vim, but does not play nice with regular text files / text processing tools. |
Edit: @W4RH4WK basically said what I've written in this message.. Feel free to skip it. Also, sorry it isn't a solution for you, since you know this method but want a plain text version.. @PascalZh To edit a macro you can paste it somewhere in a buffer, edit it, and copy it back into the register, to be applied:
You can also share macros (really, registers) by saving them in a file, with the syntax: let @a = 'paste your macro here' All special characters like Escape (^[) and ^ then [ will be saved and restored correctly. Note that to paste a register literally from insert mode (if you ever want that), use |
Regarding plain text, I think a translation can be to encode all non-printable inside Escape is: With an exception for <, which would be encoded as Can be done in a few lines of vimscript or C or Lua (not including the translation mappings), would be nice to have it builtin 👍 |
I think some plugin would be better than having it built in. Anybody could give a recommendation? |
Maybe it can be done (for example) with something like this: function! EscReg(reg) abort
let lhs = '<sid>(_tmp)'
call nvim_set_keymap('n', lhs, getreg(a:reg), {})
let res = maparg(lhs)
call nvim_del_keymap('n', lhs)
return res
endfunction
nnoremap <silent> \p "=EscReg(nr2char(getchar()))<cr>p |
This seems to be also achievable using FFI: local ffi = require('ffi')
ffi.cdef([[
char *str2special_save(const char *str, bool replace_spaces, bool replace_lt);
void xfree(void *ptr);
]])
function _G.Str2special(src)
local ptr = ffi.C.str2special_save(src, true, true)
local str = ffi.string(ptr)
ffi.C.xfree(ptr)
return str
end These can then be converted back using For example, to turn register let @a = v:lua.Str2special(@a) To turn it back into a macro: let @a = nvim_replace_termcodes(@a, v:false, v:true, v:true) |
Btw, other people have pointed out Marvim to me. |
|
Macros stored in registers can already be pasted, modified, and loaded. However, special keys like escape or enter are not represented as printable characters. This makes it hard to store macros in text files.
IIRC there are escape sequences like
\<CR>
one can use, but there doesn't seem to be a way to convert the original macro representation to one that uses only printable characters.Can we improve upon this somehow such that macros can be exported to plain text files without messing up the file?
Edit: I also want to load a macro from this plain text representation.
The text was updated successfully, but these errors were encountered: