Every now and then I dig up a
bash tutorial
and learn a few new tricks. The fc built-in caught my eye this time. fc allows you to edit the last command in a traditional text editor. When you quit the editor, the contents of the buffer are evaluated by the shell.
fc is really useful for debugging long pipelines or long ruby operations performed from the command line. The default editor can be customized by changing the FCEDIT variable. I tried making vim the default, but with all my plugins, it loads too slowly. I ended up doing the following:
export FCEDIT="vim --noplugin"
I also figured out how to yank back in deleted strings. You can insert the most recently deleted string by hitting C-y. I learned a couple of neat history tricks as well. If you type !* in a command line sequence, it will replace it with all but the first word of the last command entered. !$ will be replaced with just the last word of the last command, making it the equivelent of the C-. shortcut.
While I was poking through the documentation, I took the time to learn the readline config file format. I configured M-h to perform the history-search-backward operation, which is like cycling back through the history, but only using lines that start the same way the current line does. Check out some of the other spiffy readline commands you can bind to shortcuts.
Tags: shell, bash, vim
Posted on 2005-04-04
Yesterday, I sent a message to the Vim development mailing list. I've been using GVim to manually edit the contents of a stream mid-pipeline:
cat testfile | sed '/[0-9]:\|=/d' | awk '{print $2 ", " $1}' |\
sort | cat -n | gvim -V0 - | grep -v "Vim:" | sed 's/1/*/' > test
Unfortunately, Vim emits a message when it reads from stdin, so I have to use grep -v to pull the notification out of the output stream after closing GVim. Bram responded with an explanation and some suggestions. I'll finally be able to fix the problem by making the message go to stderr. Piping through Vim will be less of a hassle now.
Tags: shell, vim
Posted on 2005-03-23
I've been following the Vim development mailing list since early January in order to help me keep up with progress on Vim 7. On Friday, somebody mentioned the Vimshell patch in a message about integrated debugging support.
I'd never heard of Vimshell before, but I decided to investigate. One of Vim's major failings is that it can't run an ansi capable shell inside of a buffer. There are some relatively kludgy interactive shell buffer implementations that utilize scripting languages, but none of them are really very useful. I used to have one that uses Python. It doesnt do Ansi, it doesnt do vt100, it doesnt support tab completion, and it has a lot of other issues. Vimshell is different. Implemented in C, it provides complete support for almost all standard shell features. With Vimshell, it's possible to run an entire Vim session inside of a single Vim buffer. It's really a very impressive patch. Unfortunately, it too has some limitations. At the present time, it does not work with Gvim, and it doesnt allow you to use Vim normal mode key shortcuts inside of shell buffers.
My experiments with Vimshell were all quite succesful. I hade some compilation issues at first, because AAP doesn't like patches that add new files. When I dumped the AAP build and grabbed a normal tarball, I was able to patch and build without any errors. All of my tests were successful and impressive: I was able to run ssh, ftp, Vim, top, bash, and even emacs flawlessly in individual vim buffers.
Tags: vim, programming, shell
Posted on 2005-02-27
There are a number of frustrating bugs in the Ruby interface for Vim that make it
difficult to utilize effectively. Deleted buffers are still accessible to the Ruby
interface, and are still counted by the Buffer count class method. Additionally,
changes to displayed but inactive buffers are not refreshed appropriately.
I have managed to fix the deleted buffer problem in the buffer access method and
in the buffer count method. I have also managed to fix the problems with screen
refresh for append and delete operations. There are probably other situations in
which the the refresh is not done correctly, but I havent found them yet.
In addition to my various bug fixes, I have written an extension to the interface
in native ruby that can be loaded at run-time in a vimrc file. Using my new Ruby
interface extensions, I've managed to port my PyRun tools to Ruby, and make some
nice improvements to them.
I plan on documenting my new Vim extensions at the moot eventually, but for now,
if you are interested you can get the code from the cixar web site. To add my
bugfixes to Ruby interface, get
my if_ruby.c file
and replace the one in your code base with it, and then recompile Vim. Then,
you can download
my native ruby interface extension
and put it somewhere in your .vim directory. Then you just have to add a line
in your vimrc file to include it.
Tags: ruby, programming, vim
Posted on 2005-01-11