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 ...
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
...
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....
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
...
5
votes
Accepted
Define text object that depends on the current operator
The following example comes close to what you are asking for:
onoremap <expr> w '<esc>' . v:operator . v:count1 . (v:operator ==# 'd' ? 'aw' : 'iw')
It creates a textobject w that is ...
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 ...
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 ...
4
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 ...
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 §...
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 ...
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" " ...
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 ...
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.
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 <...
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 ...
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.
...
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
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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*&
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'...
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.
...
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 ...
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 ...
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 ...
1
vote
Accepted
how can i remap <C-w>{number}h to <C-w>{number}j
what worked for me was to use langmap.
set langmap=jklöJKLé;hjlkHJKL
this remaps the keys for all commands
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
map-operator × 41key-bindings × 17
vimscript × 9
cursor-motions × 5
custom-text-object × 4
insert-mode × 3
functions × 3
count × 3
command-line × 2
visual-mode × 2
error × 2
command × 2
escape × 2
keyboard-layout × 2
object-motions × 2
operator-pending-mode × 2
vimrc × 1
neovim × 1
regular-expression × 1
search × 1
buffers × 1
cut-copy-paste × 1
autocmd × 1
substitute × 1
cursor-movement × 1