12
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 them to call a function like so:
fun! SetOpFunc()
set opfunc=CountSpaces
return 'g@'
endfun
nno <expr> <F4> SetOpFunc()
This technique isn'...
6
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
*'operatorfunc'* *'opfunc'*
'operatorfunc' 'opfunc' string (default: empty)
global
{not in Vi}
This option specifies a ...
5
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
visual object register operator
Similarly, placing "a in the omap after the operator ix passes it to the opfunc. Either of these ...
5
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 either aw, in case it is used by the delete operator, that is, dw = daw, or iw otherwise, for example cw = ciw.
4
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.vim.
Then, in my ~/.vim/after/ftplugin/sh.vim, I remove the setlocal iskeyword+=$ line. This is the key step, since it allows completion to work again.
I add
...
4
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 as characterwise only first character of the last line is copied (because that's where `] is positioned; do vipv on a paragraph to see it for yourself).
Thus ...
3
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 § key the same as it sees the combination Alt+', or Meta+'.
The § symbol has character code U+00A7.
To represent keystrokes involving the Alt or Meta key, Vim ...
3
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 because a user comand takes its arguments from <...> special sequences, such as <args> or <bang>, which makes it so that it takes <lt> to ...
3
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 more cases where the command-line mappings apply, such as the input() function, or entering an expression for the expression register with <C-R>= from Insert ...
3
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 complete the operator.
3
@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" " for operator-pending forced to characterwise
"noV" " for operator-pending forced to linewise
"no\<c-v>" " for operator-pending forced to ...
2
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 are simply two-character commands.
In order to have ii to map to gg, you actually need:
noremap ii gg
Though you'll probably need to map all the other i-...
2
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
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 <c-a>. command. Simply use . to repeat the command.
If you rather reselect and keep visual block mode then use the following mapping:
xnoremap <expr> ...
2
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 function definition.
To check for improper uses, you have to define a function. There, first record the current line, and then check the first and last line you ...
2
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.
Try it without starting vim.
The plugin you downloaded just changes the guifont.
For this I have the following in my gvimrc:
command! -bar -nargs=0 BiggerFont ...
2
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
That's it. Well except for a caveat or two which I'll reproduce here for your convenience ;) ...
The CTRL-O command sometimes has a side effect: If the cursor ...
2
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 using >= instead of == in case you do have 'virtualedit' set.)
I'm not 100% sure what you mean by these tests, but you can find the documentation for col() ...
2
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 on how you want the mapping to behave if run when the cursor is not between a pair of $ signs. Some tweaks to the above may be necessary.
2
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 space after the =, that's being swallowed as the "motion" for = (which is roughly equivalent to the motion of going right one character.)
I guess this reformatting ...
2
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 the commands that accept a text character, such as "r" and "f"
So lmap <c-j> <space> ... note, though, that you may need to explicitly enable lmap ...
1
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 key combinations that are difficult to map, if not impossible. If you need more mapping key combinations, @b-layer referenced how to set up mapping the Alt key ...
1
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 the previous SCM conflict marker or diff/patch
hunk. Try d[n inside a conflict.
]n Go to the next SCM conflict ...
1
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 care about § characters. Also the § character does not appear a single time in the repository. I actually like the plugin. If I find an alternative my problem ...
1
what worked for me was to use langmap.
set langmap=jklöJKLé;hjlkHJKL
this remaps the keys for all commands
1
The requirements, which were unclear originally, have been updated. Result: much of my original answer is out the window. Here's the new one...
We can't reasonably wedge logic into global commands and/or Normal mode commands so in this case it makes more sense to use a function...to be called from a sub-replace-expression
The function:
func! ProcessYHV(in,...
1
The problem with having a count at the end is Vim will have to wait to see if more keys are going to be pressed. E.g. <c-t>1 might mean you are supplying a count of 1 or maybe it will end up being 14.
The other problem is you have to make all these mappings. So if you want to support a count up to 15, then you need 15 mappings.
Options:
Provide a ...
1
If your desired operator is a motion rather than a text object (i.e., does not need to alter the starting position), and it is exclusive, you can instead use absolute positioning.
function! s:motion()
" ... compute cursor position for motion ...
call cursor(28, 10)
endfunction
onoremap X :<c-u>call <sid>motion()<cr>
Then dvX, dVX and ...
1
It works by using:
call feedkeys("\e")
even if an error message is hard to display in all the cases.
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
map-operator × 31key-bindings × 16
vimscript × 5
cursor-motions × 4
custom-text-object × 4
count × 3
command-line × 2
insert-mode × 2
error × 2
escape × 2
command × 2
object-motions × 2
operator-pending-mode × 2
vimrc × 1
regular-expression × 1
search × 1
cut-copy-paste × 1
buffers × 1
substitute × 1
cursor-movement × 1
visual-mode × 1
replace × 1
functions × 1
cursor × 1
visual-block × 1