Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [count]

Vim's "count" feature allows you to multiply or iterate a command by passing it an optional number.

2
votes
1answer
36 views

Are counts commutative?

Newbie question: Are counts commutative? 2d2w is the same as 4dw, right? Is it the case for all commands that (count1)(verb)(count2)(whatever) the same as (count1+count2)(verb)(whatever)? If counts ...
1
vote
1answer
57 views

`gt` is not consistent with `gT` (and many other commands) when `{count}` is prepended

I know it's not a bug, since the help page explains it cleary, but is there any reason why gt is still kept different from the majority of commands that accept a {count} prepended? I mean, isn't it in ...
1
vote
2answers
42 views

Changing content within the specified [count] number of braces for each line

I need to change the content within a [count] number of braces for each line in my buffer. 1 {Lorem} ipsum dolor {amet} blah blah {change this text} more blah blah 2 Hello. The {sun} rises in {the} ...
0
votes
1answer
55 views

Is it possible to detect when a command uses no count?

Based on v:count help I define: :map _x :<C-U>echo "the count is " . v:count . ' and count1 is ' . v:count1<CR> So _x the count is 0 and count1 is 1 0_x the count is 0 and count1 is 1 ...
2
votes
2answers
50 views

How to clear digit arguments in a mapping?

I have a set of bindings for jumping to the (n*10)th column that are basically just sugar over the | command and somewhat nice for coarse horizontal movement. nnoremap <silent> <leader>` ...
1
vote
1answer
49 views

reset count for `v`

According to :help v a count of 1 provided to v will select the same number of characters as the previous selection, but starting from the current cursor (see full help below). When there was no ...
4
votes
1answer
221 views

How can a mapping have behavior dependent on the presence of a count?

I have this mapping to move by visible line when wrap is enabled nnoremap <silent> j gj nnoremap <silent> k gk But when I use a count (like 10 j), I expect to move by actual lines How ...
4
votes
1answer
76 views

repeat search in vim: count is off by one sometimes

I've happily used count prefixes on search commands in vim for probably a couple of decades, so I know they used to count correctly. 5n was equivalent to n 5 times. As of some recent version, 5n is ...
0
votes
1answer
66 views

how to accept count for visual block ctrl+a remap?

I have created a vmap but I can't figure out how to apply a count to it. In this case, the mapping is on <C-a> and 4<C-a> is an example of a command with a count failing to be applied. We ...
5
votes
1answer
192 views

How to allow count *before* my custom operator?

I'd like to define my own operator. Vim's builtin help has a nice little tutorial on it, where they show you can create your own operator with opfunc and g@: nmap <silent> <F4> :set ...
5
votes
2answers
63 views

Unexpected behavior using “<count>J” to join multiple lines

When I prefix the J ("join") command with a count, Vim is joining one fewer line than I expect. For example, with the cursor at the first column, first line of the following, one two three four five ...
12
votes
4answers
955 views

Can I repeat a macro with the “dot operator”?

Can I repeat a macro with the . command? For example, I'd like to be able to type: @q... and have it effectively call @q 4 times. With the default behavior, this works only if 'q' holds a single ...
6
votes
2answers
119 views

How to get the count given to a macro?

When executing an ex command I can use the variable v:count to get the count which was given to this command. From :h v:count, if I create this mapping: :map _x :<C-U>echo "the count is " . v:...
6
votes
1answer
114 views

What does [count]v and [count]V do? How is it useful?

I am confused about how the start visual commands work when you pass them a count. I checked the help page but I am still confused. [count]V Start Visual mode linewise. ...
6
votes
2answers
80 views

Can I make the indent commands take an additional count that doesn't affect the motion?

Let's say I'd like to indent the current line 4 times. (Not 4 spaces, 4 indent commands). As far as I can tell, the shortest way to do this is >>... (Indent once, repeat three times) This ...
2
votes
1answer
174 views

Can I make all “resize split” commands take a default count?

While reading through this answer, I found these useful commands: Ctrl+W +/-: increase/decrease height Ctrl+W >/<: increase/decrease width These are super useful, but I hate how it defaults to ...
7
votes
2answers
295 views

Repeat n time a mapping starting with a count

I have created the following mapping: :map <F8> 3w When I pressed 2<F8>, I thought it would move six words (2*3w), but it moves 23 words. (This has been mentioned in help section of vim ...
4
votes
1answer
133 views

Insert mode counts in neovim

Is there a way to get insert mode emacs style meta counts in neovim (which has support for the meta key)? Such that, for instance, <m-3>- produces 3 hyphens. PS. I mean is it possible to ...
5
votes
1answer
94 views

Can my mapping/function detect when count/range 1 is given instead of none?

I have a key mapped to a command which runs a function, and I would like to detect whether it has been passed a range (prefixed with a count) or not. The difficultly is that I need to be able to ...
0
votes
1answer
42 views

Why does the <count> escape sequence insert the current line number in my user command?

I've added the following to my .vimrc in order to test how <count> works in a user defined command because I was noticing odd behaviour: :command! -count=1 CountTest :exe "echo " . <count>...
2
votes
2answers
849 views

Creating a Vim function mapping that takes a count

I'm trying to create a function mapping that takes a count, in this case the number of lines to yank to the system clipboard. func! Clipboard() echo 'Clipboard function called' if v:count is 0 ...
2
votes
1answer
335 views

Original column number in a mapped function called with a count

Here's an example: function! TestCursorPosWithCount() range echo virtcol('.') endfunction nmap <leader>c :call TestCursorPosWithCount()<CR> If I press <leader>c, the column ...
1
vote
1answer
109 views

How can I clear normal mode command count in mappings?

I have a mapping like this: noremap <expr> zj FindNext() FindNext will calculate which line to go, and return something like 10G. This works without a count, but with a count the line number ...
5
votes
2answers
2k views

What does [count]<leader> mean?

I found a command in NERDCommenter like this: [count]<leader>cc |NERDComComment| I have installed the plugin. But, I don't know how to make it work. So what's the meaning of that command? How ...
8
votes
2answers
208 views

What does [count]% do?

I would expect [count]% to jump back and forth between matching braces count times or something like that, but instead, typing that command seems to move the cursor to a random place in the buffer. ...
18
votes
1answer
1k views

How can I map d[count]d?

N.B. This is not a duplicate of How does the "d3fg" command work? Please read it before voting to close! I've come to a bit of an impasse in my quest to get small deletions work like big ...
6
votes
2answers
813 views

Bidirectional tag stack movement with cscope in vim

When using ctags, one can move back through the tag stack by using [count]CTRL-T or :[count]pop, and forward using :[count]tag However, when using cscope instead of ctags and setting 'cscopetag', ...