Emacs in Neovim

There's a pull request on the neovim / neovim project that adds libvterm. This library is a C implementation of a terminal emulator that provides callbacks for drawing, so Thiago de Arruda has hooked into it and displays the output from within Neovim.

That means you can get a full terminal by typing :terminal. It's even capable of running Emacs. There's even a video of this on YouTube: take a look at Emacs running in Neovim by Justin M. Keyes.

I found this on reddit/r/vim under Emacs running in Neovim. Besides the obvious Emacs/Vim jokes, people seemed genuinely impressed. If this ships in Neovim it'll mean we have to completely rewrite all of our "Vim as an IDE" posts!

Read More →

gVim to xcolors

gvim-to-xcolors (GitHub: 97-109-107/gvim-to-xcolors) is a Python script for extracting colours from Vim themes and outputting colours in the X resources convention.

It does this by parsing highlight groups and their priority. The normal group is processed separately to determine the foreground and background colour.

The author has been using it to generate i3wm colour schemes with Charles Leifer's themer. I think this would be cool if you've got a favourite Vim colour scheme but can't quite get your window manager to look right.

Read More →

Registers and the Clipboard

Recently I somehow ended up with set clipboard=unnamed in my .vimrc. I don't remember adding it, but I searched and removed it when I realised changes were overwriting my system clipboard contents. Here's what :help unnamed says, in case you're not familiar with this feature:

When included, Vim will use the clipboard register '*' for all yank, delete, change and put operations which would normally go to the unnamed register. When a register is explicitly specified, it will always be used regardless of whether "unnamed" is in 'clipboard' or not. The clipboard register can always be explicitly accessed using the "* notation.

Some people like set clipboard=unnamed. I find the "* register is way too frequently updated -- I prefer to think of the system clipboard as something that exists outside Vim, and keep Vim's registers as a separate bank of snippets.

Read More →

A Vim Clojure Toolchain

For those of us who like Lisp, Emacs is naturally compelling. But I always gravitate back to Vim. Therefore, whenever I see a Clojure/Vim article I find it very interesting -- how do people get that immediate REPL feel? How do you get parens balancing properly?!

Today I found My Clojure Toolchain: Vim by @venantius, and noticed the author also use Fireplace, which is the best Clojure REPL I know. The post goes into lots of detail about other Vim scripts that can help with Clojure development, from code traversal to linting.

Paredit.vim is another absolutely critical plugin to have for the Vim Clojure developer's toolbox ... Its true value lies in its support for what Emacs users refer to as "Slurpage" and "Barfage" - the ability to, with a keystroke or two, move existing arguments into or out of a given form.

Read More →

Indentation Motions

Here's a cool idea: indentation with motions. IndentWise by Jeet Sukumaran (GitHub: jeetsukumaran/vim-indentwise) provides motions based on indent depths or levels in normal, visual, and operator-pending modes.

For example, pressing [- moves to the previous line of lesser indent than the current line. The opposite is ]-, which moves to next line of lesser indent than the current line. It supports lots of other motions which are all documented, and configurable.

You can also move based on the absolute indentation level by providing a count argument, and block-scope boundary navigation is supported as well.

Read More →

Five Time-Saving Vim Tricks

Benjamin Klein, who wrote The VimL Primer, recently published a blog post entitled Save time in Vim NOW with these five weird tricks. I was looking for one weird trick, so I was very happy to receive five weird tricks. Anyway, one of them is about switching windows with CTRL and then a direction (hjkl), which saves a key press.

This is what the mapping looks like:

noremap <c-j> <c-w>j
noremap <c-k> <c-w>k
noremap <c-l> <c-w>l
noremap <c-h> <c-w>h

I've accidentally enabled this before when I've tried out .vimrc files from GitHub, or those Vim plugin packs aimed at beginners. For some reason I've never got used to it, I don't know if pressing CTRL and then a key with the right-hand just feels weird to me or what, but I find it tricky.

Read More →

Preview Images with image.vim

Sometimes I accidentally open a png or jpg with Vim, and it shows me a face-melting representation of the binary data. If you do this enough it gets annoying, so instead I've been using Ashish Anand's image.vim to render ASCII previews of images.

image.vim

Converting images to ASCII is an old trick that you can do pretty easily on the command-line (at least it's easy in Linux), but the thing I liked about this plugin is it uses an autocmd to run whenever an image is opened:

Read More →

Cmd2: Fuzzy Search for cmdline

Command-line mode, where you enter commands with : and /, can be enhanced with gelguy's new plugin Cmd2.vim. It gives you fuzzy completion for search, which can be really useful if you've been searching for long strings in overly wordy projects. It also lets you easily get the line number and current word, which I always find fiddly.

Cmd2.vim works by behaving like a new submode -- it's more accurate to think of it as a framework for creating extensions that require command-line input. The fuzzy completion module which most people will want to try is actually an extension built on Cmd2.vim that is bundled with the plugin:

At a higher level, Cmd2 provides a framework to create extensions which require cmdline input. One such extension is Cmd2Complete which provides fuzzy completion for search in wildmenu style. The rendering of the UI and handling of the input is handled by the framework, but can be further customised - for example to create a CtrlP/Unite style menu instead.

Read More →

The Vim Regular Expression Dialect

If you look at the "pattern" help page, then you'll see this: "Vim's regexes are most similar to Perl's" which sounds great, until you continue reading to find "in terms of what you can do." One thing to keep in mind about Vim's regular expressions is they behave like other regular expression syntaxes that you might be familiar with, until they don't, in which case you start randomly escaping characters until your pattern works.

Sarcasm aside, you should think of regular expressions in Vim as a unique dialect. If something doesn't work, refer to :help pattern-searches. Here's an example: today I was converting a large Objective-C switch statement into a JSON file. I used a few regular expressions to slice and dice the entire file, and ended up with something close to what I wanted. I even managed to join every other line with :%normal J. I went from lots of these:

case ExampleTypeName:
  return @"TypeName";  

To JSON properties and values:

Read More →

Vim or Emacs?

Chris Penner is just starting out with Vim, and he's written an interesting article about his experiences: Vim Vs. Emacs?. I remember being in the same position, and the reason I stuck with Vim was the reason I could have stuck with Emacs: I didn't want to waste time learning a platform-specific editor. Also, Emacs and Vim work well in the command-line, which is great if you're an old school server-loving IRC nerd like me.

One of the beautiful things about creating vim commands or mappings is that it uses the same interface as normal editing. The mapping you need is exactly what you'd type inside the editor. This means that the more you learn in the main editor, the more customization options you unlock.

Emacs is also great (and far ahead of Vim) when it comes to doing more than one thing at once, and for being able to run and check code as you work on it.

Read More →