Questions tagged [count]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
38 views

Undo <count> macro instances

Often I would record a macro and run it till end of file like 200@q. However, there may be a few lines/instances at the bottom I don't want to run the macro on (like 5 lines). Pressing u would undo ...
1
vote
1answer
35 views

Why does `.,.+[count]` appear in command box when typing [count+1] before :

For example if in normal mode 4: is pressed, in the command line there will be :.,.+3. What does this mean and what is it used for?
5
votes
2answers
107 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 ...
1
vote
1answer
85 views

Make mapping that accepts count independent of line count

I have a mapping that looks like this: nnoremap <expr> <c-x>b ":call MyFunction(" . v:count . ")\<cr>" I also tried to instead define function with range, but the effect is the ...
2
votes
2answers
360 views

How to add a [count] to a binding

How do you create a binding that behaves like yy but doesn't yank the leading white spaces? nnoremap <leader>f ^v$y Yanks one line and the ^J. Which is what I want but how do I add a [count] ...
16
votes
5answers
3k 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 ...
0
votes
1answer
50 views

Call function with count after performing some normal! level tasks

I have this following function " copy yanked text to tmux pane function! Send_to_tmux(count) range if (a:firstline == a:lastline) execute "normal! \"zyip" else execute "normal!...
0
votes
1answer
45 views

Mappings with counts at the end without using loops?

Suppose you are trying to create a set of mappings such that pressing <C-t> followed by a number # would alternate to the respective tab at index #. I know that using a loop, I can do: " Map ...
6
votes
2answers
2k 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', ...
2
votes
1answer
53 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
71 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
52 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} ...
8
votes
2answers
252 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. ...
0
votes
1answer
72 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
94 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>` ...
2
votes
1answer
366 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 ...
2
votes
1answer
427 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 ...
0
votes
1answer
52 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>...
4
votes
1answer
156 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 ...
8
votes
2answers
712 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 ...
5
votes
2answers
97 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 ...
8
votes
1answer
551 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 ...
3
votes
1answer
244 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
102 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 ...
6
votes
2answers
3k 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 ...
3
votes
2answers
2k 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 ...
3
votes
1answer
123 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
107 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 ...
1
vote
1answer
124 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 ...
18
votes
1answer
2k 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 ...
7
votes
1answer
185 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. ...
1
vote
1answer
73 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 ...
6
votes
2answers
208 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:...