Saturday, August 26, 2017

Re: Sorry to use the `e' word but does vim have similar to cperl

On 26/08/2017 03:30, Harry Putnam wrote:
> Any one here familiar with emacs cperl mode, that can tell me how to
> get something similar when using vim?
>
> If not familiar, `cperl-mode' trys to offer a host of short cuts that insert
> quite a bit of standard code for you... a simple example is; if you
> type `if<spc>' `cperl-mode' inserts:
>
> if (_) {
> }
>
> With the underscore indicating where the cursor is left.
>
> I vaguely remember using something with vim, years ago, that did
> something similar, but no longer remember how to load that sort of
> thing.

If you want to use a built-in feature, you may use abbreviations (`:help
abbreviations`). In the simplest form:

iab <buffer> if if () {<cr>}<c-o>2gE

You may want to put this in ~/.vim/after/ftplugin/perl.vim to make it
filetype-specific.

The above also inserts the space you type after `if`. You most likely
won't wanto that. You may type if<c-]> to expand the snippet without
inserting a space, or use the `Eatchar()` function described in Vim's
help.

If the cases in which you do *not* want `if` to be expanded, you may
type if<c-v><spc> to insert a literal space. Alternatively, give the
snippet a different name, like `if…` (… is <alt>-. in my keyboard).

Enjoy,
Life.


--
--
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:

Post a Comment