Les Orchard

Roleplaying Editors and Dreams

Archived Comments

  • Two very helpful vim things that really accelerated my vim learning (I never did figure out how to do these in emacs):

    (1) Substitute:

    substitute on the current line:

    :s/search for this/replace with this/

    substitute on all lines:

    :%s/search for this/replace with this/

    find all matches on each line, not just the first one:

    :%s/search for this/replace with this/g

    prompt to confirm each replace:

    :%s/search/replace/gc

    case insensitive

    :%s/search/replace/gi

    :help substitute for more

    (2) Execute commands on matching lines

    :normal command means to execute commands as if you typed them in, eg: 'dd' or 'yyp', etc. With standard {range} operators, you can use :normal to execute a command on every matching line:

    delete every line that contains the word "foo"

    :/foo/normal dd

    I find :normal really useful.

Weekend quick things  Previous Bouncing Browsers Next