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
1
vote
0answers
23 views

How to have word count exclude bracketed text?

I'm using vim to write documents and trying to get word count to exclude anything that is delimited by brackets, which I use for notes or comments that are not a part of the document. So I don't want ...
2
votes
1answer
138 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 ...
1
vote
1answer
26 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=...
3
votes
1answer
33 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 out. I ...
2
votes
1answer
107 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
36 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?
1
vote
1answer
106 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
590 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] ...
0
votes
1answer
52 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
48 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 ...
2
votes
1answer
59 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
77 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
74 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
84 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
101 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
89 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 ...
3
votes
1answer
271 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 ...
3
votes
1answer
140 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
130 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 ...
9
votes
1answer
634 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
130 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 ...
18
votes
5answers
4k 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
264 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:...
7
votes
1answer
230 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. ...
5
votes
2answers
101 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
495 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 ...
8
votes
2answers
939 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
167 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 ...
4
votes
1answer
106 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
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>...
5
votes
2answers
3k 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
435 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
128 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 ...
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 ...
8
votes
2answers
269 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
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 ...
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', ...