VIM "d%" (delete to matching brace/paren) behavior change - vim

I recently did a new install of VIM 8.2.2825 on Windows. The behavior of <operator>%, such as d% or c% appears to have changed, compared to how I have used those commands for many years. These operations are now "exclusive", meaning they do not include the final paren or brace in the text that you want to delete or change.
The documentation still claims that the <op>% operation is inclusive. (see the beginning of section 9 (various motions) in :help motion.txt). But that's not happening. If the cursor is on the left paren and I type d%, it now deletes everything before the right paren, but not the right paren. It should include deleting the right paren.
I searched quite a while looking for anything related to the inclusivity / exclusivity of the d% operation, with no luck. Apologies if I missed something.
I'm wondering if this really is a change in VIM behavior (in which case the documentation seems to be wrong), or if perhaps there is some .vimrc setting that I now need, that wasn't needed before.
TIA.

You're probably using :h matchit standard plugin that re-maps %. In fact, it does not necessarily make the motion exclusive, it just uses Visual mode that depends on your :h 'selection' setting.
Just don't load it if you don't like it.

Related

Figuring out why keybinding is not working in vim

I installed SpaceVim to test it out and ; (semicolon) is not working. :nmap ; says "No mapping found". The thing is I could not find where it is unmapped in the source. Are there different ways to re/un-map a key in vim and how should I go about finding those in general?
There seems to be some confusion here about the difference between the « standard » vim functionality and the effects of a mapping.
Note: One of the reasons I prefer a customized regular vim is that it forced me to learn real vim and its philosophy, then to build tools on top of that. This may be the purist in me, but distros like SpaceVim make it remarkably hard to see what’s going on under the hood when you need them to do something different, whereas vim is ready-made for that. I write this because I suspect those who start with SpaceVim do not read :help and therefore lack a complete grasp of the fundamentals.
Standard vim keys are not mappings. n to jump to next search match, J to join, q to record a macro, ; to repeat the last fFtT—all are implemented in the source. Changing their default behavior would require an edit and recompile. This is why :normal! ; works no matter what—it ignores mappings and uses the source definition.
So, to answer your question, :map ; says there is no mapping because there is no mapping.
Note: I assume SpaceVim does not map ; because I could not find documentation that it did.
Of course, one can always create mappings shadowing this behavior, but it’s considered an anti-pattern to do so (esp. without at least having another sequence to do the old behavior). The reasoning goes that the original is actually considered useful, so why override it?
Note: from my glance at SpaceVim’s keybindings, SV does this a lot. They remapped q, which created macros, requiring me to type 2 extra characters to access one of my favorite—and one of the most awesome—features!

Vim8 cannot delete letters

I installed a vim 8.1 on the cluster I am using in my home folder. I also installed a number of plugins including YouCompleteMe. I then made an alias so that I can open the vim easier.
However, I found that my vim cannot delete letters very well. When I am writing I can delete what I just typed. But if I move the cursor to other places, then it cannot delete letters at all, unless I type in something at first.
I am using a Scientific Linux system developed by the Fermi Lab.
How can I solve this problem?
Thanks
This sounds like the default configuration of the :help 'backspace' option. If this doesn't contain start, you cannot remove characters over the start of insertion by pressing Backspace, only what got inserted before. Removal of characters via the x or d commands (:help deleting) should always work - anywhere. Else, you have a serious misconfiguration should inspect your ~/.vimrc and re-add plugins one by one.
If you're new to Vim (and using backspace for deletion in insert mode is a typical approach of people used to other, modeless editors), you should spend 30 minutes on the vimtutor that comes with it (see :help vimtutor). Then, there are several good resources, cheatsheets, and vi / Vim tutorials out there on the net. http://vimcasts.org/ has several short entertaining episodes that go beyond the basics.
Your problem could be fixed by putting
set backspace=indent,eol,start
into your ~/.vimrc. Also have a look at :help defaults.vim; by including that instead, you'll get other goodies and recommended settings as well! (The reason for the odd defaults is backwards compatibility.)

Pair completion in Vim

