Slashdot Mirror


(Useful) Stupid Vim Tricks?

haroldag writes "I thoroughly enjoyed the recent post about Unix tricks, so I ask Slashdot vim users, what's out there? :Sex, :b#, marks, ctags. Any tricks worth sharing?"

6 of 702 comments (clear)

  1. Filter Lines by saberworks · · Score: 4, Interesting

    Use visual mode (shift-v) to highlight lines, then shell out to external programs to filter them, such as perltidy. To do that, with lines highlighted, type !perltidy (assuming you have it on your machine). This lets you filter specific lines instead of the whole file.

  2. Couple off-hand by Reality+Master+101 · · Score: 4, Interesting

    Not horribly exciting ones, but useful:

    xp - reverse next two characters
    dL - Delete to end of page, in other words, everything visible.
    C - Often overlooked: chop off end of line and go into insert mode.

    --
    Sometimes it's best to just let stupid people be stupid.
  3. Re:Replacement by MrKaos · · Score: 3, Interesting

    Also, you can do use "ma" to mark the beginning line, "mb" to mark the ending line, and then:

    :'a,'bs/FROM/TO/g

    And if you add a c (confirm) to the end

    :'a,'bs/FROM/TO/gc

    you will get a Y/N to replace that instance or not, in case you don't want to replace every occurrence. if you search like this :'a,'b g/FINDME/ s/FROM/TO/gc

    vi will ask for confirmation to replace FROM to TO only on line between a and b markers on lines with the string FINDME on it.

    :.,$ g/FINDME/p will search from your current cursor position (.) to the end of the document ($) and get /regular expression/ print (i.e grep) inside of vi.

    456G

    go to the 456 line (G for the last line)

    These are a few of my favourite things. Vi plugin for Eclipse and Visual Studio actually makes them have a worthwhile editor, I couldn't imagine not having all the effort I invested into using vi available in some of the "editors" available today.

    --
    My ism, it's full of beliefs.
  4. Re:Just using VIM by Constantine+XVI · · Score: 5, Interesting

    main utility of vi is that I know it's going to be there in any Linux enviroment (and I suspect Unix in general).

    vi is part of the Single UNIX Specification, so anything passing itself off as UNIX must include vi. Even without the spec, it's much, much more universal than emacs, and more powerful than pico/nano.

    --
    "I think an etch-a-sketch with an ethernet port would beat IE7 in web standards compliance."
  5. Re:Just using VIM by Adam+Hazzlebank · · Score: 5, Interesting

    The one I find really useful is .,+20s/foo/bar/g

    Replace all occurrences in the next 20 lines from the current line only. Great when your editing code and you've realised you used the wrong variable name in that method for example.

  6. Re:Just using VIM by petard · · Score: 3, Interesting

    Sigh. I'm sure I'm not the only one here... I distinctly remember purchasing my first 9600bps modem. (A real Hayes, no less! I sent them a large manilla SASE and they shipped me the AT command manual for no charge.) I spent a few months mowing every lawn I could to raise the funds for it. Exactly a week after I got it installed and found a couple local BBSes I could connect to at 9600, Hayes shipped the very first 14400bps modem.

    Apart from the nature and amount of labor involved in raising funds, that's been a pattern for so many equipment purchases since. That was the very first time I bought something so close to the release of the new shiny, though :-)

    --
    .sig: file not found