mattn / vim-sonictemplate

Easy and high speed coding method
http://mattn.github.com/vim-sonictemplate
333 stars 42 forks source link

How can I set a default value for `{{_input_}}`? #58

Closed Itto1992 closed 2 years ago

Itto1992 commented 2 years ago

English

How can I set a default value for {{_input_}}? In other words, when asked to type {{_input_}}, is there any way to input the default value by just typing enter key?

For example, I made the following snippet for python loop.

for {{_input_:i}} in range(N):

In most cases, I use i as a cursor. However, in some cases, e.g., making a double loop, I want to use another cursor such as j. Thus, I want {{_input_:i}} to fill i by default and want to fill it if I needed. Is there any way to do this? Thank you in advance.

日本語

{{_input_}} オプションを使うにあたってデフォルト値の設定は可能ですか? 例えば、ほとんどのケースではデフォルト値でよいが、特定のケースではカスタマイズした値を入れたいと言った場合に、デフォルト値をエンターキーを押すだけといった簡単な動作で達成できるとうれしいです。

mattn commented 2 years ago

If you don't need to prompt, you can set default value like below.

  let g:sonictemplate_vim_vars = {
  \ 'python': {
  \   'variable_name': 'default value',
  \ },
  \}

If you want the prompt, please try https://github.com/mattn/vim-sonictemplate/pull/59

mattn commented 2 years ago

59 allow to put default value like below

{{_input_:name:default value}}
mattn commented 2 years ago

In your use-case, it should be

for {{_input_:variable_name:ii}} in range(N):
Itto1992 commented 2 years ago

@mattn I just tried #59. This is exactly what I wanted! Thank you for your super quick work!

mattn commented 2 years ago

Thank you