I use coc.nvim with the proposed default configuration that set (in a lua file) :
-- Use `[g` and `]g` to navigate diagnostics
-- Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
keyset("n", "[g", "<Plug>(coc-diagnostic-prev)", {silent = true})
keyset("n", "]g", "<Plug>(coc-diagnostic-next)", {silent = true})
I would like to know is there is a way to make these motion repeteable with ".".
I see that the tpope's plugin vim-repeat seems to allow it. Indeed, it says that:
Adding support to a plugin is generally as simple as the following command at the end of your map functions.
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
But I have no idea how to actually put this line of code with the "keyset" command.
Do you have an idea of how to do it?
Thanks for reading (and helping) me!
Cross-posted with https://github.com/tpope/vim-repeat/issues/92#issuecomment-1826910664
In your example:
You can do something like:
or
and similar for
]g. You may want to make some helper function to reduce repeating similar lines.The use of
feedkeysis quite hacky and brittle here (although you can useexprto avoidfeedkeys), so below I would suggest some ways to automatically create an internal wrapper mapping that makes things repeatable.A general recipe & usage for neovim (Lua)
You can use the following wrapper to conveniently wrap a
rhsto be passed tovim.keymap.set:(Note: this does not implement
optsfor such asbuffer,nowait,silent, etc., but it should be straightforward to extend)Example: If you want to make a keymap
<leader>tcmapped to a lua function (or any keymap sequence string) repeatable:This will:
<Plug>(ToggleComment)that does the job to make the internal keymap repeatable.<leader>tcto<Plug>(ToggleComment), which will execute the desired body (rhs).{ remap = true }.More detailed explanation and breakdown
So in order to make vim-repeat work, in general one should have a keymap (or a command) like:
<Plug>(MyKeymap).repeat#set("<Plug>(MyKeymap)")to mark the keymap sequence to repeat by..feedkeysunder the hood -- so need to usenvim_replace_termcodes; also an anonymous function cannot be used.For keymap, it is very recommended (although not mandatory) to use
<Plug>to create an internal mapping, because this will make key repeat much, much easier to write and understand.