ZZ

I was at a VimGolf evening at Vim London a few months ago, and one thing I picked up there was the use of ZZ. If you look at VimGolf solutions, a lot use ZZ to write and close the file. If multiple windows (split buffers) are open, it'll write and close that window. If you're in Normal mode, this is shorter than typing :wq.

There's also ZQ, which quits without saving changes. ZQ is equivalent to :q! rather than :qa!, which quits all windows and Vim entirely.

I like these marginally more efficient ways to quit Vim -- I use ZZ more than :wq or CTRL-W c (which just closes a window). Vim's documentation covers all of these commands and more under Writing and quitting (:help write-quit).

Read More →

Script Roundup: tbone.vim, Niji

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

tbone.vim

tbone.vim (GitHub: tpope / vim-tbone, License: Vim) by Tim Pope provides some integration between Vim and tmux. The :Tmux command executes arbitrary tmux commands with tab completion, and :Tyank and :Tput gives you access to tmux's buffers.

Would you like to paste a shell command into another pane over and over again? I am sorry but you will have to install one of the 300 other Vim plugins for tmux.

Niji

Niji (GitHub: amdt / vim-niji, License: Vim) by Alastair M. D. Touw is another rainbow parentheses plugin that has been influenced by previous similar plugins, including RainbowParenthsis.vim, Lisp.vim, and rainbow_parentheses.vim.

Read More →

Spellchecker Wrangling

I've been writing a whole lot of XML lately. Doesn't sound like fun, does it? Well, it's not all that bad, because I'm well-versed in working with XML in Vim.

One oddity you'll run into when editing XML is spell checking won't work as expected. This is partly because of how the XML syntax file is configured ($VIMRUNTIME/syntax/xml.vim). To force Vim to check spelling, you can run these commands:

:set spell
:syntax spell toplevel

Afterwards, press CTRL-l to redraw the screen so you can see any spelling mistakes. The last command basically forces spell checking in text where the syntax file hasn't defined any other behaviour. If you've got an XML file open, you should see spell checking in each element's content, but tags themselves will be ignored.

Read More →

VimSpeak: Control Vim with Speech Recognition

VimSpeak by "AshleyF" is a program that allows you to speak to Vim:

You can say "select three words" to type v3w or "change surrounding brackets to parens" to type cs]) or crazy things like "change occurrences of 'foo' into 'bar', globally, ignore case, confirm" to type :%s/foo/bar/gic. Of course in insert mode you may dictate whatever you like. To learn the grammar, have a look at the unit tests and the code.

There's an introduction video on YouTube that explains how the source for VimSpeak works, and how to use it:

Read More →

Script Roundup: MarkMyWords, breeze.vim

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

MarkMyWords

MarkMyWords (GitHub: dahu / MarkMyWords, License: Vim) by Barry Arthur allows you to create bookmarks for files and Vim's documentation. Creating a bookmark is as simple as typing :MMWMarkLine, and jumping to a bookmark is performed with :MMWSelect <tag>.

The bookmarks are saved in markmywords.tags, so anything you save should be available between sessions.

Breeze

Breeze (GitHub: gcmt / breeze.vim, License: MIT) by Giacomo Comitti is a plugin for working with HTML. It has EasyMotion-inspired navigation, tag matching, element highlighting, and DOM navigation.

Read More →

Irregular Expressions

Believe it or not, Vim's regular expressions are unique. They're not Perl-compatible regular expressions, or even POSIX regular expressions. Many tools that you use day to day as a programmer use the Perl compatible (PCRE) C library. It's BSD licensed and widely adopted. Also, programming languages themselves often use Perl-derived regular expressions.

Therefore, it's not surprising that Vim's non-standard pattern matching language brings puzzlement to newcomers, but it's simply a question of heritage. Vim is derived from vi, which evolved from ed. Now, ed itself dates back to 1971, when it was created by Ken Thompson, who also created Unix. So the next time someone bemoans Vim for not supporting PCRE, you can say "so what? Did Larry Wall invent Unix as well?!"

In Vim's version of the universe, we have "patterns", and they have some interesting irregularities next to PCRE. While I was researching this post, I found Vim Regexes by Andrew Radev that introduces Vim's regular expression modes, keyword patterns. This is a great introduction to some of the features that make Vim's patterns unique. He also references Refining search patterns with the command-line window on Vimcasts.org, which is a tutorial that will help you build complex search patterns.

Read More →

E492: Not an editor command: W

I was looking at dotfiles on GitHub for something completely unrelated, and noticed this snippet by Gianni Chiappetta:

" Remap :W to :w
command W w

This will help when :W is accidentally typed instead of :w and Vim displays E492: Not an editor command: W. I occasionally do this when I'm making a lot of rapid changes and my finger lingers on the shift key.

Creating an alias with :command (or :com for short) will result in something slightly different to the real :w though, because it won't copy the arguments. Ingo Karkat posted a response to a Stack Overflow question about the same problem: Is there a way in vim to make :W to do the same thing as :w?.

Read More →

Script Roundup: Join, reprocessed.vim

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

Join

Join (GitHub: sk1418 / Join) by Kai Yuan is an enhanced :join command. It can join lines with a separator, trim whitespace, join lines in reverse and even join lines while leaving the original content.

The command's syntax is :[range]Join[!] [separator] [count] [flags]. The GitHub project readme has further details and screenshots.

reprocessed.vim

reprocessed.vim (GitHub: willpragnell / vim-reprocessed) by Will Pragnell brings some Processing support to Vim. It adds syntax highlighting for the Processing language, documentation integration, and it can invoke sketches from Vim.

Read More →

Practical: Joining and Splitting Text

The J (:help J) command is the kind of thing that seems suboptimal when initially learning Vim, but I find I use it with surprising regularity:

Join [count] lines, with a minimum of two lines. Remove the indent and insert up to two spaces (see below).

I even used it to join the previous lines after I pasted them from Vim's manual! The weird thing is, there's no equivalent "split" command. You might be tempted to split text on a single line using a regular expression, and while that does the job there are other ways to do it. Let's look at one method that uses registers as an excuse to practice working with registers and repeats.

Read More →