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

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.


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


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

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

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


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


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.


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