Scripting Vim with Ruby 2.0.0

Vim supports several dynamic languages for scripting, including Python and Ruby. With the release of Ruby 2, interest in using the latest stable version of Ruby with Vim will start to pick up steam over the coming months. Kohei Suzuki noticed that Vim wouldn't compile with --enable-rubyinterp=dynamic on 64bit platforms with Ruby 2.0.0, so he submitted a patch to the vim_dev group: ruby-dyn-2.0.0.patch.

The patch is fairly short, adding some preprocessor macros for numerical functions. Bram Moolenaar responded so presumably this patch will appear in Vim's source soon.

Read More →

Script Roundup: vim-tmuxify, vim-git-log

Send in your Vim scripts for review through our contact form.

vim-tmuxify

vim-tmuxify (GitHub: mhinz / vim-tmuxify, License: BSD) by Marco Hinz allows tmux to be controlled from within Vim.

Panes can be associated with tmuxify and then manipulated using various commands. For example, <leader>ms will prompt for text and send it to the associated pane. Panes can be created, deleted, cleared, and you can even send the interrupt signal.

vim-git-log

vim-git-log (GitHub: kablamo / vim-git-log) by Eric Johnson is an extension to Fugitive that allows Git's log to be viewed. Almost any argument that can be passed to git log can be used, except --pretty (because presumably the script needs to interpret the output of log).

Read More →

Vim 101: Practicing Motions with Visual Mode

I often find myself using Visual mode purely to figure out the best motion to use for a given task. For example, let's say I'm trying to duplicate the following function's body:

function specialAdd(a, b) {
  if (!a || !b) {
    return 0;
  }
  return a + b;
}

If the cursor was on function and I pressed v/} it would select up to and including the curly bracket that closes the if condition. Pressing n would select the whole function.

The next thing I might try would be the } motion (for moving over a paragraph). Typing v} would select the whole function, which is what I wanted. By using Visual mode I can easily see what the outcome of typing the } motion was. From that point on I can combine } with operators, like y} to yank the function.

Read More →

Script Roundup: vim-scroll-position, interactive-replace

Send in your Vim scripts for review through our contact form.

vim-scroll-position

vim-scroll-position (GitHub: junegunn / vim-scroll-position) by Junegunn Choi is another plugin that uses Vim's sign feature (:help :sign-intro). This one displays the relative position of the cursor, and indicates the latest jump and change positions.

interactive-replace

interactive-replace (GitHub: hwrod / interactive-replace, License: MIT) by Harold Rodriguez adds a new command, :InteractiveReplace, which can be used to interactively substitute search matches.

Harold's documentation includes an example where variables are substituted for various values that stem from a ..

Read More →

Vim 101: Pasting Into Command-line Mode

There are times when you're tempted to lift your hand from the keyboard to the mouse, idly wondering if there's a better way. One such case is taking text from a buffer and placing it into Command-line mode. For example, performing text substitution with %s, or invoking a shell command with :!. Many Vim users will reach for the mouse and use the operating system's copy and paste feature to do this, but there's a quicker way provided by Vim's registers.

The CTRL-R (:help i_CTRL-R) command can insert the contents of a register in Insert or Replace mode. This is known as a "special key" (:help ins-special-keys). The great thing about this shortcut is you can reuse it to put registers into Command-line mode. For example, let's say you've got some text you want to search for in a buffer. First yank the text into a register, and then paste it with CTRL-R:

  • In Normal mode, type "ayw to yank a word
  • Press escape, and then / to search
  • Then press CTRL-R and a to put register a

A shorter way to do this is to use the default register. Typing yw will yank up to the word boundary into the default register, and then typing CTRL-R_" will put it into the command-line. It's worth practicing using this, particularly if you haven't got used to working with registers yet.

Read More →

Tern: Better JavaScript Completion

Tern is an open source JavaScript project designed to run as a server that sends completion results to compatible editors. The author is looking for a "Vim expert" to help finish the Vim plugin. The project has an Indiegogo funding page and quickly met its goal.

"Tern is a piece of software. It dives into the muddy depths of a JavaScript system to locate the information that it was asked for. Combined with an editor plug-in, it can make the life of a JavaScript programmer a lot more pleasant."

The project was created by Marijn Haverbeke and is currently on GitHub, released under the MIT license. The source is based on the Acorn parser.

Read More →

Script Roundup: obsession.vim, vim-multiedit

Send in your Vim scripts for review through our contact form.

obsession.vim

obsession.vim (GitHub: tpope / vim-obsession, License: Vim) by Tim Pope provides some sugar for working with Vim's session files. It automatically calls :mksession before exiting, and whenever the layout changes.

To start using it, type :Obsess with an optional file or path. Session files can then be loaded with vim -S or :source.

vim-multiedit

vim-multiedit (GitHub: hlissner / vim-multiedit, License: MIT) by Henrik Lissner is a plugin for working with multiple selections, based on Felix Riedel's earlier work.

Read More →

Vim 101: Search as a Motion

The search command, /, is actually a motion, which means it can be used with operators. Any operator can be combined with search just by typing the desired search and pressing return.

For example, when in Normal mode, d/,<CR> will delete up to a comma. Although dt, would be more efficient, there are times when a search is more specific and useful than the other motions.

Much like last week's HTML editing with text objects, understanding how this works in terms of Vim's grammar gives you a greater understanding that can improve your productivity. The lesson is simply that / can work as a motion, because motions are just instructions that move the cursor in some way.

Read More →

MacVim File Drawer

Eloy Durán's port of MacVim, complete with a file drawer.

Here's a curious thing: a Mac-friendly file drawer GUI for MacVim. It was made by Eloy Durán, and is available at alloy / macvim on GitHub. To try it out, follow the build instructions on the fork's wiki.

The sidebar itself behaves as you'd expect: it's "global", so it always looks the same even when tabs are in use. It also works correctly in full-screen mode. File system commands like :cd are reflected in the drawer, and switching buffers causes the highlighted file to change.

The General settings panel has options that pertain to the file drawer, so you can change the side which it appears on and make it always open by default.

Read More →