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;









1

















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?










share|improve this question


























  • Couldnt you just use v:count in MyFunction, and not go through the expr hoops?

    – D. Ben Knoble
    3 hours ago

















1

















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?










share|improve this question


























  • Couldnt you just use v:count in MyFunction, and not go through the expr hoops?

    – D. Ben Knoble
    3 hours ago













1












1








1








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?










share|improve this question















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






share|improve this question














share|improve this question











share|improve this question




share|improve this question










asked 8 hours ago









ThunderbeefThunderbeef

1901 silver badge8 bronze badges




1901 silver badge8 bronze badges















  • 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
















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










1 Answer
1






active

oldest

votes


















4


















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>





share|improve this answer




























  • 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













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
);



);














draft saved

draft discarded
















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









4


















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>





share|improve this answer




























  • 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
















4


















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>





share|improve this answer




























  • 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














4














4










4









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>





share|improve this answer
















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>






share|improve this answer















share|improve this answer




share|improve this answer








edited 8 hours ago

























answered 8 hours ago









DJMcMayhemDJMcMayhem

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 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

















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



















draft saved

draft discarded















































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.




draft saved


draft discarded














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





















































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









Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單