Make mapping that accepts count independent of line countHow can I map d[count]d?Creating a Vim function mapping that takes a countMaking a custom function to comment out a range of linesCan my mapping/function detect when count/range 1 is given instead of none?Repeat n time a mapping starting with a countCan I make the indent commands take an additional count that doesn't affect the motion?Swap two keys in such a way that works with both `f` and macrosHow do I use function to effect editing a file?My status line is getting erased, so I can't print function resultHow to make insert mode mapping count as multiple undos?
Could you use uppercase or special characters in a password in early Unix?
Why do baby boomers have to sell 5% of their retirement accounts by the end of the year?
What actually is "unallocated space"?
How can a stock trade for a fraction of a cent?
Why do some audio amps use AC while others use DC
Why did my relationship with my wife go down by two hearts?
What is the common verbal association?
I run daily 5kms but I cant seem to improve stamina when playing soccer
How much does freezing grapes longer sweeten them more?
Did it take 3 minutes to reload a musket when the second amendment to the US constitution was ratified?
Why do these two ways of understanding constant acceleration give different results?
If I did not sign promotion bonus document, my career would be over. Is this duress?
Company indirectly discriminating against introverts, specifically INTJ
First author doesn't want a co-author to read the whole paper
What is Ferb's name short for?
What's the meaning of Electrical Inches?
Sum of all digits in a string
Can elves trance in armor without any downsides?
How to figure out key from key signature?
Does C have an equivalent of std::less from C++?
How can I seal 8 inch round holes in my siding?
Prisoner's dilemma formulation for children
Why is Trump releasing (or not) his tax returns such a big deal?
Why do military jets sometimes have elevators in a depressed position when parked?
Make mapping that accepts count independent of line count
How can I map d[count]d?Creating a Vim function mapping that takes a countMaking a custom function to comment out a range of linesCan my mapping/function detect when count/range 1 is given instead of none?Repeat n time a mapping starting with a countCan I make the indent commands take an additional count that doesn't affect the motion?Swap two keys in such a way that works with both `f` and macrosHow do I use function to effect editing a file?My status line is getting erased, so I can't print function resultHow to make insert mode mapping count as multiple undos?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
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 same.
The point is to be able to press a number, followed by the mapping, e.g. 30<c-x>b
. The problem is, it fails if the number of remaining lines in the file is less than count I input. The function actually don't do any line operations, so I don't care about actual number of lines. How can I make a mapping or a function that accepts count and isn't dependent on number of lines in open file?
key-bindings functions count
add a comment
|
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 same.
The point is to be able to press a number, followed by the mapping, e.g. 30<c-x>b
. The problem is, it fails if the number of remaining lines in the file is less than count I input. The function actually don't do any line operations, so I don't care about actual number of lines. How can I make a mapping or a function that accepts count and isn't dependent on number of lines in open file?
key-bindings functions count
Couldnt you just usev:count
in MyFunction, and not go through the expr hoops?
– D. Ben Knoble
3 hours ago
add a comment
|
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 same.
The point is to be able to press a number, followed by the mapping, e.g. 30<c-x>b
. The problem is, it fails if the number of remaining lines in the file is less than count I input. The function actually don't do any line operations, so I don't care about actual number of lines. How can I make a mapping or a function that accepts count and isn't dependent on number of lines in open file?
key-bindings functions 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 same.
The point is to be able to press a number, followed by the mapping, e.g. 30<c-x>b
. The problem is, it fails if the number of remaining lines in the file is less than count I input. The function actually don't do any line operations, so I don't care about actual number of lines. How can I make a mapping or a function that accepts count and isn't dependent on number of lines in open file?
key-bindings functions count
key-bindings functions count
asked 8 hours ago
ThunderbeefThunderbeef
1901 silver badge8 bronze badges
1901 silver badge8 bronze badges
Couldnt you just usev:count
in MyFunction, and not go through the expr hoops?
– D. Ben Knoble
3 hours ago
add a comment
|
Couldnt you just usev:count
in MyFunction, and not go through the expr hoops?
– D. Ben Knoble
3 hours ago
Couldnt you just use
v:count
in MyFunction, and not go through the expr hoops?– D. Ben Knoble
3 hours ago
Couldnt you just use
v:count
in MyFunction, and not go through the expr hoops?– D. Ben Knoble
3 hours ago
add a comment
|
1 Answer
1
active
oldest
votes
The answer is actually not as complicated as you might think. A trick that I have found very useful in situations similar to this is to remove the <cr>
from the end of your mapping and see what comes up. If I do that and run 30<C-x>b
, this pops up in the command line:
:.,.+29call MyFunction(30)
This is because it's basically like you typed 30:call MyFunction(30)
, and putting a count before :
will always insert a range. (Try it!)
To fix this, you just use <C-u>
to clear the command line before typing in "call MyFunction(30)
"
nnoremap <expr> <c-x>b ":<C-u>call MyFunction(" . v:count . ")<cr>"
From :h c_<C-u>
*c_CTRL-U*
CTRL-U Remove all characters between the cursor position and
the beginning of the line. Previous versions of vim
deleted all characters on the line. If that is the
preferred behavior, add the following to your .vimrc: >
:cnoremap <C-U> <C-E><C-U>
It is worth mentioning that without <C-U>call MyFunction(30)
(unless it hasrange
attribute) will be executed 30 times in a row. So in most cases<C-U>
is a must.
– Matt
8 hours ago
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "599"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f21485%2fmake-mapping-that-accepts-count-independent-of-line-count%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The answer is actually not as complicated as you might think. A trick that I have found very useful in situations similar to this is to remove the <cr>
from the end of your mapping and see what comes up. If I do that and run 30<C-x>b
, this pops up in the command line:
:.,.+29call MyFunction(30)
This is because it's basically like you typed 30:call MyFunction(30)
, and putting a count before :
will always insert a range. (Try it!)
To fix this, you just use <C-u>
to clear the command line before typing in "call MyFunction(30)
"
nnoremap <expr> <c-x>b ":<C-u>call MyFunction(" . v:count . ")<cr>"
From :h c_<C-u>
*c_CTRL-U*
CTRL-U Remove all characters between the cursor position and
the beginning of the line. Previous versions of vim
deleted all characters on the line. If that is the
preferred behavior, add the following to your .vimrc: >
:cnoremap <C-U> <C-E><C-U>
It is worth mentioning that without <C-U>call MyFunction(30)
(unless it hasrange
attribute) will be executed 30 times in a row. So in most cases<C-U>
is a must.
– Matt
8 hours ago
add a comment
|
The answer is actually not as complicated as you might think. A trick that I have found very useful in situations similar to this is to remove the <cr>
from the end of your mapping and see what comes up. If I do that and run 30<C-x>b
, this pops up in the command line:
:.,.+29call MyFunction(30)
This is because it's basically like you typed 30:call MyFunction(30)
, and putting a count before :
will always insert a range. (Try it!)
To fix this, you just use <C-u>
to clear the command line before typing in "call MyFunction(30)
"
nnoremap <expr> <c-x>b ":<C-u>call MyFunction(" . v:count . ")<cr>"
From :h c_<C-u>
*c_CTRL-U*
CTRL-U Remove all characters between the cursor position and
the beginning of the line. Previous versions of vim
deleted all characters on the line. If that is the
preferred behavior, add the following to your .vimrc: >
:cnoremap <C-U> <C-E><C-U>
It is worth mentioning that without <C-U>call MyFunction(30)
(unless it hasrange
attribute) will be executed 30 times in a row. So in most cases<C-U>
is a must.
– Matt
8 hours ago
add a comment
|
The answer is actually not as complicated as you might think. A trick that I have found very useful in situations similar to this is to remove the <cr>
from the end of your mapping and see what comes up. If I do that and run 30<C-x>b
, this pops up in the command line:
:.,.+29call MyFunction(30)
This is because it's basically like you typed 30:call MyFunction(30)
, and putting a count before :
will always insert a range. (Try it!)
To fix this, you just use <C-u>
to clear the command line before typing in "call MyFunction(30)
"
nnoremap <expr> <c-x>b ":<C-u>call MyFunction(" . v:count . ")<cr>"
From :h c_<C-u>
*c_CTRL-U*
CTRL-U Remove all characters between the cursor position and
the beginning of the line. Previous versions of vim
deleted all characters on the line. If that is the
preferred behavior, add the following to your .vimrc: >
:cnoremap <C-U> <C-E><C-U>
The answer is actually not as complicated as you might think. A trick that I have found very useful in situations similar to this is to remove the <cr>
from the end of your mapping and see what comes up. If I do that and run 30<C-x>b
, this pops up in the command line:
:.,.+29call MyFunction(30)
This is because it's basically like you typed 30:call MyFunction(30)
, and putting a count before :
will always insert a range. (Try it!)
To fix this, you just use <C-u>
to clear the command line before typing in "call MyFunction(30)
"
nnoremap <expr> <c-x>b ":<C-u>call MyFunction(" . v:count . ")<cr>"
From :h c_<C-u>
*c_CTRL-U*
CTRL-U Remove all characters between the cursor position and
the beginning of the line. Previous versions of vim
deleted all characters on the line. If that is the
preferred behavior, add the following to your .vimrc: >
:cnoremap <C-U> <C-E><C-U>
edited 8 hours ago
answered 8 hours ago
DJMcMayhem♦DJMcMayhem
12.1k3 gold badges31 silver badges67 bronze badges
12.1k3 gold badges31 silver badges67 bronze badges
It is worth mentioning that without <C-U>call MyFunction(30)
(unless it hasrange
attribute) will be executed 30 times in a row. So in most cases<C-U>
is a must.
– Matt
8 hours ago
add a comment
|
It is worth mentioning that without <C-U>call MyFunction(30)
(unless it hasrange
attribute) will be executed 30 times in a row. So in most cases<C-U>
is a must.
– Matt
8 hours ago
It is worth mentioning that without <C-U>
call MyFunction(30)
(unless it has range
attribute) will be executed 30 times in a row. So in most cases <C-U>
is a must.– Matt
8 hours ago
It is worth mentioning that without <C-U>
call MyFunction(30)
(unless it has range
attribute) will be executed 30 times in a row. So in most cases <C-U>
is a must.– Matt
8 hours ago
add a comment
|
Thanks for contributing an answer to Vi and Vim Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f21485%2fmake-mapping-that-accepts-count-independent-of-line-count%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Couldnt you just use
v:count
in MyFunction, and not go through the expr hoops?– D. Ben Knoble
3 hours ago