Skip to main content

Questions tagged [count]

Vim's "count" feature allows you to multiply or iterate a command by passing it an optional number. Questions about counting things should use the "counting" tag instead.

Filter by
Sorted by
Tagged with
24 votes
5 answers
7k 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 ...
DJMcMayhem's user avatar
  • 17.8k
21 votes
1 answer
3k 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 ...
Rich's user avatar
  • 32.4k
9 votes
1 answer
801 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 ...
DJMcMayhem's user avatar
  • 17.8k
8 votes
2 answers
2k 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 ...
SibiCoder's user avatar
  • 3,442
8 votes
2 answers
296 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. ...
Daniel's user avatar
  • 183
8 votes
2 answers
160 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 ...
Eric Burgess's user avatar
7 votes
2 answers
4k 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 ...
Mas Bagol's user avatar
  • 537
7 votes
1 answer
468 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. ...
wefwefa3's user avatar
  • 1,193
6 votes
2 answers
4k 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 ...
math hates me's user avatar
6 votes
2 answers
396 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:...
statox's user avatar
  • 50.4k
6 votes
2 answers
3k 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', ...
John O'M.'s user avatar
  • 8,622
5 votes
2 answers
114 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 ...
DJMcMayhem's user avatar
  • 17.8k
4 votes
3 answers
251 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 ...
Enlico's user avatar
  • 2,256
4 votes
2 answers
2k 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] ...
nunmap's user avatar
  • 55
4 votes
1 answer
257 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 ...
Toothrot's user avatar
  • 3,139
4 votes
1 answer
121 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 ...
joeytwiddle's user avatar
  • 3,652
3 votes
1 answer
421 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 ...
srghma's user avatar
  • 155
3 votes
1 answer
1k views

Fastest way to find last occurence of a character in line?

Say we have the following: echo 'This is a test'.$test1.$test2.$test3.$test4.$test5.'and this is another test'; ^ With the cursor being on the first dollar sign, and I want to ...
MiK's user avatar
  • 143
3 votes
1 answer
76 views

Repeating command for running external script?

I have a script called lorem.sh which takes in the number of paragraphs (first argument) and number of lines in each paragraph (second argument) and prints random text of that format to standard ...
First User's user avatar
3 votes
1 answer
247 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 ...
user avatar
2 votes
2 answers
115 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>` ...
Greg Nisbet's user avatar
  • 1,889
2 votes
1 answer
464 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 ...
VanLaser's user avatar
  • 9,840
2 votes
5 answers
143 views

Mapping with termwinkey that accepts a v:count

In Vim, typically, prefixing a command repeats the action multiple times. This is not the case for gt, which goes to the next tabpage. Whereas gt goes to the next tabpage, 2gt always goes to the ...
user22476690's user avatar
2 votes
1 answer
327 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 ...
ChocolateOverflow's user avatar
2 votes
1 answer
71 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 ...
Travis's user avatar
  • 121
2 votes
1 answer
627 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 ...
DJMcMayhem's user avatar
  • 17.8k
2 votes
1 answer
34 views

Vimscript - Prevent Column From Moving When Using a Count

When you use a count to a key mapping it goes down count number of times and resets to column 1. Actually it already resets to col 1 when entering the function if there is a count. So I can save the ...
theerrormagnet's user avatar
1 vote
1 answer
164 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 ...
Thunderbeef's user avatar
1 vote
1 answer
43 views

Create mapping that works both with a motion and a count

I'd like to have a mapping that separates words, like this: noremap RJ :s/\>\s*\</\r/g<CR>='' I can do 3RJ with that. I can also create opfunc, so I can do RJ}: noremap RJ :set opfunc=...
pacholik's user avatar
  • 113
1 vote
2 answers
139 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} ...
Dr Krishnakumar Gopalakrishnan's user avatar
1 vote
1 answer
155 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 ...
Octaviour's user avatar
  • 982
1 vote
1 answer
54 views

Is there a way to substitute a text that has regex formatted number ranges and replace with all combinations?

Let's say I have a file that looks like: host[1-2]lx host[1-4]win what I want is an easy way to get host1lx host2lx host1win host2win host3win host4win Is there a neat way to automate that process? ...
deedar huq's user avatar
1 vote
1 answer
19 views

How can I replicate behaviour of go-to command? (42gg, 42G)

I've been searching far and wide around tutorials, :help command, source code, Stacks but maybe I just can't form my query correctly in Vimscript. My goal is to have a short command for switching ...
Radosław Cymer's user avatar
1 vote
1 answer
37 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?
user avatar
1 vote
1 answer
149 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 ...
infmagic2047's user avatar
0 votes
1 answer
146 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 ...
albfan's user avatar
  • 178
0 votes
1 answer
175 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 ...
kevinlawler's user avatar
0 votes
1 answer
216 views

vim mapping diffput / diffget to Ctrl+Left / Ctrl+Right with working buffer selection from count

Pretty new to mappings in Vim, In Diff Mode I've got C-Up and C-Down mapped to [c and ]c for diffjumping. I'm wanting to map C-Right and C-Left to :<C-U>diffput v:count<CR> and :<C-U>...
Jack T's user avatar
  • 1
0 votes
1 answer
64 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!...
3N4N's user avatar
  • 5,864
0 votes
1 answer
81 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 ...
Jorget Millani's user avatar
0 votes
0 answers
18 views

How can I have my mapping handle a count in a function? [duplicate]

I wrote the following filetype plugin. It comments out lines in shell scripts by typing <leader>c. The problem is when I execute the mapped command multiple times by writing for example 4<...
theerrormagnet's user avatar
0 votes
1 answer
59 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>...
AMackie's user avatar