Running Tests from Inside Vim

If you're keen on TDD, then leaving your editor to run tests can be annoying. There are lots of options for running tests, however: some people use file watchers to trigger tests when the project's files are modified, and others use test runners from within their IDE or editor. Janko Marohnić sent in test.vim, which is a new plugin for triggering test runners.

Janko wanted features like zero dependencies and configuration, automatically choosing the correct test runner, and a wide range of language/platform support. Lots of Vim test runners are Ruby-focused, which makes sense because the Ruby community is big on testing. However, the exact way in which a single test, test file, or test suite is actually run is highly dependent on each test framework.

The way test.vim works is to associate test runners with strategies. It has to be able to do the right thing for running a test nearest the current line of code (:TestNearest), running the current test file (:TestFile), or running the entire suite (:TestSuite).

Read More →

Script Roundup: En Masse, vim-expand

En Masse

En Masse (GitHub: Wolfy87/vim-enmasse) by Oliver Caldwell is for those of you who like to work with the quickfix list. Given a quickfix list, :EnMasse will open a new buffer that contains each of the lines. You can edit these lines in the same buffer. When you save, each of the relevant files will be updated.

The project includes tests and documentation.


vim-expand (GitHub: Wolfy87/vim-expand), also by Oliver Caldwell, allows text to be expanded based on Visual mode selections. It uses the expand function.

Read More →

The Finer Points of Repeat and Registers

The repeat change command, ., has an interesting side effect when combined with pasting a register: if you type "1p to put register 1, and then press ., you'll see the contents of register 2. You can repeat this up to the ninth register. To understand how this works you need to look at how the registers work.

Register 0 is used for storing the contents of the last yank command. So if you press yy to yank the current line, it will be stored there. Register 1 stores the most recently deleted text, and subsequent deletes cause the contents to be copied from 1 to 2 and so on, up to 9.

If you've gone on a delete frenzy, then you can actually get the text back by repeating a put. Try typing "1p and then pressing . a few times and you should see what I mean. If you combine this with undo then you can cycle through each line: "1p.u.u..

Read More →

Copy and Paste with Clipper

If you're a Mac user and you're using tmux, do you ever have trouble getting the tmux copy buffer to work with the system clipboard? The widely recommended solution is reattach-to-user-space, which you can install with Homebrew. However, this doesn't help when you also work with remote sessions -- I end up pasting content into a buffer, then using scp to copy it into pbcopy on my Mac. Or fudging it with the mouse and formatting the weird whitespace issues.

Greg Hurrell has created clipper, a Mac daemon that runs in the background and allows you to interact with local and remote clipboards. The documentation explains the need for clipper and how it works, and it also has a snippet you can use with Vim. Incidentally, this solution is based on netcat, which seems like a clever way of keeping the project relatively simple.

The source code is Go, and it's pretty short and readable. The network traffic is over the local loopback interface and SSH, so it does mean that people on your local machine can connect to your clipper instance:

Read More →

Improved Asterisk Motions

vim-asterisk (GitHub: haya14busa/vim-asterisk, License: MIT) by haya14busa aims to improve the * motion. The * motion itself searches forward for the word nearest the cursor, so it's quite useful once you get used to it.

However, vim-asterisk allows you to search within visual selections and it uses smartcase by default which seems more natural to me.

haya14busa notes that the visual search feature is based on vim-visualstar.

Read More →

Alternative Windows Builds

There's a really useful resource on r/vim about alternative Vim builds for Windows. The official Vim homepage doesn't list all the builds that users would like, and this includes 64-bit and extra language bindings.

Some of the suggested links include builds with Perl, Python 2 and 3, Ruby, Lua, and TCL, so if you're having trouble getting plugins working in your version of Vim for Windows then you might want to try these out.

Read More →

Highlight the Current Line

I've used cursorline for so long I can't even remember when I added it to my .vimrc. It highlights the current line so you can see the cursor more easily. The highlight is restricted to the current buffer, so it's easy to see in a collection of split windows as well.

The exact settings I use for my dark background theme are as follows:

set cursorline
hi cursorline cterm=none term=none
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
highlight CursorLine guibg=#303000 ctermbg=234

This also only highlights the line in the current window, which I found works well in GUI Vim, although I don't usually use gVim/MacVim.

Read More →

Run Tests with vim-testkey

Micah Geisel sent in vim-testkey, a script for quickly running tests. You can press <Enter> or <Space> in a test file to run the tests, and the same shortcut will trigger a save and rerun in non-test files.

It comes with built-in support for Cucumber and Mocha, but you can add your own test runner settings as well. You can also change the key mapping with let g:TestKey.

If you're a TDD practitioner then this might reduce the amount of times you switch to another terminal and press up/return. I use a file watch-based solution, but vim-testkey might be more efficient for large projects.

Read More →


I write a lot of Markdown, and my usual workflow is to write in Vim and then use a tool to generate the corresponding HTML. Livedown by Hrvoje Šimić generates a live preview by using a small Node program to watch for file changes. It updates the preview document with WebSockets, so there's no slow page refresh when you make small changes.

You can install the Node application with npm install -g livedown, and there are separate plugins for Vim, Emacs, and Sublime. The Vim plugin is available at GitHub: shime/vim-livedown. It has some options: you can make it automatically open a web browser preview whenever a Markdown file is opened, and change the port the web server uses.

I found this project through Hacker News (Show HN: Livedown), so if you've got any comments it might be a good idea to post them there.

Read More →