Skip to main content
Share Your Experience: Take the 2024 Developer Survey
13 votes
Accepted

How to allow count *before* my custom operator?

You can call a function transparently within a mapping, thus circumventing mode changes (e.g. by pressing :) or losing counts, by using <expr> mappings, similar to what you suggested. Just use ...
Antony's user avatar
  • 2,580
6 votes

Is there a way to make the `r` operator accept a motion?

Like romainl said, the easiest way to that is with visual mode. However, if you absolutely want this to be an operator, you can define you own with operatorfunc. From :help opfunc ...
DJMcMayhem's user avatar
  • 17.7k
5 votes
Accepted

Create a mapping that works whilst searching

You can use :cnoremap, which works for search / but also for Ex commands, that you enter with :. See :help :map-modes for more information on the map modes available. (To be exact, there are a few ...
filbranden's user avatar
  • 28.9k
5 votes
Accepted

Modify `iskeyword` for keyword-local completion only

I wrote my own solution by creating a parameter-expansion text object, something I'd been meaning to do for a while anyway. I include the full code at the very end, which I place in ~/.vim/autoload/sh....
D. Ben Knoble's user avatar
  • 26.4k
5 votes
Accepted

How to pass v:register to custom operator when working on custom text object?

Consider if you were doing some operation in visual mode for deleting in a word, you would use the following to put the deletion in register a. viw"ad -> v [iw] ["a] d ...
Mass's user avatar
  • 14.1k
4 votes
Accepted

Problem mapping operator

If you look at example in documentation for g@, you can notice that your function is missing handling of a linewise selection. ip motion apparently acts as a linewise in this case and if you handle it ...
xaizek's user avatar
  • 1,788
4 votes
Accepted

Why does `<Bar>` behave like `|` in the `:command` command in Vim?

So I went digging for this one and as far as I can tell this behavior has been present ever since the user-defined command feature was introduced in Vim 5.2. Initially I thought this was present ...
filbranden's user avatar
  • 28.9k
3 votes
Accepted

Problem remapping § to esc in vim on a macbook with touch-bar

TL;DR: To prevent conflicts with mapping the § key and the auto-pairs plug-in, add the following to your vimrc: let g:AutoPairsMoveCharacter = '()[]{}"' The root of the problem is that Vim sees the §...
filbranden's user avatar
  • 28.9k
3 votes
Accepted

Abort an operating pending mapping

This works for me: :function! Foo() call feedkeys("\<esc>") return :endfunction This works since you can hit esc in operator pending mode (for example, c<esc>), and it will not ...
DJMcMayhem's user avatar
  • 17.7k
3 votes

overwrite motion-wiseness of operator pending mode

@christian had referred a very useful link to me, which already provided a solution in the future release of vim. Specifically: mode(1) will return "no" " for operator-pending "nov" " ...
doraemon's user avatar
  • 1,667
2 votes

Operator pending mode remaps not working

Well, gg is a full command by itself, so operator mode is not involved here at all. It's not like the first g is a command and then the second g is an operator. The g-something family of commands ...
filbranden's user avatar
  • 28.9k
2 votes

change inner backslashed quotes

This could be implemented using: https://github.com/kana/vim-textobj-user Lots of existing plugins are close to this behavior, but none seems to answer the question yet.
Charles Gueunet's user avatar
2 votes
Accepted

how to accept count for visual block ctrl+a remap?

You can use v:vcount1 with a map expression. xnoremap <expr> <c-a> "\<esc>'<V'>".v:count1."\<c-a>" The key is to escape visual mode then apply the count only to the <...
Peter Rincker's user avatar
2 votes
Accepted

onoremap: defining a bounded region

Have you looked at Quick search, limited to a C++ function all the techniques presented in this discussion shall apply to your question. I'm not sure my solution is checking the cursor is within a ...
Luc Hermitte's user avatar
  • 17.4k
2 votes
Accepted

Can't exit buffer using leader mapping - 'cannot make changes'

The problem is with the = in your command. It's being taken as part of the expansion for the mapping. That's triggering the = command, which typically reformats a block of code. Since you have a ...
filbranden's user avatar
  • 28.9k
2 votes
Accepted

Map <C-J> to <Space> in all possible modes

