Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass an argument to a function through a keymapping?

Tags:

vim

I have a function that takes an argument (num) I'm wanting a mapping so that I can enter a number beforehand and it gets passed to the function.

e.g If I press 3<leader>i

I would like the following to happen: :call MyFunction(3)

like image 364
Adam Ladell Avatar asked Oct 21 '25 12:10

Adam Ladell


1 Answers

The repeat number is automatically stored in v:count and v:count1, whichever suits your needs. Also, you have to drop the line range out (:help c_CTRL-U):

nnoremap <Leader>i :<C-U>call MyFunction(v:count1)<CR>
like image 60
Matt Avatar answered Oct 23 '25 07:10

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!