Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Learn vi/vim in 50 lines and 15 minutes

by dragonchild (Archbishop)
on Mar 04, 2004 at 01:14 UTC ( #333748=note: print w/ replies, xml ) Need Help??


in reply to Learn vi/vim in 50 lines and 15 minutes

You forgot a number of very important commands and distinctions:

  1. vi's regex language is very different than Perl's. It's much more akin to the shell command grep's. Specifically, there is no + and you only have back-references.
  2. Aliases:
    • Colon Mode:
      • :x is :wq
      • :NN moves you to the NNth line. :$ moves you to the bottom of the file.
      • :!asdf executes asdf in the shell.
      • :map X asdfasdf will map the key X to the key sequence asdfasdf. These are macros, to be used in Nav Mode. My favorites are:
        • v - :!perl -wc %^V^M (That's Ctrl-V, Ctrl-M.) - compile the current file in Perl.
        • V - :!%^V^M - Execute the current file.
        • q - :e #^V^M - Switch you to the last buffer. (Read up if you want to know what these are.)
    • Nav Mode
      • 0 is ^
      • z-z moves the screen to center on your line. z-Enter moves the screen so that your line is on the top. (There's on that does it for the bottom, but I never remember it.)
      • o inserts a new line below where you are and puts you in Insert Mode at the beginning of it. O does it for above.
      • w goes the beginning of the next word. b to the prior. e to the end of the current word.
      • J takes the next line and puts it at the end of the current line.

The reason to use vi is that, once you understand it, it's is extremely efficient to edit in. I found that my productivity in sheer editing is almost as fast as I think. (Which, granted, isn't that fast, but still!)

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


Comment on Re: Learn vi/vim in 50 lines and 15 minutes
Re: Re: Learn vi/vim in 50 lines and 15 minutes
by thelenm (Vicar) on Mar 04, 2004 at 01:31 UTC

    Good post... a minor nit, though. You can use + in Vim regexes, but you have to precede it with a backslash. Vim regexes and Perl regexes are not the same (knowing when to use backslashes often throws me off), but I think they're much more similar than they are different.

    -- Mike

    --
    XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
    -- grantm, perldoc XML::Simpler

      OK so I lied (it was just a little one!) It really uses the abortive GNU regex syntax that is just different enough from Perl to s!+t you if you really know perl REs.....it is like grep. My usual greps are called re and re! linked into /usr/bin. They look like:

      [root@devel3 root]# cat /usr/bin/re #!/usr/bin/perl die "Usage re [RE]\nFull Perl grep on STDIN\n" unless @ARGV == 1; my $re = qr/$ARGV[0]/; while(<STDIN>) { print if m/$re/; } [root@devel3 root]# cat /usr/bin/re! #!/usr/bin/perl die "Usage re [RE]\nFull Perl grep on STDIN\n" unless @ARGV == 1; my $re = qr/$ARGV[0]/; while(<STDIN>) { print if ! m/$re/; } [root@devel3 root]# cat some.file | re "some perl re"

      cheers

      tachyon

Re: Re: Learn vi/vim in 50 lines and 15 minutes
by tachyon (Chancellor) on Mar 04, 2004 at 02:28 UTC

    Sure there are shortcuts. Only had 50 lines!. All good points. :NN is 4 strokes as is NNgg. :$ is 3 strokes but G is only two.

    cheers

    tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://333748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-12-20 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls