Vim: A How-To Guide (2024)

What is Vim?

Vim is a text editor. It is a powerful tool developers use to edit their code.

What you can use Vim for:

  • browsing + editing files (including remote editing)
  • opening tabs
  • split screen functionality (horizontal or vertical split screen)
  • run linux commands, without leaving the file
  • trigger make builds from your source code (also without exiting the file)
  • bookmark directories and/or lines of a file
  • autocomplete
  • find and replace words
  • indentations
  • cut, copy, paste
  • and much more!

The above list is a summary of the key features highlighted in this article, titled Why I love Vim: It’s the lesser-known features that make it so amazing.

Why Vim?

A key reason why Vim is used is speed. Vim allows you to be incredibly fast when navigating and editing files.

Vim also provides freedom and flexibility. You can customize a vimrc file to override defaults such as default indenting and syntax highlighting defaults. For more on this topic, refer to Learn Vimscript the Hard Way linked here.

Vim is supported on every operating system. In addition, it is a tool you can use regardless of file type — a large majority of files can be edited with Vim.

Also, this code editing tool is lightweight compared to IDEs (Integrated Development Environments) and is available to use without any configuration. That is to say, it can be used right away!

How Do I Use Vim?

Let’s Start at the Beginning.

Some commands you can use in the terminal include:

  • pwd: print working directory
  • ls: list directory contents
  • cd: change directory
  • mkdir: create a new directory
  • rmdir: remove directory
  • rm -R: remove nested directories
  • cp: copy file to a different directory
  • open: open a given file
  • touch: create a file
  • mv: move file
  • rm: remove file

Setting Up Vim.

Like the terminal commands listed above, Vim is used on a terminal.

Vim is pre-installed on Mac computers. This page contains instructions on how to download if you are using a different operating system, or how to update the existing version you have on your Mac.

Typing vim opens a file with Vim text-editor capabilities.

From your terminal, save .bashrc and .vimrc to the home directory (~/).

After saving, run source ~/.bashrc and source ~/.vimrc. These files will be updated with your personalized preferences. Close or open a new terminal to see the changes.

The Four Modes.

Vim has the following modes:

  1. Normal Mode (move around the text)
  2. Insert Mode (allows typing)
  3. Visual Mode (highlights text)
  4. Command Mode (runs commands such as save, edit, quit, find & replace)

Important Vim Commands.

Switching between modes: To exit visual mode and insert mode, press ESCon your keyboard.

To edit a file, you can type in the terminal vim filename.

The section “Operators and Motions, Counts, And Combining Them” in this article is helpful for understanding the why of Vim. There are many commands to memorize, and understanding the logic behind their structure could be insightful and provide more context while learning.

The structure of Vim commands can be described as follows. You’ll see some examples below.

 [OPERATOR][NUMBER][MOTION]

Here are a few of the main commands to get you up and running:

Navigation

For navigation, you can use the standard arrow keys or alternatively the h, k, l, j keys as pictured below.

Vim: A How-To Guide (1)

Normal Mode

  • s — delete character and substitute text
  • dd — delete 1 line
  • xdd — deletes x number of lines (ie. 2dd deletes 2 lines)
  • dw — deletes word
  • d4w — deletes x number of words (ie. d4w deletes 4 words)
  • . — repeat last command
  • 0 — move to beginning of current line
  • u — undo
  • yy — copy or yank a line
  • y$ — copy to end of line
  • p — (lowercase p) put or paste after cursor
  • P —(uppercase P) paste before cursor

Insert Mode

  • x — (lowercase x) delete character
  • i— insert before the cursor
  • I — (uppercase I) insert at the beginning of the line
  • a — insert or append after the cursor
  • A — insert at the end of the line
  • o —(lowercase o) append or open a new line below the current line
  • O — (uppercase O) add a new line above the current line
  • ea— insert at the end of the word
  • ctrl + h— delete the character before the cursor during insert mode

Visual Mode

  • v — Enter visual mode and highlight a character
  • V — (capital V) enter visual mode and highlight entire lines

Command Mode

  • :%s — find and replace
  • :q — exit
  • :q! — quit (no saving)
  • :w — save
  • :wq — save + exit

Interested in seeing a live demo?

You can watch a brief video here:

Opening a New Tab.

:tabnew — command while in normal mode

Simultaneously Opening Files in Multiple Tabs.

vim -p file1 file2 file3 file4

File history.

Reverting a file back to a previous version: u in Command Mode will undo the last change and CTRL-R will redo the changes.

Another option: :earlier 15m will revert the document to how it was 15 minutes ago. The same command can take different variables for time, like :earlier 5m. You can revert the changes with its opposite command :later (from RoseHosting).

Sorting CSS.

:sort alphabetically orders CSS selectors.

Horizontal and Vertical Screen Splitting.

:split — horizontal screen split.

:sp (shorter version of :split)

:vsplit — vertical screen split.

:vsp (short version :vsplit)

More information on this particular topic can be found here.

Additional Resources to Help You on Your Vim Learning Journey

A Special Thanks

I would like to thank Melissa Hovik, a Caltech computer science professor who introduced me to Vim, without whom I would not have learned this tool and seen its beauty in full.

As an enthusiast with considerable expertise in text editors and coding tools, I've had extensive hands-on experience with Vim, a powerful text editor widely used by developers. My proficiency in Vim extends beyond basic functionalities, delving into its advanced features and lesser-known capabilities. I've explored Vim's customization options, delved into Vimscript, and optimized its use for efficient coding.

The article you provided outlines various aspects of Vim, highlighting its key features, use cases, and advantages. Let's break down the concepts discussed in the article:

  1. What is Vim?

    • Vim is a text editor used by developers to edit code efficiently.
  2. Uses of Vim:

    • Browsing and editing files, including remote editing.
    • Opening tabs.
    • Split screen functionality (horizontal or vertical).
    • Running Linux commands without leaving the file.
    • Triggering make builds from source code without exiting the file.
    • Bookmarking directories and/or lines of a file.
    • Autocomplete.
    • Find and replace words.
    • Indentations.
    • Cut, copy, paste, and more.
  3. Why Vim?

    • Speed: Vim allows fast navigation and editing of files.
    • Freedom and flexibility: Customizable vimrc file for overriding defaults.
    • Cross-platform support: Available on every operating system.
    • Lightweight: Compared to Integrated Development Environments (IDEs), Vim is lightweight and can be used without configuration.
  4. How to Use Vim:

    • Vim is used in the terminal.
    • It's pre-installed on Mac computers.
    • Customization involves saving .bashrc and .vimrc files in the home directory.
    • Vim has four modes: Normal, Insert, Visual, and Command.
  5. Important Vim Commands:

    • Navigation using arrow keys or h, k, l, j keys.
    • Modes for deleting characters, lines, and words.
    • Copying and pasting text.
    • Inserting text at different positions.
    • Undo and redo commands.
    • Finding and replacing text.
    • Sorting CSS.
  6. Working with Tabs and Splits:

    • Opening a new tab with :tabnew in normal mode.
    • Simultaneously opening files in multiple tabs with vim -p file1 file2 file3 file4.
    • Reverting a file to a previous version.
  7. Additional Resources for Learning Vim:

    • Vim Cheat Sheet: vim.rtorr.com
    • Vim Adventures: vim-adventures.com
    • Practice and Learn: openvim.com
    • Extensive Vim Tutorial: danielmiessler.com/study/vim/
    • Vim Interactive Guide: digitalocean.com/community/tutorials/getting-started-with-vim-an-interactive-guide
  8. A Special Thanks:

    • The author expresses gratitude to Melissa Hovik, a Caltech computer science professor, for introducing them to Vim.

Vim's capabilities go beyond the basics, making it a versatile and powerful tool for developers seeking efficiency and flexibility in their coding workflows.

Vim: A How-To Guide (2024)

FAQs

How to effectively use Vim? ›

Here are ten tips to help make you more efficient as you learn to use Vim.
  1. Navigate more quickly by increasing your key repeat rate. ...
  2. Navigate vertically with gg/G and ctrl-d/ctrl-u. ...
  3. Navigate horizontally with 0 and $ ...
  4. Escape quicker by re-binding to caps lock (or using ctrl-c)

How to learn Vim easily? ›

The Best Way to Learn Vim
  1. Understand the basics of modal editing and learn a small number of keybindings.
  2. Don't go 'full Vim' – Enable Vim keybindings in your IDE first.
  3. Practice by making small edits to config files from the command line.
  4. Start using Vim entirely for low risk small/medium side projects.
Feb 12, 2022

How do I navigate in Vim? ›

How to move really efficiently in Vim?
  1. gg - move cursor to first line.
  2. #G - move cursor to # line.
  3. GG move cursor to last line.
  4. CTRL+f - move cursor Forward full page.
  5. CTRL+b - move cursor Backwards full page.
  6. CTRL+u - move cursor Up half page.
  7. CTRL+d - move cursor Down half page.
  8. zt - move screen so cursor is at Top.
Jul 1, 2023

Is Vim still relevant? ›

Vim is still the most efficient way to edit text.

While sophisticated editors like Visual Studio Code (VS Code) have come a long way, there's still no great replacement for Vim. Furthermore, because Vim has stood the test of time, it is now widely available as an add-on in many applications.

Should I learn Vim as a beginner? ›

Everyone who types on a computer eight hours a day should learn the Vim language. Yes, it's hard in the beginning, but that's the case with everything new and different. But getting better every day and having more fun coding or writing should be motivation enough. You're not too busy to learn - you'll learn as you go.

What is the best Vim course for beginners? ›

Top Picks
Course HighlightWorkload
Best Introductory Course for Beginners: Vimtutor (Vim)1-2 hours
Best Course for Vim's Philosophy and Demonstration (Massachusetts Institute of Technology)1 hour
Best Short Vim Tutorial for Beginners (freeCodeCamp)1 hour
Best Flashcard-Styled Game for Practicing Vim (vimgenius.com)2-4 hours
5 more rows
Nov 23, 2023

How long did it take to learn Vim? ›

