Script Roundup: Vim-CtrlSpace, railsdock.vim

Vim-CtrlSpace

Vim-CtrlSpace (GitHub: szw / vim-ctrlspace, License: MIT) by Szymon Wrozynski helps you organise buffers by listing them per-tab. Workspaces can be saved to disk, and it supports fuzzy search through buffer lists and files.

I've introduced a concept of many buffer lists tightly coupled with tabs. That means each tab holds its own buffer list. Once the buffer is shown in the tab, the tab is storing it in its own buffer list. No matter in which window. It's just like having many windows related to the same concern, but without the need of split windows at all! Then you can forget the buffer (remove it from tab's buffer list), or perform many other actions.

It changes the status bar, but Szymon has some ideas about integrating it with vim-airline.

Read More →

Too Many Tabs!

I use tabs and split windows a lot. I organise them depending on context: sometimes I'll have test | source, other times arbitrary groupings based on the problem at hand. I have two main issues with tabs, though: switching between large numbers of tabs, and opening them based on buffers.

Too many tabs!

The basic tab switching commands are gt and gT -- move forward and backwards. These commands can take a numerical arguments, so 3gt skips three tabs ahead. You can even skip to the first tab with :tabr. If you've got mouse input enabled (:set mouse=a), then you can click tabs.

If you don't like the order of your tabs, :tabm + and :tabm - can be used to move tabs around.

Read More →

Search and Replace with Capture Groups

Once you get comfortable with :%s for searching and replacing across an entire file, you can start to unlock more power by exploiting Vim's rich regular expression handling. Coming from a GUI background, you might be tempted to look for a plugin to solve a seemingly general problem. However, a deeper knowledge of regular expressions may be all you need.

Here's an example: bluMyst on reddit wanted to know how to generalise search and replace to add \n" to lines that start with printf(. The solution suggested by "who00oot" was capture groups:

Use capture groups. Search for (printf("[^"]+) and replace with $1\n (you may have to escape).

Read More →

Script Roundup: vim-vertical-move, npm.vim

vim-vertical-move

vim-vertical-move (GitHub: bruno- / vim-vertical-move, License: MIT) by Bruno Sutic adds vertical movement motions. You can move the cursor to the point where a column change would be required. Bruno's example shows him editing quoted URLs in CSS, where he uses f'<Ctrl>V,]f' to do the following:

  • f': Move to the first quote
  • CTRL-v: Enter Visual mode, blockwise
  • ,]: Move down to the last column
  • f': Move to the next column that contains '

This causes a set of image URLs to be replaced with a new relative URL.

npm.vim

npm.vim (GitHub: oinksoft / npm.vim, License: MIT) adds support for npm to Vim. Once it's installed you can use :Npm to install and manage modules. It even supports tab completion!

Read More →

Avoiding Modelines with scripts.vim

I don't like .gitignore files very much. For general things I want Git to ignore, like .DS_Store and *.sw?, I prefer to use ~/.gitignore_global. Similarly, rather than using modelines to improve filetype detection I use .vim/scripts.vim.

Here's an example: I have a Node project that has command-line scripts that I've written in JavaScript. The scripts are named without .js: bin/chpass, bin/run_migration, etc. These files start with #!/usr/bin/env node, but Vim doesn't know they're JavaScript so the syntax highlighting is off.

I could add a modeline, like this: // vim: set ft=javascript. The problem with that is I've now added an editor-specific line. What if other people on my team use Emacs or Sublime Text?

Read More →

Using Vim as a Password Manager

A few weeks ago I wrote about Vim's built-in cryptographic features in Protect Notes with Vim Encryption. In Using Vim as your Password Manager, Sam Stelfox writes about an iteration on this idea -- using Vim for encrypting passwords:

Using this personally required me coming up with a pseudo-file format that would allow me to quickly and easily find the credentials I needed.

You'll notice I also used this to keep track of whether an account had physical information tied to it. When I moved this made it very quick for me to search for accounts that I needed to update with my new mailing address.

Read More →

Script Roundup: HowMuch, Airlineish

HowMuch

You might be surprised to learn that there's a lot of interest in the Vim mathematics plugin space. Kai Yuan, who has written several interesting Vim plugins (including Join) sent in HowMuch (GitHub: sk1418 / HowMuch). It supports all Visual modes, two output formats (append, replace), and multiple expression evaluators (bc, Python, native).

The documentation has animated gifs so it's easy to see how it works. It even has some spreadsheet-like functionality -- block-wise selection can do sums (something I find hard to communicate without an animation).

Airlineish

I like plugins for plugins. This one is a theme for Airline, called Airlineish (GitHub: paranoida / vim-airlineish, License: MIT) by Rafal Bromirski. It makes it extremely easy to see what mode you're in by using bold colours. Red means replace, and Normal mode is a neutral purple. And Rafal also gets bonus points for using an animated gif in the documentation.

Read More →

Visual Mode Tricks

My most-used Visual mode command is probably gv. When in Normal mode, gv starts Visual mode but selects the previous area. So if you had a selection you wanted to work on and lost it, perhaps by pressing <Esc>, then gv will restore the selection.

Sometimes you just want to skip back to the location of the previous section. The '< mark allows you to do that: while in Normal mode, type '< and the cursor will skip back. You can even use this mark to modify selections -- move the cursor to the desired location, then go into Visual mode with v and press '< to select up to the first line or character of the previously selected area.

If I'm being lazy I'll go into Visual Line mode with V, then select entire chunks of text by triggering a search for part of a line. This can be efficient for moving or deleting methods or functions.

Read More →

LearnVim

LearnVim by Barry Arthur is an introduction to Vim, distributed as a help text file.

A suggested path for learning Vim. This help file introduces fundamental concepts, offers concrete advice for correctly configuring a new Vim instance and outlines a progressive set of topics for the enthusiastic newcomer to study and practise.

You can drop it into your .vim/doc directory, which allows the document to be easily searched. It's written in a tutorial style that starts by introducing the help system, then goes on to configuring Vim, and eventually explores motions and marks.

Read More →

Script Roundup: Vimdeck, noerrmsg.vim

Vimdeck

Vimdeck

Vimdeck (GitHub: tybenz / vimdeck, License: MIT) by Tyler Benziger is a plugin for showing presentations. It uses Markdown, and renders headers with fonts that look like FIGlet. Code is syntax highlighted, and images are turned into ASCII art.

noerrmsg.vim

Apparently, some plugins like YouCompleteMe generate unwanted error messages that can't be turned off. Hector Arciga wrote a plugin that intercepts these errors and changes the text colours so you can't see them: noerrmsg.vim.

Read More →