dirkrob's blog

dirkrob's picture

Vim Tip #5: Calling Perl for math help!

I often run into a situations where I need to do simple numerical calculations on large blocks of text. Or, I would just like to do a calculation and have the result added to the file I'm working on. One way to deal with these situations is to process them with Perl.

"I don't know Perl", you might be saying. Well, if you have used search/replace in Vim, you know more Perl than you think. And the template below is easy to modify for common situations.

dirkrob's picture

Vim Tip #4: The "less" macro - vim > less > more

The "less" text file viewer is great for vi users. But wouldn't is be great if it had syntax highlighting too? With vim's "less" macro, it can.

Search commands with less are identical to vi. Also, most of the vi movement commands are built in, with a few extra shortcuts, like:

gg - Begining of file
G - end of file
ctrl-g - file info
99% - go to 99th percent of file
f / ctrl-f - forward one screen
b / ctrl-b - back one screen
u / ctrl-u - forward 1/2 screen
d / ctrl-d - backward 1/2 screen

dirkrob's picture

Vim Tip #3: the X11 clipboard and other registers

Getting Vim to work with the X11 clipboard can be a struggle, at least when you like to run Vim in a terminal. gvim, the GTK2 version of vim, always has clipboard support. But, if you like to use Vim from a terminal like I do, you will have to check for X11-clipboard support.

From the console, type:
% vim --version

dirkrob's picture

Vim Tip #2: Mutliple windows and vimdiff

Using multiple windows in VIM is a great way to do side-by-side editing, comparison and cut-and-paste (yank-and-put). Unlike other editors, you can do all this with your hands on home row. Learning to use multiple windows will also help you make better use of the built in :help, and also makes it easy to learn a powerful file comparison tool: vimdiff.

dirkrob's picture

VIM Tip: Visual Blocks

You could read VIM's built in help page:
:help ctrl-v

But I will skip to the good parts:

Syndicate content