Tag Archives: vim

vim backups using git

I am a vim guy. I’ve been hooked on to it ever since my first introduction to Unix (back in ~1995). One of the things I like about vim is that it is just an editor. Nothing more, nothing less. It does allow for creation of plugins, but only as far as they complement editing tasks. So, although you’ll find vim plugin scripts that provide file browsers, IDE features, encryption etc in vim, you will almost certainly never find an integrated mail client, IRC client, web browser etc (things which are rumoured to exist for a long time in that other editor which shall not be named).

The reason I mention this is because, I recently came across this interesting plugin named VimLocalHistory which maintains a backup of files that you edit in vim using git at every write to the file. Cool, ehe ? btw, git is another really cool tool that I’ve fallen in love with recently but more of that in another post probably.

The second reason for this post is, considering how i have waste^H^H^H^H^Hspent a lot of time creating, maintaining and tweaking my preferred vim configuration and plugins(*), it only makes sense that I share it with friends who share my preferences and style of working but don’t/can’t look for the tools that’ll help them at it . So, here is my vim configuration: http://github.com/lonetwin/lonetvim

Obviously, you’d have to rename dot_vimrc and dot_vim to ~/.vim and ~/.vimrc respectively. The dot_vimrc file is well commented (i think) so reading that and adopting it to suit your needs should not be a problem. Enjoy.

(*) I created the file in 2004, IIRC and have maintained it ever since

Reblog this post [with Zemanta]

vim as a syntax highlighting capable pager

Just thought I’d share what I learned sometime back.

Do you ever wish that you could “cat” a file and have it displayed on the terminal with syntax highlighting ? Well, “cat” is a tool for concatenating files. It does not know (or care) where it is cat-ing to (for that matter, it does not know or care, where it is cat-ing from either)

OTOH, Pagers (like ‘more’ or ‘less’) are tools to view files on the terminal. That said, vim also behaves somewhat like a pager when invoked using the command ‘view’. However, this does not do syntax highlighting, nor does it take input from stdin (ie: executing “cat /some/file | view” does not do what you expect). So what do we do ?

Well, we use a little a vim trick:

  • Look for the file /usr/share/vim/vim<version>/macros/less.sh
  • create an alias for that script:

    $ alias vless='/usr/share/vim/vim/macros/less.sh'

    (you may also save the alias later in ~/.bashrc if you like the way it works)

  • now use vless as you would use less

    $ vless foo.c
    $ cat /some/file | some_filter | vless

Nice huh ?

I <3 vim !

I’ve been a vim user for a long time. I’ve always liked vim, because the modal interface fits my brain and the keybindings, my wrists (which never really liked emacs).

Now, although I have used vim for a long time, I often tend to use a small subset of the power that this awesome editor offers.

I would like to say that this is because “what I know, is all that I need to know”, but the simple truth is it’s because I am too lazy to read the docs.

That said, I *do* sometimes feel the urge to become more productive, which leads me to invest time into really understanding my basic tools (vim, firefox, thunderbird, pidgin, windowmaker, aterm/xterm/rxvt).

Today, I decided it was going to be vim. Here’s what I learned:

  • Since version 7.0, vim has a builtin spell checker (“:help spell”; I was using the vimspell plugin all this while).
  • The ‘-x’ option [1] ! Look it up !
  • vimgrep (“:help vimgrep”)

Since I was so impressed with what I learned today, I’m listing down some of the things that I do know about. Some of these, you might already know, and if you don’t, I think you should.

Note that I’m not explaining any of these. This is more like a quick-n-dirty, see-and-do, reference. So, I’d suggest open up a decently large text file (something with more lines than your window size) and try out what’s listed. If you like what you see, the vim doc is beautiful, just pull out the help topic mentioned to learn more.

Note also that most of these refer to ‘command’ mode, ie: You need to press ‘Esc’ before trying any of these out.

  • visual mode (“:help visual”) – Not spectacular, if you already know about it. If you don’t, do a ‘v’ and move around the text, yank-n-paste, you’ll get the idea.
  • visual-block (“:help visual-block) – Now, this one, I’ve seen a lot of ‘old’ unix guys didn’t know about (which is a bit strange). Anyways, do a ‘Ctrl-v’ and move a couple of characters left/right and then up/down, yank-n-paste, you’ll get the idea …..neat huh ??
  • folding (“:help fold”). In visual mode, select a few lines, do a ‘zf’. To open, do a ‘space’ or ‘zo’ on the fold.
  • Editing an entire block – Using a visual-block, select a set of lines. Now, without pressing Esc, try some editing commands, like type in ‘I’ followed by #. Now, press Esc.
  • Inserting special characters in your search-and-replace patterns: An example is best for this one. Do this:

    Create a file with the contents:
    <HTML><HEAD><TITLE>42</TITLE></HEAD><BODY>The answer is</BODY></HTML>
    Do a ":1,$ s/></>Ctrl-v+Enter</g"

    See what I mean ?

There is so much more, but now I am bored …and I think at least for those who have not invested time in learning vim by reading the docs, at least some of this stuff would be new.

Maybe, I’ll post about vim again later. Till then though, here’s something that you could possibly use — My vim files. Just untar, rename the contents correctly (ie: mv {dot_,.}virc && mv {dot_,.}vim) and copy them to you $HOME. The .vimrc is written from scratch and mostly well commented.

Thanks for reading.

[1] wtf !! …and I’ve been breaking my head over getting an nice, easy to use and small tool for storing sensitive stuff (like account numbers, login/passwords, etc) and was left unsatisfied with all the fancy GUI tools and the CLI one’s I’d have to install separately on each new system)

UPDATE: The default encryption algorithm used for the -x option is breakable. It is the same as that which Pkzip uses (and has documented). So, -x is probably not a good idea for ultra sensitive stuff, but good enough and convenient enough for short lived files which don’t need high level of security. For proper encryption support in vim, I would recommend using Noah Spurrier’s OpenSSL vim plugin. . (Now included in the vim files link above).