JuanPablo
JuanPablo

Reputation: 24774

vim iabbrev S to self

in python is frequently I use self. string.
I think in a vim iabbrev similar to this

ia S self.

but for use this is necesary

S<space><bs>var

for get

self.var

how I can implement this idea ?
and only work when the S is the first char of word

Upvotes: 1

Views: 552

Answers (3)

sehe
sehe

Reputation: 393613

Edit I found problems with my first response (e.g. when typing print(s.someprop) it wouldn't expand, since abbr. of s. is a so-called non-id abbreviation).

Even simpler would be:

iabbrev S self

In that case, you would only have to apply a trick to type a lone S: SC-v...

Upvotes: 1

david
david

Reputation: 6129

You can trigger the replacement for the abbreviation by hitting the space, but as you're aware it will insert a space after the replacement text.

You can also trigger the replacement by hitting Ctrl-] which will not insert a space.

There's also a function described in the help that you can define and include in your abbreviation that will eat the added space when using space to trigger the replacement.

Type :help abbreviation

Then /eatchar

Upvotes: 2

romainl
romainl

Reputation: 196789

The answer is in :help abbreviations: hit <C-]> instead of <Space> to do the expansion without inserting a <Space>.

Did you consider using a snippet-completion plugin like Snipmate or SnippetsEmu?

Upvotes: 2

Related Questions