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


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 →

Project Specific Settings with Vim

When I started using Vim for my day job -- beyond server config editing and quick text file notes -- one thing I struggled with was the project management side of things. Visualising projects and quickly navigating files seemed more painful than some of the IDEs that I'd grown used to, so I was constantly trying different project management plugins in Vim.

If you work on several projects at any one time, then it can be nice to have project-specific settings. This might be something as simple as different code formatting styles, but it could be more complex build system configuration as well.

In Project Specific Settings with Vim, Adrien Giboire writes about using .exrc files. You have to set exrc to make this work, and it comes with caveats -- if someone commits an .exrc with malicious commands then you could be in trouble. Adrien explains all of this and also how he uses it with real projects.

Read More →

Script Roundup: vim-line-jump


I like plugins for plugins, and I noticed something interesting in vim-line-jump (GitHub: rargo / vim-line-jump) -- you can specify mappings based on the current buffer with an autocmd. That means you can add NERDTree-specific mappings with something like this:

autocmd BufEnter NERD_tree_\d\+ nnoremap <buffer> <nowait> <silent> f <ESC>:silent! call LineJumpSelectForward()<cr>

The rest of the examples are for NERDTree and Tagbar so you can navigate between files more easily.

Read More →

Design by Typing

I got asked about my three preferred web development tools, and I really wanted to answer with simply "Vim". The reason I like Vim for HTML is things like cit ("change inner tag"), ci" (change inner quote), and the visual selection and manipulation possibilities created by these motions.

Coincidentally I ran into Design by Typing, a site dedicated to screencasts for Vim and modern web development. It includes examples for things like responsive layouts, SVG, and publishing with npm.

The responsive photo grid example shows the author navigating and editing HTML with motions that you might find useful if you find the idea of working with HTML in Vim difficult.

Read More →

Get the Vim Stack Exchange Started

There's an Area 51 proposal to get a vi/Vim Stack Exchange site going. The way this works is enough people have to commit to use it. Right now it's 45% complete with 91 people who are committed.

I read a discussion about whether Vim questions belong elsewhere, but due to the volume of Vim questions across Stack Overflow I think it's a reasonable proposal.

People already find a huge wealth of Vim advice on Stack Overflow -- I still find discussions about the "you don't grok vi" post, so a more vi/Vim focused community would be very interesting.

Read More →

Script Roundup: vim-lambdify


Some languages make heavy use of lambdas to the point that you may like to fold them. vim-lambdify (GitHub: calebsmith / vim-lambdify) by Caleb Smith is a plugin that conceals lambdas and inline functions with a lambda character.

It supports Python, JavaScript, and Scheme. It works by replace text for display, but not when the file is saved:

Plugins such as vim-haskellConceal and vim-cute-python use this to replace many different things with more pithy/mathy symbols. The approach taken here is to replace only lambdas, but to do so for many different languages to avoid having to use many plugins for a single feature.

Read More →

Ex Mode

Apparently, NeoVim may be removing Ex mode. The NeoVim developers have found supporting Ex mode adds extra code that they'd like to remove.

Why would you care about Ex mode (:help Ex-mode)? It's basically a mode that allows you to enter several : commands, with some slight caveats. To leave Ex mode you have to type :visual. To enter it, you type Q, which some people hit accidentally and consider an annoyance.

Scripts sometimes use Ex mode, and plugin authors occasionally use it to try out snippets of Vim script. Many people use Vim for years without using it at all, and some even remap Q.

Read More →

Writing to External Commands

I like to use Vim as a general place to manipulate text. Sometimes that means I paste text into an unsaved buffer, pipe it through a Unix command, and then further manipulate the buffer in Vim before finally yanking it and pasting it to another program.

One tool that makes this process easier is :w !cmd, where cmd, is a Unix command. For example, :w !wc will pipe the current buffer to the standard input of wc, giving me a neat character, word, and line count.

This works with unsaved buffers, which is perfect for quickly editing pasted text from a document or web page.

Read More →