1

I am using the AutoClose plugin for vim and I was trying to add my own custom feature which will close my <% with %> but right now when it is closing my cursor is being placed in the middle of the % and > therefore I have to go back with the arrow keys. Does anyone know how to fix this? Right now I have this line in the autoclose.vim file:

let s:charsToClose = {"<% ": " %>", "<%= ": " %>"}

I am using the AutoClose plugin by Thiago Alves found here: http://www.vim.org/scripts/script.php?script_id=2009

trev9065
  • 3,371
  • 4
  • 30
  • 45
  • Which autoclose? There are several and some have identical names. – Andrew Marshall Mar 15 '12 at 19:05
  • @AndrewMarshall http://www.vim.org/scripts/script.php?script_id=2009 – trev9065 Mar 15 '12 at 19:16
  • I think that it's hardcoded to go 1 char to the left (see line 75) but you'd need to go 2 characters to the left. You could add an if-else to see if the replacement pair's right member is made of 2 chars or 1. – romainl Mar 15 '12 at 20:22
  • @romainl I tried messing around with this file by could not get it to move two lines back, do you know how to do this? – trev9065 Mar 16 '12 at 21:19

1 Answers1

0

This is a bit rough but it works here.

After adding your pairs to

let s:charsToClose = {'(': ')', '{': '}', '[': ']', '"': '"', "'": "'","<% ": " %>", "<%= ": " %>"}

Change line 75 from:

let l:result .= s:charsToClose[a:char] . "\<Left>"

to:

if len(a:char) > 1
    let l:result .= s:charsToClose[a:char] . "\<Left>\<Left>\<left>"
else
    let l:result .= s:charsToClose[a:char] . "\<Left>"
endif
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Maybe to `let l:result.=s:charsToClose[a:char].repeat("\", len(split(a:char, '\v.@=')))`? – ZyX Mar 17 '12 at 09:40
  • BTW, [latest development version](https://github.com/Townk/vim-autoclose) does not have `s:charsToClose` variable at all and script page of referenced script describes `g:AutoClosePairs`. Plugin does have another error when using `g:AutoClosePairs` with same contents though. – ZyX Mar 17 '12 at 09:43