Townk / vim-autoclose

This plugin for Vim enable an auto-close chars feature for you. For instance if you type an '(', ``autoclose`` will automatically insert a ')' and put the cursor between than.
http://townk.github.com/vim-autoclose/
503 stars 66 forks source link

^H like BS #28

Closed iamFIREcracker closed 12 years ago

iamFIREcracker commented 12 years ago

What about making ^H behave like backspace while in insert mode (i.e. erasing empty pairs)? The following patch should be enough to enable such a feature.

--- .vim/bundle/vim-autoclose/plugin/AutoClose.vim      (revision 367)
+++ .vim/bundle/vim-autoclose/plugin/AutoClose.vim      (working copy)
@@ -428,6 +428,7 @@
 function! s:CreateExtraMaps()
     " Extra mapping
     inoremap <buffer> <silent> <BS>         <C-R>=<SID>Backspace()<CR>
+    inoremap <buffer> <silent> <C-H>        <C-R>=<SID>Backspace()<CR>
     inoremap <buffer> <silent> <Del>        <C-R>=<SID>Delete()<CR>
     if b:AutoCloseExpandSpace
         inoremap <buffer> <silent> <Space>      <C-R>=<SID>Space()<CR>
artm commented 12 years ago

thanks. on its way.

Townk commented 12 years ago

Ok, I though a LOT about this particular one and I'm afraid I'm against it and here is the reason:

I know that < C-H > is the same as < BS > on old terminals or through SSH and I can actually make this "problem" happen as described, but there is a fundamental problem here that we should think about.

Inside Vim < C-H > is not the same as < BS > and we shouldn't treat it as such. < C-H > is a perfectly valid shortcut and other user might already have it mapped to something else. For instance, in my vim configuration when I type < C-H > on insert mode it inserts a { } block on the next line and position the cursor in the middle of it.

So, I'm not sure if this is just me or more people might be affected by this change so I would like to hear from you what you think.

iamFIREcracker commented 12 years ago

What about making it user configurable (opt-in)? That should be a nice trade-off.

artm commented 12 years ago

we could expose Backspace() function (along with some others) so a user could bind whatever they want.

iamFIREcracker commented 12 years ago

+1.

Probably you should change the name of the exposed function into something like AutoCloseBackspace, but in general I love the idea!

Townk commented 12 years ago

Guys, I can use all these arguments in the other way. For instance, if you're having issues with < C-H >, why not put this into your .vimrc:

imap < C-H > < BS >

artm commented 12 years ago

duh :) sounds like solution

Townk commented 12 years ago

Artm, if you're OK with this I'll close this issue and let users configure their maps on vimrc instead of adding more and more configuration to the plugin.

artm commented 12 years ago

sure.

achalddave commented 12 years ago

I was wondering if someone could help me out here. I'm trying to get used to using ^H instead of <BS>, but it's hard to break the habit. Generally, I break these habits by remapping the key I don't want to press with <nop>.

So in this case, I have the following in my .vimrc

inoremap <buffer> <BS> <nop>

However, I want to be able to use ^H the way <BS> works with autoclose. If I do imap ^H <BS>, it will map to <nop>, but if i do inoremap, I can't use the autoclose backspace.

I can't seem to think of any way to get around this. Any ideas? Or is there any chance that you could reconsider making some of the function accessible from .vimrc? I understand that this isn't a common use case, but if it's possible that would be great.

In general, it would be great if users could access some of the functions from vimrc so it's possible to remap the default keys to something else, and then some other keys to do what the default keys did. Currently (as far as I know), there isn't a way to do this.

artm commented 12 years ago

simplest I can think of is if we expose the Backspace as AutoCloseBackspace or something. Then you can map it to ^H yourself