If you look at :h f you'll see |:lmap| mappings apply to {char} (as in f{char}) Go to :h mapmode-l: ":lmap" defines a mapping that applies to: ...<snip>... - the argument of ...
B Layer's user avatar
  • 19.9k
2 votes

Numpad characters don't work in keybindings mappings (but work in general)

If I understand your question right, you are working in a terminal. Vim can't change the font size in a terminal. What you see, when pressing Ctrl-+ and Ctrl-- is a functionality of the terminal. ...
Ralf's user avatar
  • 9,247
2 votes
Accepted

How to prevent cursor shift when using <C-O>{delete cmd} at the end of a line?

All you need to do is insert <C-\> before the <C-o>. inoremap <C-_> <C-\><C-o>dB Help for i_CTRL-\_CTRL-O says: CTRL-\ CTRL-O : like CTRL-O but don't move the cursor ...
B Layer's user avatar
  • 19.9k
2 votes
Accepted

How to test whether the cursor is at the end of a line in a mapping?

Try this instead: col('.') >= col('$') - 1 col('$') returns the number of the bytes in the cursor line plus one. Unless you have 'virtualedit' set, the cursor will never be in that position. (I'm ...
Rich's user avatar
  • 32.1k
2 votes
Accepted

How to ignore or silence errors in operator-pending mappings?

One option would be not to include the h in the mapping if you're on the first column: onoremap <expr> a$ col('.') == 1 ? "f$" : ":<C-U>normal! hEF$v,<CR>" N.B. I'm not 100% clear ...
Rich's user avatar
  • 32.1k
2 votes

Can I allow additional arguments in an operatorfunc?

operatorfunc is very limited and can't take arguments or be set to e.g., lambdas. A "standard" way to handle this situation is to use an expression map to a setup wrapper function, and keep ...
Mass's user avatar
  • 14.1k
2 votes
Accepted

Auto pairing using strings instead of characters

Since you're looking at pairing open/close tags across multiple lines (enclosing a block) and in your case it makes sense to insert the closing tag when breaking the line, my suggestion is to add a ...
filbranden's user avatar
  • 28.9k
2 votes
Accepted

How to map <Plug>MarkdownPreviewToggle

Use nmap instead of nnoremap for <Plug> mappings: nmap mk <Plug>MarkdownPreviewToggle The <Plug> mappings are defined by plug-ins, so you need to be able to expand other mappings in ...
filbranden's user avatar
  • 28.9k
2 votes
Accepted

using EasyAlign in a function

You can also try :normal command: :normal gAip*& And then @: to repeat last command. Or if you want to map it: nmap <buffer> gT gAip*&
Maxim Kim's user avatar
  • 13.5k
2 votes
Accepted

What is the purpose to use "==#" with empty string?

:help maparg() explains that maparg('<C-L>', 'n') will return the normal mode mapping assigned to control-L. When there is no mapping for <C-L>, then it will return an empty string...so it'...
Chris Heithoff's user avatar
2 votes
Accepted

Opfunc inserts text before cursor position sometimes

{ is called "exclusive motion". There is topic in help about that. Cf. pressing "w" moves cursor onto the first letter of next word, but pressing "dw" deletes until it. ...
Matt's user avatar
  • 20.8k
2 votes
Accepted

Unmap error in filetype autocommand

The mapping are by default global (valid for all the buffers). If you unmap it you unmap it globally and the next time you try to do so Vim will complains that the mapping is not existing. I would ...
Vivian De Smedt's user avatar
1 vote
Accepted

Bind a specific search to a map in normal mode

When I try your mapping for <C-/> nothing happens for me either. I've also had my own issues when I wanted to use <A-/> as well. As @b-layer and @filbranden pointed out, there are certain ...
Vee's user avatar
  • 338
1 vote

Bind a specific search to a map in normal mode

Rather than rolling your own mappings for this purpose, I'd recommend adopting the excellent vim-unimpaired plug-in, which defined two specific mappings for this purpose: [n Go to ...
filbranden's user avatar
  • 28.9k
1 vote

Problem remapping § to esc in vim on a macbook with touch-bar

So thanks to @filbranden I was able to find the source of the error. This plugin causes it: https://github.com/jiangmiao/auto-pairs I have yet no clue how the error is produced. The plugin should not ...
Mr.Sh4nnon's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible