You probably want to use :h getchar()
to let the user input the name of the mark they want to set, otherwise your mapped m
command will be executed without a mark name and that doesn't work.
Here is an example in vimscript using a function: You remap m
to call the MarkAndDo
function. This function reads the input of the user with getchar()
and uses execute
to run the command m + mark name
then you can do whatever you want in the function.
function! MarkAndDo()
execute "normal! m" . nr2char(getchar())
echo "hello world"
endfunction
nnoremap <silent> m :call MarkAndDo()<CR>
Adapting this solution to the nvim_set_keymap()
api is straight forwards:
vim.api.nvim_set_keymap("n", "m", ":call MarkAndDo()<CR>", {noremap= true})
If you want to keep it a one liner that should be possible too but I think that it's better to use a function to keep your code readable.