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?.
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.
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.
vim-startify (GitHub: mhinz / vim-startify, License: Vim) by Marco Hinz adds a startup screen to Vim with a menu that displays recently used files, sessions, and bookmarks. It effectively replaces Bram Moolenaar's message with something potentially productivity enhancing, particularly if you like using sessions.
If, for some reason, you like the idea of customising the startup message, but don't want to use vim-startify, then take a look at :help 'shortmess'. This is a setting that can be placed in your .vimrc to customise Vim's behaviour when it starts up. For example, to turn off Bram's message, use I:
Send in your Vim scripts for review through our contact form.
vim-table-mode
vim-table-mode (GitHub: dhruvasagar / vim-table-mode, License: MIT) by Dhruva Sagar is an Emacs-inspired Table Mode plugin that makes it easier to work with ASCII formatted tables. The author wrote a blog post with a bit of background behind the plugin (it was derived from earlier work by Tim Pope), and some videos that illustrate how it works.
Using Table Mode is dead simple. You simply start typing on a new line with the table separator - |g:table-mode-separator|, and you just type away! The plugin does the rest automatically for you as you type. With each additional separator you add, it aligns the table properly, without having to do anything else.
Gundo
I was going through Steve Losh's plugins, after referencing Learn Vimscript the Hard Way in a talk I gave earlier this year about Vim. I stumbled on Gundo (GitHub: sjl / gundo.vim, License: GPLv2+), which was released before I started writing usevim, but I thought it was worth writing about because I know many people struggle with Vim's undo system.
Continuing with the trite university themed Vim 101 posts, I thought it would be useful to drop in the occasional practical lesson. Something for you to practice to develop good habits when using Vim.
One thing that tripped me up early on was registers. I managed to get used to yanking and putting text, but I kept overwriting the default register when I actually wanted to keep that content hanging around.
A few weeks ago I wrote about the black hole register, and I included a note about copying the default register. I believe that it's better to get used to thinking "should I yank this into a register?" before applying an operator command.
There are a few emerging solutions appearing for collaborating with Vim. The most obvious solution, which people are actually using for serious work, is to set up a server with your code, tmux, and Vim. In How We Use tmux for Remote Pair Programming, Joe Moore of Pivotal Labs talks about how to set this up and why he prefers this approach. Although it would be equally trivial to connect using GUI desktop sharing, the text-based approach has its own advantages:
Due to network latency GUI-based desktop screen sharing was intolerably slow for coding. tmux made network latency a non issue. My personal experience was that tmux + Vim was so fast when working remotely that it was usually indistinguishable from coding locally.
If you're remote pair programming, you could get a cheap virtual machine somewhere, set up tmux and Vim, then hand out ssh keys so people can connect to the same tmux instance safely.
Send in your Vim scripts for review through our contact form.
vim-signify
vim-signify (GitHub: mhinz / vim-signify, License: Vim), or Sy, by Marco Hinz, uses signs to show linewise changes in a file. It works with lots of version control systems: git, mercurial, darcs, bazaar, subversion, cvs, and rcs (phew!). It's configurable, and has some clever navigation features -- g:signify_mapping_next_hunk and g:signify_mapping_prev_hunk can be set to jump between changed lines.
Other options allow the sign colours to be changed, and the plugin can be toggled per-buffer.
If you've managed to fit tabs into your workflow, then you've probably noticed curious numbers and signs that appear alongside the truncated filename. It's very easy to read this information once you know how: the number refers to the number of split windows in a tab, and the + means there is an unsaved file in the tab.
The tab bar itself is known as the 'tabline' (:help 'tabline'). If you executed :set tabline=hello then 'hello' would be displayed instead of the standard content. You can switch back to the default by typing :set tabline=.
Working in a modern command-line environment can offer several ways to manage multiple windows: Vim itself supports split windows and tabs, and many Vim users also use terminal multiplexers like tmux and GNU screen. However, there are those of us who also use a terminal that supports split windows and tabs, like iTerm2.
A new breed of Vim plugins can take advantage of all of these features to better support asynchronous tasks. For example, dispatch.vim by Tim Pope is a new one that can talk to tmux, screen, and iTerm to run time-consuming tasks in the background using Vim's standard compiler plugins. The intention is that you can asynchronously run test suites while continuing to work.
There's also Vitality by Steve Losh which enables Vim to communicate with iTerm2 and tmux.