Learning Vim is a process, and that process takes weeks of dedicated time (or months of dabbling) just to get up to the same speed as with a mouse. It's probably one of the steepest learning curves of anything I've ever learned, but the payoff of learning it is extremely valuable, in my opinion.

Which is harder Vim or emacs? ›

Emacs is easier to learn since it has a more natural interface (for users familiar with GUI-based text editors). Since Vim has different editing modes, beginners find it a little harder to learn. The main difference between the two is speed.

How do I navigate between words in Vim? ›

Vim has two speeds for moving backward and forward word-wise. Both allow for a more rapid traversal than moving by one column at a time. We can think of these motions as coming in pairs: the w and b commands both target the start of a word, while the e and ge commands target the end of a word.

How do I skip words in Vim? ›

Press w (“word”) to move the cursor to the right one word at a time. Press b (“back”) to move the cursor to the left one word at a time. Press W or B to move the cursor past the adjacent punctuation to the next or previous blank space. Press e (“end”) to move the cursor to the last character of the current word.

How do I navigate to the first line in Vim? ›

In normal mode:
  1. Press 0 to move the cursor to the start of the line.
  2. Press ^ or _ to move to the first non-whitespace character in the line.
Jan 31, 2024

How to use Vim effectively? ›

Use h, j, k, and l

When you are editing e-mail or other paragraph-formatted text, you might notice that the direction keys skip more lines than you expect. This is because your paragraphs appear as one long line to vim. Type g before h, j, k or l to move by screen lines instead of virtual lines.

How to practice with Vim? ›

The best way to learn is practice. Take a few minutes to try Vim out. If you're on a Linux system right now, open up a terminal and type vim filename. Enter insert mode and type a bit (or copy some of the text from this article into Vim) and then hit Escape to start practicing movement around the file.

What is the point of Vim? ›

What is Vim? Vim is a text editor for Unix that comes with Linux, BSD, and macOS. It is known to be fast and powerful, partly because it is a small program that can run in a terminal (although it has a graphical interface). It is mainly because it can be managed entirely without menus or a mouse with a keyboard.

How do I maximize in Vim? ›

ctrl-w | will make the window as wide as possible. ctrl-w _ will make the window as tall as possible.

Is Vim a good skill? ›

While the path to mastering Vim may seem daunting, the endless possibilities it offers in terms of speed, health benefits, and adaptability make it a skill worth acquiring.

What is the most useful feature of Vim? ›

One of the unique features of Vim is its modes. Vim has several modes, each serving a different purpose: Normal Mode: This is the default mode when you first open Vim. In this mode, you can navigate the file, delete text, copy text, and perform other commands.

How much time does it take to master Vim? ›

Learning vim is not hard. But like any other learning process, to reach proficiency you need to master the fundamentals first. For vim that means about a couple of weeks of your time. Get through those two rough weeks and you can quickly get to a higher level of productivity.

Top Articles
Buying Balloons
What is the Cheapest Way to Build an App?
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
Le Blanc Los Cabos - Los Cabos – Le Blanc Spa Resort Adults-Only All Inclusive
Nestle Paystub
Comenity Credit Card Guide 2024: Things To Know And Alternatives
How Quickly Do I Lose My Bike Fitness?
Minecraft Jar Google Drive
Cashtapp Atm Near Me
Amc Flight Schedule
History of Osceola County
Trac Cbna
Star Wars: Héros de la Galaxie - le guide des meilleurs personnages en 2024 - Le Blog Allo Paradise
Clear Fork Progress Book
Prosser Dam Fish Count
Hollywood Bowl Section H
Accuweather Mold Count
Joann Ally Employee Portal
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Our History
Days Until Oct 8
Barber Gym Quantico Hours
Great Clips Grandview Station Marion Reviews
Air Quality Index Endicott Ny
How Long After Dayquil Can I Take Benadryl
Southland Goldendoodles
BJ 이름 찾는다 꼭 도와줘라 | 짤방 | 일베저장소
Urbfsdreamgirl
Busted Mugshots Paducah Ky
Happy Shuttle Cancun Review
Mercedes W204 Belt Diagram
Pch Sunken Treasures
Blackstone Launchpad Ucf
Honda Ruckus Fuse Box Diagram
Boggle BrainBusters: Find 7 States | BOOMER Magazine
Wsbtv Fish And Game Report
Skyrim:Elder Knowledge - The Unofficial Elder Scrolls Pages (UESP)
Raisya Crow on LinkedIn: Breckie Hill Shower Video viral Cucumber Leaks VIDEO Click to watch full…
7543460065
Google Chrome-webbrowser
Sc Pick 4 Evening Archives
Housing Intranet Unt
Legit Ticket Sites - Seatgeek vs Stubhub [Fees, Customer Service, Security]
Kornerstone Funeral Tulia
Complete List of Orange County Cities + Map (2024) — Orange County Insiders | Tips for locals & visitors
Why Are The French So Google Feud Answers
Mauston O'reilly's
Who Is Nina Yankovic? Daughter of Musician Weird Al Yankovic
Sdn Dds
Craigslist Centre Alabama
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 6046

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.