help with custom mapping #46

Closed
djtal opened this Issue Apr 6, 2012 · 2 comments

Projects

None yet

2 participants

@djtal
djtal commented Apr 6, 2012

Hi,

I jsut try to add some custom mapping for ruby here what I want to do

# => #{} only inside a string
| => || always

but it didn't work and I can't find a clear exemple of adding customme mapping. Could yuo please help and maybe we can add some sample to the documentation

here waht i add to my vimrc file

smartinput#map_to_trigger('i', '|', "|")

smartinput#define_rule({'at': '\%#', 'char': '#', 'input': "#{}\<Left>" ,'filetype': ['ruby'], 'syntax':['Constant']})
smartinput#define_rule({'at': '\%#', 'char': '|', 'input': "||<Left>" ,'filetype': ['ruby']})
@kana
Owner
kana commented Apr 6, 2012

Thank you for the feedback. How about the following configuration?

call smartinput#map_to_trigger('i', '#', '#', '#')
call smartinput#map_to_trigger('i', '<Bar>', '<Bar>', '<Bar>')

call smartinput#define_rule({'at': '\%#', 'char': '#', 'input': '#{}<Left>', 'filetype': ['ruby'], 'syntax': ['Constant', 'Special']})
call smartinput#define_rule({'at': '\%#', 'char': '<Bar>', 'input': '<Bar><Bar><Left>', 'filetype': ['ruby']})

| has a special meaning in key mappings. So that it should be written in another form <Bar>.

input items in rules are internally passed to :map commands. So that special keys must be written like '<Left>' instead of "\<Left>".

If you edit a Ruby script and the current buffer contains a text 'foo',

  • The opening ' is highlighted as Constant (over Special).
  • Quoted text is highlighted as Constant.
  • The closing ' is highlighted as Special.

So that the syntax item of the former rule must contain also Special.

You can use the following command to check how the character under the cursor is highlighted:

echo map(synstack(line('.'), col('.')), 'synIDattr(synIDtrans(v:val), "name")')

Additionally, | is often used as foo ||= bar, it's better to use the latter rule if the cursor is just after { or do, isn't it?

call smartinput#define_rule({'at': '\({\|\<do\>\)\s*\%#', 'char': '<Bar>', 'input': '<Bar><Bar><Left>', 'filetype': ['ruby']})

Since I wrote vim-smartinput for my personal use, I've never thought that it is used by others. And it's a bit tricky to write rules involving special keys. I'll add more description to the document.

@djtal
djtal commented Apr 6, 2012

Thank you for the quick reply,

I'll try this a soon has I have a little of spare time and tell you if it work.

I see your plugin in thechanglog blog and decide that I should try it.
For the moment it work quit well and do the work.

@kana kana added a commit that closed this issue Apr 7, 2012
@kana Merge branch 'add-tutorial-to-write-rules'
Close gh-46.
db6bec8
@kana kana closed this in db6bec8 Apr 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment