Questions tagged [count]
Vim's "count" feature allows you to multiply or iterate a command by passing it an optional number.
44
questions
1
vote
1
answer
37
views
Replace command with /n works wrong
I tried to count sentences in the text using the :s///gn command. It does no replace actually, just counts. The total command was:
:%s/\C[A-Z]\_.\{-}[.?!]\_s\+//gn
A sentence must start with a ...
0
votes
1
answer
27
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>...
0
votes
0
answers
12
views
Insert ordered list in visual mode? [duplicate]
In visual (or visual block) mode, how do I insert an ordered list?
For example, convert
foo bar baz quux
corge grault garply
waldo fred plugh
xyzzy thud
to
1. foo bar baz quux
2. corge grault ...
2
votes
1
answer
28
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 ...
0
votes
0
answers
16
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<...
1
vote
1
answer
42
views
How to get the number of occurrences of a certain character on the current line in Vim?
Using Vim 8. I want to count the number of pipe symbols that are on the current line so that I can compare it to the other lines in the file and make sure my pipe symbol count is consistent. How do I ...
1
vote
1
answer
53
views
Can you get a count on a search where the count is > 1000 matches?
I have a file listing all the books I have read since 2013. I told someone I read x books a week and they didn't believe me so I started doing it :)
The data looks like this. The last column is the ...
2
votes
0
answers
72
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
1
answer
232
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
1
answer
34
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
1
answer
48
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
1
answer
206
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
1
answer
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
1
answer
136
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
2
answers
959
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
1
answer
53
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
1
answer
62
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
1
answer
66
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 ...
3
votes
2
answers
144
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
2
answers
107
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
1
answer
101
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
2
answers
114
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
1
answer
104
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
1
answer
332
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
1
answer
204
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
1
answer
162
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
1
answer
717
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 ...
6
votes
2
answers
138
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
...
23
votes
5
answers
5k
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
2
answers
330
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
1
answer
271
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
2
answers
104
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
1
answer
568
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
2
answers
1k
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
1
answer
200
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
1
answer
111
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
1
answer
54
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>...
6
votes
2
answers
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
1
answer
454
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
1
answer
130
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 ...
7
votes
2
answers
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
2
answers
281
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. ...
19
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 ...
6
votes
2
answers
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', ...