Friday, September 18, 2009

Resizing with GNU Screen

I know a lot of you use screen frequently. My friend Chris gave me a tip recently related to resizing split windows in a screen session.

In screen, you can do <C-a>:resize [+-]N<CR> to resize a window +/- N lines

This is handy if you've got a cmd running and want to see when it's done. You can split the screen, load it in one window, and resize it to be small; thereby, preventing it from occupying valuable real estate on your monitor.

Screen has a handful of : commands such as :number N to change the numeric position of the current window. Take a look at the DEFAULT KEY BINDINGS section of man(1) screen for the the full list (parenthesized next to each key binding).

For more screen tips, check out the screen extravaganza posted back in 2008.

Mouse Tips

This has been mentioned on the blog in the past, but readers email me about it often enough that it deserves a formal tip. You can use the mouse to resize windows in Vim if you set your mouse as follows.

:set mouse=a

This will even work over a remote ssh session if you also set your term appropriately.

:set term=[the appropriate setting]

Options for term settings are as follows:

in the GUI: "builtin_gui"
on Amiga: "amiga"
on BeOS: "beos-ansi"
on Mac: "mac-ansi"
on MiNT: "vt52"
on MS-DOS: "pcterm"
on OS/2: "os2ansi"
on Unix: "ansi"
on VMS: "ansi"
on Win 32: "win32"

If the mouse setting interferes with your operating system's copy and paste ability such as the select to copy feature under X windows, you can revert to the standard behavior by holding shift while selecting text.

Setting your mouse as described also prevents accidental terminal scrolling with the mouse wheel when editing a file remotely and causes Vim to scroll within the current buffer instead.

Thanks to mmmattos for emailing me and providing the motivation for this tip.

Monday, September 14, 2009

Diffing From Inside Vim

To compare two files without resorting to launching vidiff from the command-line, you can do the following.

1) open one of the two files in a standard buffer
2) type in :vert diffsplit filename

Put the name of the file you'll be comparing in place of filename. Prefixing the command with vert gives you a vertical split. If you'd prefer a horizontal split, simply omit the vert.

Wednesday, July 29, 2009

Types of Registers

There was some mention of the special registers in Vim in the comments on my last post. Here's a list of all available registers in Vim (copied directly from the docs). For more info on what these registers do, please see :help registers.

There are nine types of registers:
1. The unnamed register ""
2. 10 numbered registers "0 to "9
3. The small delete register "-
4. 26 named registers "a to "z or "A to "Z
5. four read-only registers ":, "., "% and "#
6. the expression register "=
7. The selection and drop registers "*, "+ and "~
8. The black hole register "_
9. Last search pattern register "/

Tuesday, July 28, 2009

Insert Register Contents

If you're in insert mode and would like to insert the contents of a given register without going into normal mode, you can hit ctrl-r and then input the desired register. Between typing ctrl-r and the second character, a '"' will be displayed to indicate that you are expected to enter a register.

Friday, June 19, 2009

An Introduction to Clojure's Agents

For anyone that's interested in alternative programming languages, I've written a lengthy introduction to Clojure's agents.

For those unfamiliar with Clojure, it's a modern Lisp running on the JVM with excellent support for concurrency. It allows excellent interoperability with Java, so essentially you get a dynamic and clean programming language with a huge standard library. On the performance front, it's often on par with Java. I've spent a good deal of time learning the language lately, and I have to say that it's very enjoyable to work with.

One huge bonus of working with Clojure inside Vim is the VimClojure project. It allows interactive programming from inside of Vim and proxies code between a stateful NailGun server and the editor. To be honest, I wasn't aware that an interactive REPL was possible inside of Vim until I installed this, and I'm wondering if there are any other projects out there using similar techniques with different languages.

Wednesday, June 17, 2009

Switching from Horizontal to Vertical Split

If you have two windows which are horizontally split, and you'd like to make them vertically split instead, the following command sequence works well:

<ctrl-w>t<ctrl-w>H

To orient them back to a horizontal split do this:

<ctrl-w>t<ctrl-w>K

Note that if the top (or left) window is already current you can omit the <ctrl-w>t and simply do <ctrl-w>H or <ctrl-w>K.