Heading image for post: Best of TIL Year One: Vim

Hashrocket Projects

Best of TIL Year One: Vim

Profile picture of Jake Worth

Here are some of the top Vim posts from Today I Learned.

Today I Learned is now over a year old.

The participation from my coworkers has been inspiring, rocketing our posts count to over 750. The enthusiasm from fans of the site has been encouraging, on Twitter, Hacker News, and elsewhere. We open-sourced the codebase earlier this year and have gotten issues and pull requests, as well as several clones in production. It's been awesome.

TIL content is like a river; if you haven't posted today, your content gets lost in the stream. That's why I'd like to pause and highlight some of the top posts from the first year of Today I Learned.

Beyond a chance to reflect, I hope we can all benefit from the hard-won epiphanies of Rocketeers at work. Leverage the head-banging of others!

We'll start with Vim, our first and most active channel. Below are the top five most liked Vim posts, in order, from the first year of Today I Learned.

Enjoy!

Highlight #Markdown Fenced Code Syntax in #Vim (Dorian Karter)

Up until now I was editing all my blog posts in Atom for lack of markdown fenced code block highlighting in Vim. Atom supported it out of the box. As it turns out Vim can do that too, out of the box!

If you are running a recent version of Vim (mine at time of writing 7.4.9910) you can setup highlighting for fenced code blocks in markdown.

Open your .vimrc and add the following line:

let g:markdown_fenced_languages = ['html', 'vim', 'ruby', 'python', 'bash=sh']

You can customize it to your liking and add more languages.

> Note: Not all languages are supported but you can try and see if they work. To see a list of languages you have installed on Mac (with Vim installed by Homebrew) run ls -l /usr/local/Cellar/vim/7.4.1190/share/vim/vim74/syntax

screenshot

This is a game changer.

Vim Change Case of Words (Vinicius Negrisolo)

If you want to switch the case in Vim:

gu => lowercase

gU => uppercase

g~ => toogle case

You can also combine with Vim motions like:

g~ip => toogle case for the current paragraph.

Browse and repeat Vim commands (Dorian Karter)

If you typed a command in Vim's command line and want to repeat it you can open the command-line window and browse through past commands. There are two ways two do that:

  1. From Normal mode type q:
  2. From the command line after typing a colon press CTRL-f

In the command window you can browse up and down with HJKL and hit return to re-run the command.

Delete to the End of the Line (Josh Branchaud)

There are a number of ways to delete from the cursor position to the end of the line. Generally when I am doing this, I want delete to the end of the line and then start typing something different. Perhaps the best way to do this is by hitting C. It deletes to the end of the line and then leaves you in insert mode. This also makes for easier repetition with the dot command.

This is synonymous with hitting c$.

See :h C for more details.

h/t Dorian Karter

VSwitch Direction of Selection in Vim (Dorian Karter)

Switch the free end of the cursor in Vim's VISUAL MODE.

Simply press o while selecting and the free end will go to the beginning of your selection.

screenshot

Conclusion

Thanks to Josh, Dorian, and Vinicius for those posts.

Today I Learned had a spike in traffic near the beginning of the year, and these posts are mostly from that time. But there's a lot of great Vim tips from earlier. See them all here:

https://til.hashrocket.com/vim

Keep composing those commands, and learning every day.


This post is part of a series. Stay tuned for my next post, when we will look at the top SQL posts from year one.

  • Adobe logo
  • Barnes and noble logo
  • Aetna logo
  • Vanderbilt university logo
  • Ericsson logo

We're proud to have launched hundreds of products for clients such as LensRentals.com, Engine Yard, Verisign, ParkWhiz, and Regions Bank, to name a few.

Let's talk about your project