Loading ...
Sorry, an error occurred while loading the content.

Abbreviations Tips

Expand Messages
  • zzapper
    Hi, The Vim abbreviation feature is very useful. Unfortunately when you have a lot it gets tricky to remember what you called them. solutions:- a) list them
    Message 1 of 10 , Sep 27, 2007
    • 0 Attachment
      Hi,

      The Vim abbreviation feature is very useful. Unfortunately when you
      have a lot it gets tricky to remember what you called them.

      solutions:-
      a) list them

      :ab (all)
      :iab (insert)
      :cab (command)

      b) filter

      :ab php (list all your abs beginning php???)

      eg


      i phpvv echo "<hr><pre>";var_dump(<C-R>a);exit("debug
      line:".__LINE__);
      i phpv echo "<hr><pre>";var_dump($a);exit("debug
      line:".__LINE__);
      i phps <!-- Start Content --><CR><?php echo $page_content; ?
      ><CR><!-- End Content -->
      i phpt <?= $x ?>
      i phpp <?php <CR>echo $page_content;<CR>?>
      i phpinc include ("inc/functions.php");
      i phpstr if (strlen($var)>2)<CR>{<CR>}<CR>else<CR>{<CR>}<CR>
      i phpif if ($a=='2')<CR>{<CR>}<CR>else<CR>{<CR>}<CR>
      i phpcif $c=($v==1)?'yes':'no';
      i phpf2 for($i=1;$i<=10;$i++)
      i phpf1 foreach($keywords as $key => $value)<CR>{ echo "\n
      $key = $value"; }
      i phpc switch($HTTP_HOST)<CR>{ case "1": case "b": $a=1;
      $b="E";break;<CR>default: $a=2;$b="EE";break;}
      i phpbb exit("<hr>Debug <C-R>a line:".__LINE__);
      i phpb exit("<hr>Debug line:".__LINE__);
      i phpr return <<<__HTML__<CR><CR>__HTML__;<Up>
      i phpe $content.=<<<__HTML__<CR><CR>__HTML__;<CR>
      i phpz <?php<CR>echo <<<__HTML__<CR><CR>__HTML__;<CR>?>

      2) Expanding an abbreviation with ESC
      The common way to expand an abbreviation is by typing a space, this
      space is often a nuisance so use ESC instead

      Any more abbreviation tips?

      --
      zzapper
      Best of VimTips
      http://www.vim.org/tips/tip.php?tip_id=305


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tim Chase
      ... You can use motions in your abbreviations (though implied by some of your examples, I find it worth including as a separate item), such as ... which moves
      Message 2 of 10 , Sep 27, 2007
      • 0 Attachment
        > solutions:-
        > a) list them
        > b) filter
        >
        > 2) Expanding an abbreviation with ESC
        > The common way to expand an abbreviation is by typing a space, this
        > space is often a nuisance so use ESC instead
        >
        > Any more abbreviation tips?

        You can use motions in your abbreviations (though implied by some
        of your examples, I find it worth including as a separate item),
        such as

        :iab f long_function_name()<left>

        which moves the cursor into the parens so you can start typing
        parameters. It also happens to put a space in the parens when
        expanded, so I stumbled across

        :iab f long_function_name()<left><c-o>

        which slurps up (or prevents) the odd space.

        -tim



        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... To expand the abbreviation without inserting a space and without going back to Normal mode (which is what does), use Ctrl-] Or if there is no Ctrl-]
        Message 3 of 10 , Sep 27, 2007
        • 0 Attachment
          Tim Chase wrote:
          >> solutions:-
          >> a) list them
          >> b) filter
          >>
          >> 2) Expanding an abbreviation with ESC
          >> The common way to expand an abbreviation is by typing a space, this
          >> space is often a nuisance so use ESC instead
          >>
          >> Any more abbreviation tips?
          >
          > You can use motions in your abbreviations (though implied by some
          > of your examples, I find it worth including as a separate item),
          > such as
          >
          > :iab f long_function_name()<left>
          >
          > which moves the cursor into the parens so you can start typing
          > parameters. It also happens to put a space in the parens when
          > expanded, so I stumbled across
          >
          > :iab f long_function_name()<left><c-o>
          >
          > which slurps up (or prevents) the odd space.
          >
          > -tim

          To expand the abbreviation without inserting a space and without going back to
          Normal mode (which is what <Esc> does), use Ctrl-]

          Or if there is no Ctrl-] on your keyboard, you can either use a mapping with
          <C-]> as its {rhs} (but it won't work on ":noreabbrev"), or use a space
          followed by a backspace.

          Note: I just found out that my fr_BE keyboard can generate Ctrl-] but only if
          I hit AltGr, Ctrl and $ at the same time.


          Best regards,
          Tony.
          --
          hundred-and-one symptoms of being an internet addict:
          25. You believe nothing looks sexier than a man in boxer shorts illuminated
          only by a 17" inch svga monitor.

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • thomas
          Instead of prefixing all abbreviations with php you could use buffer- local abbreviations defined in a ftplugin.
          Message 4 of 10 , Sep 27, 2007
          • 0 Attachment
            Instead of prefixing all abbreviations with php you could use buffer-
            local abbreviations defined in a ftplugin.


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Tim Chase
            ... helpful. Thanks! ... If you re gonna succumb to such contortions, you might as well use Emacs ;-) -tim
            Message 5 of 10 , Sep 27, 2007
            • 0 Attachment
              > To expand the abbreviation without inserting a space and
              > without going back to Normal mode (which is what <Esc> does),
              > use Ctrl-]

              helpful. Thanks!

              > Note: I just found out that my fr_BE keyboard can generate
              > Ctrl-] but only if I hit AltGr, Ctrl and $ at the same time.

              If you're gonna succumb to such contortions, you might as well
              use Emacs ;-)

              -tim




              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Tony Mechelynck
              ... right on the row which starts with AZERTY); but I ll use the two methods you snipped: I just added two lines to my vimrc: F9: terminate abbreviation map!
              Message 6 of 10 , Sep 27, 2007
              • 0 Attachment
                Tim Chase wrote:
                >> To expand the abbreviation without inserting a space and
                >> without going back to Normal mode (which is what <Esc> does),
                >> use Ctrl-]
                >
                > helpful. Thanks!
                >
                >> Note: I just found out that my fr_BE keyboard can generate
                >> Ctrl-] but only if I hit AltGr, Ctrl and $ at the same time.
                >
                > If you're gonna succumb to such contortions, you might as well
                > use Emacs ;-)
                >
                > -tim

                :-) At least the're all accessible by the right hand ($ being the key at far
                right on the row which starts with AZERTY); but I'll use the two methods you
                snipped: I just added two lines to my vimrc:

                " F9: terminate abbreviation
                map! <F9> <C-]>

                (I haven't tested it yet); if or when it doesn't work, I'll use <Space><BS>



                Best regards,
                Tony.
                --
                If you think the problem is bad now, just wait until we've solved it.
                -- Arthur Kasspe

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • BartlebyScrivener
                ... Hey, that s great. That extra space has bugged me for a year or so. I make headings with H= blah blah and had iab hh H= for an abbreviation. Where
                Message 7 of 10 , Sep 30, 2007
                • 0 Attachment
                  > It also happens to put a space in the parens when
                  > expanded, so I stumbled across
                  >
                  > :iab f long_function_name()<left><c-o>

                  Hey, that's great. That extra space has bugged me for a year or so. I
                  make headings with H="blah blah" and had
                  iab hh H=""<Left> for an abbreviation.

                  Where did you stumble across that solution?

                  rd


                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Tim Chase
                  ... Experimenting. I have no idea if it s a documented feature, or if I m abusing a bug. :) I would suggest that Tony s recommendation to use control+] to
                  Message 8 of 10 , Sep 30, 2007
                  • 0 Attachment
                    >> It also happens to put a space in the parens when
                    >> expanded, so I stumbled across
                    >>
                    >> :iab f long_function_name()<left><c-o>
                    >
                    > Where did you stumble across that solution?

                    Experimenting. I have no idea if it's a documented feature, or
                    if I'm abusing a bug. :)

                    I would suggest that Tony's recommendation to use control+] to
                    expand the abbreviation instead of using <space> is a better
                    solution. I'm trying to get into my muscle memory, though I must
                    confess that I don't make great use of abbreviations, usually
                    just when I really tire of typing the same thing time and again.

                    -tim




                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • A.Politz
                    ... The docu suggests this solution to the problem in :h abbreviations You can even do more complicated things. For example, to consume the space typed
                    Message 9 of 10 , Sep 30, 2007
                    • 0 Attachment
                      Tim Chase wrote:

                      >>>It also happens to put a space in the parens when
                      >>>expanded, so I stumbled across
                      >>>
                      >>> :iab f long_function_name()<left><c-o>
                      >>>
                      >>>
                      >>Where did you stumble across that solution?
                      >>
                      >>
                      >
                      >Experimenting. I have no idea if it's a documented feature, or
                      >if I'm abusing a bug. :)
                      >
                      >I would suggest that Tony's recommendation to use control+] to
                      >expand the abbreviation instead of using <space> is a better
                      >solution. I'm trying to get into my muscle memory, though I must
                      >confess that I don't make great use of abbreviations, usually
                      >just when I really tire of typing the same thing time and again.
                      >
                      >-tim
                      >
                      >
                      >
                      >
                      >>
                      >
                      >
                      The docu suggests this solution to the problem in ':h abbreviations'

                      "You can even do more complicated things. For example,
                      to consume the space typed after an abbreviation:
                      func Eatchar(pat)
                      let c = nr2char(getchar(0))
                      return (c =~ a:pat) ? '' : c
                      endfunc
                      iabbr <silent> if if ()<Left><C-R>=Eatchar('\s')<CR>"

                      This was the first vim-function that I have ever sourced and executed.

                      -ap


                      --
                      Ich hab geträumt, der Krieg wär vorbei.


                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • Hari Krishna Dara
                      ... You should also know about Bram s popular suggested Eat Char solution that allows you to use as usual for expanding the abbreviation and still
                      Message 10 of 10 , Oct 1, 2007
                      • 0 Attachment
                        On Mon, 1 Oct 2007 at 2:12am, BartlebyScrivener wrote:

                        >
                        >> It also happens to put a space in the parens when
                        >> expanded, so I stumbled across
                        >>
                        >> :iab f long_function_name()<left><c-o>
                        >
                        > Hey, that's great. That extra space has bugged me for a year or so. I
                        > make headings with H="blah blah" and had
                        > iab hh H=""<Left> for an abbreviation.
                        >
                        > Where did you stumble across that solution?

                        You should also know about Bram's popular suggested "Eat Char" solution
                        that allows you to use <Space> as usual for expanding the abbreviation
                        and still ignore it from getting inserted into the expansion. Here is
                        the solution that I use (change the argument to ' ' instead of '\s' to
                        make it more restrictive):

                        " Eats character if it matches the given pattern.
                        "
                        " Originally,
                        " From: Benji Fisher <fisherbb@...>
                        " Date: Mon, 25 Mar 2002 15:05:14 -0500
                        "
                        " Based on Bram's idea of eating a character while type <Space> to expand an
                        " abbreviation. This solves the problem with abbreviations, where we are
                        " left with an extra space after the expansion.
                        " Ex:
                        " inoreabbr \stdout\ System.out.println("");<Left><Left><Left><C-R>=EatChar('\s')<CR>
                        function! EatChar(pat)
                        let c = nr2char(getchar())
                        return (c =~ a:pat) ? '' : c
                        endfun

                        --
                        HTH,
                        Hari

                        >
                        > rd
                        >
                        >
                        > >
                        >

                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_use" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      Your message has been successfully submitted and would be delivered to recipients shortly.