The Power of C

Seasoned Vim vets will tell you to stay out of Insert mode as much as possible. It's hard to master, but will make your edits more resilient to mistakes and more reusable with repeats.

To reach this goal you need to master entering and exiting Insert mode. One command that makes entering Insert mode better is the change command, which you can issue by pressing c. It accepts a motion, so you can change a word under the cursor cw, or even change up to a specific character (cfx where x is the character). The power lies in your understanding of motions.

Like d there are shortcuts: cc deletes the current line and starts Insert mode. I often C which deletes from the cursor position to the end of the line. This is great for editing copy and pasted lists.

Read More →

Switch Settings with VimSwitch

VimSwitch (GitHub: priomsrb/vimswitch, License: GPL) is a Python program that can change Vim's settings based on a GitHub repository. That means you can switch to a totally different setup like this:

./vimswitch amix/vimrc

Why would you want to do that? I'd probably use it to try out someone else's vimrc from GitHub, particularly if I wanted to write about a set of dotfiles that's suddenly getting hundreds of stars on GitHub. It may also be useful if you regularly ssh into new servers, or Vagrant virtual machines.

Read More →

cVim: Vim for Chrome

cVim

cVim (GitHub: 1995eaton / chromium-vim, License: MIT) by Jake Eaton is a Chrome extension that makes Chrome behave like Vim. There are other Vim for Chrome extensions, but I found this one really easy to learn. It's possibly more idiomatic than the others that I've tried.

Typing :o has a cool history search open prompt, which supports ! (new tab) and * (pin tab). Pressing f shows quick open link hints that are alphabetical rather than numerical. Like Vim, F is different to f -- in cVim it causes links to open in a new window.

Read More →

Stop the Tab Madness

If you've switched to Vim from a GUI tab-based editor like TextMate or Sublime Text, then you've probably learned how to use Vim's tabs. However, Vim's version of tabs are different, and to really take advantage of them involves properly learning buffers and split windows.

In Vim Tab Madness. Buffers vs Tabs, Josh Davis points out how he uses Vim's buffers, windows, and tabs. He shows you how to disable tabs until you learn how to use windows and buffers, and he's got some mappings for using buffers more efficiently.

Thinking back to when I started using Vim as my main editor, I struggled to understand how buffers should be used. It seemed weird that every file ever opened gets added to the buffer list, and switching between buffers seems less instant than the keyboard shortcuts in a GUI editor.

Read More →

Script Roundup: smartpairs, ftcolor.vim

smartpairs

smartpairs (GitHub: gorkunov / smartpairs.vim, License: wtfpl) by Alexander Gorkunov is a plugin for visually selecting ranges based on brackets or quotes, without needing to type the brackets or quotes. So rather than vi{ you can type viv -- the last v will cause the plugin to search for the pair of the symbol under the cursor. It's a nice tweak to the existing behaviour that seems easy to learn.

Alexander also sent in smartgf.vim. This is a method definition search plugin designed for Ruby. Once the cursor is over a method name you should be able to type gf to search for related methods. The results are obtained using The Silver Searcher, and each entry has a number so you can quickly jump to the corresponding file and location.

ftcolor.vim

ftcolor.vim (GitHub: caglartoklu / ftcolor.vim, License: BSD 2-clause) by Caglar Toklu is a handy plugin for switching colour scheme based on language. That means you could have a totally different scheme for JavaScript or Lisp code, for example.

Read More →

No Vim Stack Exchange

It turns out there won't be a Vim Stack Exchange (see my previous post).

We recently launched an Emacs site, and the Vi/Vim community quickly followed to have a site of their own. The show of support here was nothing short of amazing. It weighed heavily in our evaluation of this site, but we ultimately decide not to split off Vi/Vim from Stack Overflow and the other communities that support this subject.

A comparison between Emacs and Vi/Vim is inevitable. It's a good question, and we talked about this a lot. We were on the fence about creating the Emacs site in the first place, but the argument that there was an ecosystem of questions not suitable to Stack Overflow won over by the narrowest of margins.

Read More →

Writing Vim Syntax Plugins

Keith Smiley at thoughtbot published a detailed about writing syntax plugins. He's been adding support for Swift to Vim, and has written up all of the steps you need to make Vim support a new language: file type detection (ftdetect), Vim script execution based on file type (ftplugin), syntax highlighting, and indentation.

Swift's syntax is relatively simple, but there are still some pretty gnarly syntax region lines. Keith also had to write a function to correctly handle Swift indentation, which is invoked by setlocal indentexpr.

Read More →

Save to Evernote Using Geeknote

vim-geeknote

If you're an Evernote fan who prefers writing in Vim, then you may like Geeknote (GitHub: VitaliyRodnenko / geeknote). It's an open source command-line client that supports notes, notebooks, tags, search, and sync.

You can edit the synced files with Vim, but there's also vim-geeknote (GitHub: neilagabriel / vim-geeknote, License: Vim) by Neil Gabriel. This plugin shows your notebooks in a split view, and notes are displayed as plain text. Geeknote supports Markdown, so you can edit notes with styling as well.

Read More →

Changing Case

If you've ever been editing a file then noticed everything has somehow been made lowercase, then read on for a likely explanation. Vim has a rich set of Normal mode commands for changing or deleting text. The ones I'm going to talk about can be found under simple-change in the manual. In particular, the gu commands.

If you type gu{motion}, Vim will make the text that is covered by the motion lowercase. For example, guw will lowercase a word, and gu$ will lowercase the rest of the line. You can also use guu to make the current line lowercase, and {Visual}u to make the visual selection lowercase.

This is probably the cause of many editing mistakes: u feels a lot like undo, and it's easy to forget whether or not a visual selection has been made. I find myself hitting gu{motion} with a movement command as well, and I don't always spot it in time.

Read More →