looking for neat timesaving Vi tricks!

looking for neat timesaving Vi tricks!

Post by SetUpNam » Sat, 07 Feb 1998 04:00:00



I'm looking for neat macros and abbreviations to make editing C and C++
source faster. I'm also after cool stuff that escapes to the shell and
invokes some of the standard utilities to manipulate the file you're
editing.

I've got some good macros myself and would like to exchange my .exrc with
any other people who want to edit faster, so we can all spend less time
infront of a workstation and more time doing other things.

 
 
 

looking for neat timesaving Vi tricks!

Post by Sitaram Chamar » Sun, 08 Feb 1998 04:00:00



>I'm looking for neat macros and abbreviations to make editing C and C++
>source faster. I'm also after cool stuff that escapes to the shell and
>invokes some of the standard utilities to manipulate the file you're
>editing.

>I've got some good macros myself and would like to exchange my .exrc with
>any other people who want to edit faster, so we can all spend less time
>infront of a workstation and more time doing other things.

Trick #1: ditch plain old Vi and start using VIM :-)

Some of my fav features of VIM (ask me for details if I'm being too cryptic):

  - keyword completion: its no longer a pain to use nice long variable names
    that modern programming seems to expect.  Type a name like
    "KeyReleaseMask" once, and every time afterward, just type "Key" and hit
    Ctrl-P.
  - automatic searching of include files when needed.
  - remembering names and line/col position of last 10 files edited
  - permanent bookmarks (use uppercase) - excellent for when you are
    constantly re-visiting the same few spots when debugging a module or
    something
  - autocommands that get executed when you open certain types of files, or
    enter and leave windows for certain files
  - multiple windows editing single/multiple files
  - filename completion, point and shoot editing of filenames.  For instance,
    you can take the cursor to the filename on this line:
            #include <X11/X.h>
    and hit "gf" to start editing that file instead.  Or "Ctrl-W" and "f" to
    start editing it in a split window...

As of VIM 5...

  - syntax highlighting based on language.  Over 60 languages supported and
    counting.  Has saved me debugging time already, just by setting the colors
    in an intuitive way...
  - embeded Perl support (on Unix only, I think...)

There are more.  These are just the ones I have managed to think of in a few
minutes.

If you are thinking about "neat timesaving tricks" and "make editing faster",
you really owe it to yourself to try VIM.  Feel free to email if you need more
info or help.

Sitaram.

 
 
 

1. YANVT: yet another neat vi trick

I tend to write and rewrite a lot of shell scripts. It is
not uncommon for me to have one shell script invoke another.
This can be a nuiscance for finding the one you really want
to edit when fixing bugs/adding new ones. Recently I have
come across a solution that works nicely.

Shell scripts running in sh or ksh treat ':' as an
internally implemented /bin/true. This means that it
ignores all of its arguments. vi uses ':' as the start
of an ex command, and does not care about whitespace after
the colon. In this way I can keep ex commands permanantly
embedded in shell scripts without causing execution
problems. In particular I can do this:

        . $DIRECTORY/shell-script
        : e ~/directory/shell-script

If I want to go off and look at the subscript, I can just
yank the colon line into a register and execute it. I
usually do this with a macro:

        " Yank the current line into register y and execute it

It can also be useful for storing complex substitutions near
places they are useful, eg this one from my ksh environment
file for converting csh-isms to ksh-isms:

        : %s/^setenv \(.[^ <tab>]*\)[ <tab>]*/export \1=/

Ain't vi grand?

Elijah
------
from the guy who brought you #!/bin/vi and the vi sig virus

2. GATED for Linux

3. "Mary had a neat program...neat program...neat program...

4. activating LCD display

5. Neat trick for C-shell Icons

6. Hard disk problem

7. I will now perform a neat trick

8. bash Q: +/- in output of 'jobs'?

9. Stupid cat tricks - Anyone have other tricks?

10. Looking for a email "trick"

11. looking for 2.5.1 tricks...

12. Looking for developers editor (vi with color context)

13. Looking for Linux application to run USR Sportster VI modem