256 Kilobytes

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

Articles in Professional Tools | By August R. Garcia

Published | Last Update

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.

6,936 views, 0 RAMs, and 0 comments

Vim is the best text editor, as you know. While there aretricks 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 ofthe 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 alsoa 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 likeGoogle 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 likeedit HTML and CSS,make a website, and other exciting tasks.

Download more RAM. 🐏 ⨉ 0Posted by August R. Garcia 3 years ago

Edit History

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

Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

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.

Post a New Comment

Do you like having a good time?

Register an Account

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

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