Sunday, August 27, 2017

Re: Can I write an abbreviation that only works at the beginning of the line?

On Sun, Aug 27, Jose Caballero wrote:
>Let's say, and this is not my real need but a very clear example, I
>want to write an abbreviation that converts, when writing python code:
>
>class
>
>into
>
>class (object):
>
>But I only want that to works when string "class" is being printed at
>the beginning of a line.
>I don't want the replacement to happen when I am writing the docstring
>like "This is a class that does this and that".
>
>Is it possible?

You can use something like this

iabbrev <expr> class getline('.') ==# 'class' ? 'class (object):' : 'class'

The key moment here is "<expr>". The expression

getline('.') ==# 'class' ? 'class (object):' : 'class'

will be evaluated to obtain replacement string. You can make it more
accurate by comparison only with the part before the cursor position.

-Dmitri

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: