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 →

Script Roundup: VimL Parser, Pry/Vim Integration

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

VimL Parser

VimL Parser (GitHub: ynkdir / vim-vimlparser) by Yukihiro Nakadaira is a Vim Script parser that, given a suitable file, will output a parenthesized Polish prefix notation version of the script. For example, call vimlparser#test('.vimrc') will display a parsed version of your Vim configuration.

The project also includes tests, with examples of the expected output. The source in this plugin is pretty huge, so you might like to check it out if you want to see something extreme in Vim Script.

Pry/Vim Integration

pry for Ruby is a popular IRB replacement. Ryan King has created a script to integrate Vim and pry that has some interesting ideas behind it.

Read More →

Vim 101: Efficient HTML Editing with Text Objects

If you're working with XML or HTML, then the at and it text objects are useful. You can remember at with the mnemonic "a tag block", and it as "inner tag block". The difference is that at includes the tags.

Consider the following example:

<p><a href="http://example.com/1">This is a link</a> and <em>this is an emphasis</em>.
<a href="http://example.com/2">This is another link</a>, which points to another page.</p>

If I position the cursor anywhere inside the <em> tags and type dat, it'll remove the text and tags, because it means "delete a tag block":

Read More →

Understanding 'listchars'

I was searching GitHub to see what weird and wonderful characters people use for their 'listchars' setting. This all started because I was using a Chromebook, and the built-in shell had trouble displaying some of the characters I use for showing invisible characters. Looking at my .vimrc, I realised my 'listchars' setting hadn't been changed in years, and it was probably due a bit of refactoring.

The purpose of the 'list' (:help 'list') setting is to visualise tabs, spaces, and line endings. The 'listchars' setting (:help 'listchars', abbreviation: 'lcs') determines the strings that will be used when list mode is active. It includes just about everything a programmer generally needs for keeping track of pesky invisible characters:

  • eol: The character to show at the end of each line
  • tab: The characters used to show a tab. Two characters are used: the second will be repeated for each space
  • trail: Character to show for trailing spaces. This is probably the thing most of us are looking for

There are more settings which are all documented, but these are the ones that are used the most often. A typical 'listchars' setting might look like this:

Read More →

Script Roundup: Git Gutter, vim-nodejs-complete

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

Git Gutter

Vim Git Gutter (GitHub: airblade / vim-gitgutter, License: MIT) by Andrew Stewart shows a symbol in the sign column to indicate where lines have been added, modified, or deleted. This is based on Git Gutter for Sublime Text 2.

Vim's documentation in :help sign-intro explains what the sign column is for if you're not familiar with it.

vim-nodejs-complete

vim-nodejs-complete (GitHub: myhere / vim-nodejs-complete) by Lin Zhang adds 'omnifunc' support for Node developers. For example, typing:

Read More →

Vim 101: Object Motions

Discovering and retaining good habits for file navigation is one way to vastly improve your productivity when using Vim. Other than jumps and searching, text object motions are also a great way for skipping around a file like a Vim virtuoso.

Text object motions (:help object-motions) cause the cursor to move in Normal mode based on rules that sometimes seem archaic, but the basic ones are easy to get the hang of.

The ( and ) motions move the cursor [count] sentences backward and forward, respectively. If you type 3) the cursor will move 3 sentences forward. Of course, the concept of a "sentence" may vary depending on what you're writing, and Vim's documentation defines a sentence as text that ends in a ., !, or ?, followed by whitespace (:help sentence). This might not make a lot of sense if you're writing code, but if I'm writing documentation or blog posts then I find myself using it.

Read More →

Stop the Vim Configuration Madness

We used to use TVs as monitors and it was terrible

Convention over configuration is an established paradigm, it even has a Wikipedia page! I like the idea of things working well out of the box. However, when it comes to Vim many people are attracted to it because they've heard how configurable it is. I think most of us are drawn to hackable things -- there's probably a strong correlation between Vim users, Arduino hackers and Android tinkerers. But the obsession with configuration has got to go.

Too many new Vim users obsess over plugins and configuration. Let me give you an extremely important Vim tip: practice using it. I've seen one too many love-letter-to-Vim blog posts where the author recommends a flashy plugin that does nothing to really improve productivity. You know what improves productivity? Mastering motions and operators. Digging into Vim's grammar to better understand how to navigate within lines, and quickly hop around large files. Are you really hammering the arrow keys or page up/down, or are you instantly flipping to a previous position with a mark, or jumping between characters with t and f?

Read More →