Some vim tips

October 22nd, 2008 by Rohan

svn diff the current windows file

Put this in your vimrc:

map zs :!svn diff % > /tmp/vimsvndiff<CR><CR>
  \ :new<CR>:r /tmp/vimsvndiff<CR>
  \ :set ft=diff<CR>

Say you’re editing a checked out file and what to see what changes you’ve done without leaving your VIM session? Just type zs when in normal mode. This will open the diff in a new split window.

Apply tabs to a block of text

I found myself doing this often. Visual selecting some text and then applying a regex to prepend some spaces (or a tab) to each line

Put this in your vimrc:

map <C-i> :s/^/ / :nohlsearch
map <C-p> :s/^ // :nohlsearch

So Control-i will insert 4 spaces for all lines of the selected text. Control-p will remove 4 spaces. Very handy!

[Post to Twitter] Tweet This Post  [Post to Facebook] Facebook 

3 Responses to “Some vim tips”

  1. Applications Says:

    yo…

    thanks…

  2. Andreas Says:

    For the svn diff, I recommend the vcs plugin. Works with other version control systems, and you even commit from within vim. http://www.vim.org/scripts/script.php?script_id=90

    For prepending text in front of lines, check out the ‘<>’ commands.
    see ‘:help shift-left-right’.

  3. Rohan Says:

    Thanks for that tip on using the ” command.

Leave a Reply




Tweet This Post links powered by Tweet This v1.4.1, a WordPress plugin for Twitter.