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 →

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 →

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

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 →