I do my coding in Vim and recently have been getting more annoyed by its pair completion features. I don't really see the need for pair completion in general as I tend to naturally try to close pairs myself (by pair here I mean type the closing ')' of a set of parentheses, for example). What really annoys me is when I have text already written and to surround it by quotes for example I'll be at the beginning of the word, type ' and then two will pop up right over there rather than just 1 and then me pivoting to the end of the word and typing the other exclamation point. Anyways, that's it for my rant, so any help on stopping my vim from doing this would be appreciated. I use spfvim-13 (https://github.com/spf13/spf13-vim) and have only modified the .vimrc slightly. I wasn't able to pinpoint exactly from where this specific issue arises.
This is not a native vim behavior, it's definitely some plugin causing it. I can't pin-point a particular plugin that spf13 might be having for this, I looked for popular ones I know, like simple_pairs, delimitMate etc.
Best way to investigate what's causing is to just see the output of :verbose imap ' and you'll come to know where it's being set and then remove that plugin / setting.

Vim langmap breaks plugin (bépo)

I am using a bépo keymap (http://bepo.fr) and seeking the perfect vim mapping.
So far I used a long list of noremap, but for many binding (for exemple, the motion aw or Ctrl+r), the first keystroke is well remaped but not the others, I reckon it's the expected behaviour, but then this is not what I need.
Ideally I would have my keyboard totally remaped in a higher level (before the map commands) except when typing text (in insertion mode and when typing a substitution for exemple). What I'm looking for seems to be langmap, but I have problems using it.
I added this langmap to my .vimrc, It seems perfect but it broke some of my plugins. SuperTab now insert <Plug>SuperTabForward when pressing Tab in insertion mode, I have t<SNR>24_SelectCompletion(1) when pressing enter.
Does someone know how to fix this langmap issue or a better way to remap my keyboard?
This is a known bug, that has been discussed before. I have made a patch (see the thread starting here) and hopefully Bram will include this change soon.
Update 11/05/2014
This has been fixed by patch 7.4.502. Use the langnoremap option to fix this.

Is there a way to emulate ReSharper's "extend selection" feature in Vim?

ReSharper has a nice feature called "extend selection": by pressing CTRL+W (I think this is the default) repeatedly, you select more and more from your current caret location. First it's a word, then more and more words, a line, inner then outer block of lines (for example an if-block), then a function, etc...
Basically, by pressing the key combination repeatedly, you can end up selecting the entire file. I'm sure at least some of you will be familiar with it.
I have just started learning all the intricacies of vim and I don't have enough experience to see how something like this could be implemented in Vim (although I assume it's possible). So my question is meant for Vim gurus out there: can this be done and how?
Update: a bit of a background story. I've been talking to my ex-boss about all the benefits of Vim, and he thinks it's all great. His only question/problem was: does it have "extend selection"? My question so far has been no. So, if someone knows the answer, I'll finally win a discussion :P (and maybe create a new Vim convert:-))
I had a quick go at this problem. It doesn't work as is. Feel Free to make edits and post on the vim wiki or as a plugin if you get it refined.
chances are you'd want to make a g:resharp_list for each language (eg. one for paranthesised languages, etc.)
All that is needed is a marker for the original cursor position :he markers and a timeout autocommand that resets the index.
"resharp emulator
"TODO this needs a marker
"also c-w is bad mapping as it has a lag with all the other-
"window mappings
"
let g:resharp_index = 0
let g:resharp_select = ['iw', 'is', 'ip', 'ggVG']
func! ResharpSelect()
if g:resharp_index >= len (g:resharp_select)
let g:resharp_index = 0
endif
exe "norm \<esc>v" . g:resharp_select[g:resharp_index]
let g:resharp_index = g:resharp_index + 1
endfun
nnoremap <c-w> :call ResharpSelect()<cr>
vnoremap <c-w> :call ResharpSelect()<cr>
"Something to reset on timeout. TODO this doesn't work
au CursorHold :let g:resharp_index = 0<cr>
The answer is yes. Once in Visual mode you can use all the regular navigation methods as well as some extra ones.
Some of my favourites? First hit v while in normal mode to get to visual mode then hit:
iw - to select the inner word. Great for selecting a word while excluding surrounding braces or quotes
w - hit multiple times to keep selecting each subsequent word.
b - select wordwise backwords
^ - select all from current position to beginning of text on line
$ - select all from current position to end of line
I'm sure others here could add to this list as well. Oh and don't forget Visual Block mode C-v try it out in vim with the above commands it works in two dimensions :-)
If you're talking about Vim (and you should be :-), you can start marking text with the v command, then you have all the standard cursor movement commands (and, as you know, there are a lot of them) which will extend the selection, as well as moving the cursor.
Then you just do whatever you want with the selected text.
See here for the gory details.
One would need to write a function that would save the current selection, then try increasingly wide selections, until the new selection exceeds the saved one or selects all text. Some possible selections are:
viW - select word
vis - select sentence
vip - select paragraph
viB - select text within the innermost brackets
v2iB - select text within the next most innermost brackets
ggVG - select all text
I think Jeremy Wall's heading in the right direction. And to get a little further in that direction, you might look at the "surround.vim" script from Tim Pope. A good description is available on github. Or, if you'd rather, get it from vim.org. It'll probably help you do some of the things you'd like to do, though it doesn't seem to have a feature for say, simply selecting within a tag. Let me know if I'm wrong.
Ultimately, what you'd really like is a hierarchy of enclosing text-objects. You should read up on text-objects if you haven't. A nice overview is here. Note that you can grab multiple objects in one go using counts, or do this iteratively (try vawasap}}} from normal mode).
You can also get scripts which define other text-objects, like this one that uses indentation to define a text-object. It'll work for many languages if you're formatting according to common standards, and guaranteed for python.
One annoyance is that the cursor ends up at the end of the visual block, so, for example, you can't easily select everything between some ()'s, then get the function name that precedes them...
...BUT, I just found in this post that you can change this behavior with o. Cool!
I suspect you'll find yourself more efficient being able to skip over intermediate selections in the long run.
Anyway, I'll be curious to see if anyone else comes up with a more general solution as well!
In Rider [on a Mac with VS Mac bindings with IdeaVim], I bind:
Ctrl+= to Extend Selection
Ctrl+- to Shrink Selection
Doesn't clash with any other bindings of consequence and doesn't require a v for mode switching, and easier than Cmd+Option+-> and Cmd+Option+<-
Putting it here as I always hit this question with any Rider Vim selection searches. If I get enough harassment, I'll create a self-answered "How to use Extend Selection with Rider Vim mode".

Resources