256 Kilobytes

5 Tasks You Didn't Know You Could do With Vim

Articles in Professional Tools | By August R. Garcia

Published 4 months agoFri, 03 May 2019 21:06:22 -0700 | Last update 4 months agoSun, 05 May 2019 04:04:00 -0700

Vim is the best text editor, as you know. Most Vim users are aware of the basic hotkeys, commands, and other Vim tricks; however, there are a number of useful tricks that are lesser-known.

5,255 views, 0 RAMs, and 0 comments

Vim is the best text editor, as you know. While there are tricks that you can do with more basic text editors like Gedit, Vim allows for more complex and efficient text editing. Most Vim users are aware of the basic hotkeys, commands, and other Vim tricks; however, there are a number of useful tricks that are lesser-known.

Video Overview

The video below demonstrates the tricks described below in video form. The high quality soundtrack is Bit Bit Loop by Kevin MacLeod, accessed from FreePD.

Vim has Built-in Word Completion

While you might think that a plugin is needed for word completion in Vim, there is in fact built-in word completion, which will suggest words based on the contents of your file. Here’s an easy demonstration:

  1. Put some content into a file
  2. Start typing a word that matches an existing word
  3. Press Ctrl+N
  4. That’s it.

See this screenshot for what this looks like:

Text Completion in Vim - Screenshot

Very nice. There are also a number of other auto-completion tricks worth learning about.

Paste from External Clipboard

When working with Vim, an internal clipboard is used for copying, cutting, and pasting. For example:

  • The command “dd” will cut the current line (“yy” will copy it)
  • The command “p” will paste that line

However, often you may need to paste content from an external source. To do this, use the key combination:

  • Ctrl+Shift+V

When doing this, make sure that you are in insert mode. Otherwise, it will interpret the contents of the copy-paste as if you were manually inputting those keys in that order.

Bonus: When using most rich text editors, like Google Drive, as well as other tools that support rich text like Google Sheets, Ctrl+Shift+V will paste without formatting.

Vertical Highlighting

There are several ways to enter visual mode in Vim:

  • Pressing “v” will enter the standard visual mode
  • Pressing “V” will enter visual mode, highlighting full lines rather than individual characters
  • Pressing “ctrl+v” will enter visual mode with support for vertical highlighting

This can be seen in the screenshot below:

Vertical Selections in Vim - Screenshot

Using this vertical highlighting, it is possible to do things like:

  • Use “u” or “U” to adjust the case of the first letter in a line
  • Use “I” once multiple lines are highlighted to enter insert mode, type something, then press ESC and that text will be entered on all highlighted lines.
  • Bulk deletions to lines.

Note that using “$” to highlight to the end of all lines when in visual mode vertically, since lines may be of different lengths.

Showing Line Numbers in Vim

By default, Vim does not show line numbers. There are a few common ways to determine line number without them being shown on the left-hand side, such as:

  • Using commands like 30gg to jump to particular lines; and
  • Looking at the bottom-right corner to view the current column and number.

However, it is in fact possible to show line numbers in Vim. To do this, enter the following command:

  • :set number

To remove line numbers, use this command:

  • :set nonumber

How to Autoindent in Vim

Similarly to showing line numbers, this is an easy-to-use feature that many are unaware of. To enable, use the command:

  • :set autoindent

And to disable, use this command:

  • :set noautoindent

In Conclusion

What a great text editor. Use it to do things like edit HTML and CSS, make a website, and other exciting tasks.

Download more RAM. 🐏 ⨉ 0 Posted by August R. Garcia 4 months ago

Edit History

• [2019-05-03 21:06 PDT] August R. Garcia (4 months ago)
• [2019-05-03 21:06 PDT] August R. Garcia (4 months ago)
• [2019-05-03 21:06 PDT] August R. Garcia (4 months ago)
🕓 Posted at 03 May, 2019 21:06 PM PDT

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 187 🗨 920 🐏 274
Site Owner

Grahew Mattham

August Garcia is some guy who used to sell Viagra on the Internet. He made this website to LARP as a sysadmin while posting about garbage like user-agent spoofing, spintax, the only good keyboard, virtual assitants from Pakistan, links with the rel="nofollow" attributeproxiessin, the developer console, literally every link building method, and other junk.

Available at arg@256kilobytes.com, via Twitter, or arg.256kilobytes.com. Open to business inquiries based on availability.


Account created 9 months ago.
187 posts, 920 comments, and 274 RAMs.

Last active 6 hours ago:
Commented in thread Quality Content Dump: The Thread

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.