Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add an example for Ruby's block-local variables

  • Loading branch information...
commit 847bc557a94487b99785eca262de1162f5471e8f 1 parent c292e35
@kana authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 doc/smartinput.txt
View
25 doc/smartinput.txt
@@ -421,6 +421,31 @@ CUSTOMIZATION *smartinput-customization*
\ 'syntax': ['Constant', 'Special'],
\ })
<
+ *smartinput-customization-d*
+(D) Example #2: If you often write Ruby script and you want to insert "||"
+ by typing "|" to declare block-local variable easily,
+ add the following lines into your |vimrc|:
+>
+ call smartinput#map_to_trigger('i', '<Bar>', '<Bar>', '<Bar>')
+ call smartinput#define_rule({
+ \ 'at': '\%#',
+ \ 'char': '<Bar>',
+ \ 'input': '<Bar><Bar><Left>',
+ \ 'filetype': ['ruby'],
+ \ })
+<
+ But the above rule is not so useful, because "||" is always inserted and
+ the cursor is moved into the bars, even if you want to write the following
+ idiom: "foo ||= bar". So that it's better to tweak the "at" value to
+ activate the rule if and only if the cursor is just after "{" or "do":
+>
+ call smartinput#define_rule({
+ \ 'at': '\({\|\<do\>\)\s*\%#',
+ \ 'char': '<Bar>',
+ \ 'input': '<Bar><Bar><Left>',
+ \ 'filetype': ['ruby'],
+ \ })
+<
Please sign in to comment.
Something went wrong with that request. Please try again.