Hey,

I attended Damien Conway's 'Mastering Vim' tutorial at OSCON. It was pretty
cool, although you really have to force yourself to use some of the tips and
tricks on a regular basis to get them into memory.

Among the more useful tips [copied from his extensive notes] were -

Preview your search results
===========================
Vim has an option that causes it to show you where you search will match:
        :set incsearch
Looks ahead  as you type the search pattern, and highlights the first match.
Only jumps to that position when you hit <enter>. If you're looking ahead and
hit <esc> instead, it cancels the search and returns to the former position.
Very handy for 'peak-and-return'.

Matching delimeters
===================
To move the matching bracket of a {}, (), or [] pair, use %
By default, vim only matches the above, but you can extend that to whatever
pairs you like
        set matchpairs+=<:>
Even to 'pairs' that aren't normally considered pairs
        set matchpairs+==:;
[Very useful when programming to see what variables assign to]

Keep track of where you were
============================
In normal mode, you can leave a mark at any cursor position. Just type m<char>.
For example,
        mh
Then to go back to that mark, you type a backtick: `<same char>
That is
        `h
Or, to go to the start of the line containing the mark, type a single quote
'<same char>
        'h
If you use a lowercase letter, the mark is per-buffer. If you use an uppercase
letter, the mark is global. You can see all marks you've set by typing
        :marks

Copying delimited objects
=========================
To copy the entire {} block the cursor is in: yab or ya{
To copy the entire [] delimited text the cursor is in: ya[
To copy the entire () delimited text the cursor is in: ya(

Indented pasting
================
To paste lines above or below the current line, but with the same level of 
indenting
        ]P
        ]p


There's lots of other neat tricks like branching, defining tabs or page widths,
abbreviations and maps - it's worth having a look at the extensive help.

        :help
        :help <topic><cr>
        :help <string><tab>
        :helpgrep <pattern>

Within the help, there are a bunch of links, within bars, that you can jump to
using <ctrl>]

My personal ~/.vimrc file contains -

        set textwidth=80
        set softtabstop=4
        set expandtab
        set shiftround

which wraps everything to 80 characters, has tab stops at 4 characters, replaces
any tabs with spaces, and rounds down any tab spacing. Works for me at least ;)


Glynn

Ben Ford wrote:
> I've been having a play with vim too... mostly cos I want to be able to use
> it through ssh on my server at home. Here are some links I've found:
> 
> http://www.moolenaar.net/habits.html
> http://www.vi-improved.org/tutorial.php
> http://www.rayninfo.co.uk/vimtips.html
> http://www.vim.org/scripts/script.php?script_id=182
> http://www.geocities.com/volontir/
> 
> The second one is particularly good! :)
> Ben
> 
> -----Original Message-----
> From: Daryn Hanright [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, 9 August 2006 11:59 a.m.
> To: Canterbury Linux Users Group (CLUG)
> Subject: Brushing up on vim skills
> 
> Got a quiet period at work, so brushing up on my vim skills - its one of
> those incremental learning things I find! Anyway found this neat site:
> http://jmcpherson.org/editing.html
> 
> Nice hints there. Gonna make more use of navigating around in command
> mode, using keys like G (bottom of page), gg (top of page), h, j, k, l and
> particular the combo of j,k
> (up, down) then w, b to go forwards/back a word.
> 
> Also another one I've picked up is commenting out a
> bunch of code. From command mode, go CTRL-V, block text you want to
> comment out, go SHIFT-I, type your comment out syntax depending on what
> language you are using, then press ESC - it put that comment syntax on
> the whole block!
> 
> Anyone else got some vim tips to share?

Reply via email to