14
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 ...
12
votes
Accepted
vi (an old AIX vi, not vim): map: I can search, move, yank, or dd, but cannot paste
I checked the traditional ex-vi. The source is available on github as well, you can find the problem in ex_cmdsub.c. So it has exactly the same issue and throws an
Cannot put inside global/macro
when ...
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
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 ...
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
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 ...
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
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" " ...
3
votes
Correctly escaping <CR>: how can I map a command to send the literal string "<CR>" to a vim function?
You should extract the whole RHS of your mapping into a function that you call from the mapping:
function! MyFunc()
call term_sendkeys(term_list()[0], "python models.py -m something\<CR>...
3
votes
Correctly escaping <CR>: how can I map a command to send the literal string "<CR>" to a vim function?
@Heptite found a solution in the comments: I can escape < to <lt>.
:nnoremap <F4> :call term_sendkeys(term_list()[0], "python models.py -m something\<lt>CR>")<CR&...
3
votes
Correctly escaping <CR>: how can I map a command to send the literal string "<CR>" to a vim function?
<CR> is nothing but byte #13, so it can be written as \r or \x0d like in a normal C string.
Likewise, <NL> is the same as \n. Other keys can be passed unescaped, so they will get ...
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
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
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
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
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
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
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 ...
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
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.
...
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 ...
1
vote
Accepted
Meta-Model: Shrinking In Correct Direction
Thanks to D. Ben Knoble and filbranden I came to my desired solution!
I very much appreciate your answer.
I associated the keys with the wrong action - Instead of "moving the window" to a ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
map-operator × 43key-bindings × 19
vimscript × 9
cursor-motions × 5
custom-text-object × 4
insert-mode × 3
functions × 3
escape × 3
count × 3
command-line × 2
visual-mode × 2
error × 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
terminal × 1
autocmd × 1
substitute × 1
cursor-movement × 1