Man pages in Vim

Hit K on a keyword, and Vim looks up the program under the keyword. It’s a bit jarring because Vim appears to shell out from your buffer to show the definition. To see that man page in Vim, load the man.vim plugin from command mode or in your .vimrc: :runtime! ftplugin/man.vim Now, you can read man pages as a Vim buffer: :Man curl

November 11, 2021 · 1 min · Jake Worth

Override Vim's Filetype

Vim’s filetype auto-detection is great for effortless syntax highlighting, but what if a certain kind of file (i.e. Ruby) contains lots of another kind of code (i.e. SQL)? The Ruby code will be highlighted and readable, the SQL a large monochrome blob. Hard to read and reason about. We can do better! Override the automatic assignment with: :set ft=sql This command with no assignment returns the current setting: :set ft filetype=lua We can easily revert to the auto-detected extension as needed. ...

April 22, 2021 · 1 min · Jake Worth

My Annotated Vim Configuration File

I love Vim. Folks who’ve programmed with me, or attended a Vim Meetup when I was an organizer, can attest. When I was learning to code, getting fast at Vim changed everything for me. After almost a decade using this editor, here are my personal configurations. ...

November 26, 2020 · 6 min · Jake Worth

Vim Nonrecursive Mappings

My first PR to a new Vim plugin was merged this week, check it out, adding non-recursive Vim mappings to vim-termbux. ...

December 17, 2016 · 1 min · Jake Worth

Vim Regex Word Boundaries

Today while writing a Vim regex to change every instance of it (ignoring larger matches like itemized), we stumbled upon Vim regex word boundary matching. Given this file: foo foobar The following Vim regex will match on both the first and second line: :%s/foo/baz/g But with word boundaries, we’ll only match (and change) the first line, because only the first foo is a standalone word: :%s/\<foo\>/baz/g

September 20, 2016 · 1 min · Jake Worth

Keyword, Match, and Region in VimScript

After a recent talk I gave that included VimScript, an attendee asked a question about the differences between keyword, match, and region following syn in a Vim syntax highlighting file. Here’s my answer. ...

April 20, 2016 · 1 min · Jake Worth

Vim Buffer Problem

A few weeks back I tackled the following programming challenge from my colleague Josh Branchaud: Vim Buffer I open up a new Vim buffer and type all the numbers 1 to 10,000, separated by spaces. Then, my cat walks on the keyboard and somehow activates a substitution command that replaces all the ‘0’ digits (zeros) with spaces. If I now sum up all the numbers in the buffer, as delineated by spaces, what is the total? ...

March 6, 2016 · 2 min · Jake Worth

Count Links in a Markdown File

Today I learned a great way to count the links in a README or link collection. Vim Regex! :%s/- \[//n In Vimspeak: On every line, find all of the times where - [ (the beginning of a Markdown bulleted hyperlink) occurs, count them, and report the number of matches. See :help substitute in Vim for more information. h/t Josh Branchaud

February 14, 2016 · 1 min · Jake Worth

Get help with Pathogen

Today I found a great command in Pathogen.vim, :Helptags. This is a riff off :helptags {dir}, a Vim feature that builds helptags for directory {dir}. :Helptags does the same for all the directories in your runtimepath, which defaults on Unix and Mac OS X to: "$HOME/.vim, $VIM/vimfiles, $VIMRUNTIME, $VIM/vimfiles/after, $HOME/.vim/after" The use case here is when you’ve just loaded a new plugin into your Vim bundle, you open up Vim, and :h {my_new_plugin} isn’t ‘helping’ you out.

January 13, 2016 · 1 min · Jake Worth

Change Inner Tag Block

Vim has excellent commands for changing the contents of parentheses (ci(), brackets (ci[), and squiggly braces (ci{) (as well as single quotes, double quotes, backticks, etc.). But what about tags? Place your cursor anywhere inside the tags, type cit in Visual mode, and this: <div>Begone</div> Becomes: <div></div> d works too, but I prefer c because it puts you in Insert mode at the end of the opening tag, ready to type. ...

January 7, 2016 · 1 min · Jake Worth

Don’t miss my next essay

Hear from me immediately when I post: no ads, unsubscribe anytime.