0

I need a productive way of creating an (array) using vim ?

consider this example in ruby :

fruit = ['orange','apple','banana']

is there a way which would made this possible with less keystrokes ?

I need a productive way of creating an (array) using vim ?

consider this example in ruby :

fruit = ['orange','apple','banana']

is there a way which would made this possible with less keystrokes ?

Edit: Thanks to @ebenezer After doing some research I ended up using xptemplate which is a snippet manager for vim. if any one is interested , take a look at the def snippet inside python snippet file. which is demonstrated by the author of the plugin here.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ayed
  • 373
  • 5
  • 17

3 Answers3

3

You may wish to look at Michael Sanders’s snipMate plugin (on vim.org: http://www.vim.org/scripts/script.php?script_id=2540). If it doesn’t already have a suitable snippet, you could, as described in an answer to “How to add new snippets to snipMate in VIM”, define your own snippet, which for the purposes of your example might be done something like

:call MakeSnip(&ft, "arr", "= ['${1}', '${2}']")

and then after entering, for example

def fruit arr

hitting Tab would give you

def fruit = ['', '']

with your cursor placed in the first '', ready to fill out, and with another Tab moving it to the second. You might save this as your own snippet by placing it under ~/.vim/snippets by filetype; for your Ruby example, ~/.vim/snippets/ruby/arr.snippet could contain something like

= ['${1}', '${2}']

and you would then be enabled, when working on a file of the ruby filetype, to use it as described above.

Community
  • 1
  • 1
Ben Klein
  • 1,719
  • 3
  • 18
  • 41
  • would you suggest a snippets for doing that quickly ? – Ayed Oct 12 '13 at 05:18
  • @static I am not familiar with Ruby or with the plugin’s support for it, but have added some examples of how such a snippet could be defined in case the plugin doesn’t already provide one. – Ben Klein Oct 12 '13 at 15:43
2

One way of speeding this up would be to use Tim Pope's surround.vim plugin. It provides a nice insert mode mapping to create pairings of characters via <c-s> or <c-g>s depending on your terminal. Example: <c-s>] would create [] with the cursor between the brackets. You can also use it to create the strings. However surround does a bunch more. I suggest you look at its documentation.

A related plugin also provides a similar function called delimitMate. However I can not comment on it as I do not personally use it.

Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
0

You can do auto completion in insert mode for [] by setting following:

:inoremap [ []<ESC>i

imapollo
  • 387
  • 1
  • 2
  • 16