M
M
Maxim Samoilov2014-06-10 06:01:39
vim
Maxim Samoilov, 2014-06-10 06:01:39

How to use numbers before a command in Vim?

Actually, how to make the number entered before pressing your own keyboard shortcut set not the number of repetitions, but something else.
For example, creating a for loop from zero to the entered digit should look something like this:

map <Number><A-m> Afor (int i = 0; i < <Number>; i++) {<Enter>

Outcome:
function! MyFor(v)
python <<EOF
import vim
v = vim.eval("a:v")
vim.current.line = vim.current.line + "for (int i = 0; i < " + v + "; i++) {"
EOF
endfunction
nnoremap <A-f> :<C-U>call MyFor(v:count)<CR>o<Esc>o}<Up><Tab>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentine, 2014-06-10
@Nitive

Here , in the Supplying a count to a map section, it says that the number will be available through the v:count variable. There are also examples there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question