How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Set vi (Vim) as the Default Editor in Ubuntu
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Set vi (Vim) as the Default Editor in Ubuntu
Server Management

How to Set vi (Vim) as the Default Editor in Ubuntu

how7o
By how7o
Last updated: June 8, 2026
7 Min Read
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
SHARE

By default a fresh Ubuntu install opens nano whenever a tool needs an editor — git commit, crontab -e, visudo. If your muscle memory is vi, that’s a small papercut every single time. Making vi (or vim) the default editor takes two layers of config, and people usually set only one and wonder why git still pops open nano. Here’s the complete fix — the system default and the environment variables — so everything in your terminal uses vi.

Contents
  • TL;DR
  • Why two settings, not one
  • Step 1 — Set the system default editor
  • Step 2 — Set EDITOR and VISUAL
  • Step 3 — Don’t forget root
  • Make git use vi explicitly
  • Verify it worked
  • Frequently asked questions
  • Related guides
  • Wrapping up

Last verified: 2026-06-07 on Ubuntu 24.04 LTS.

TL;DR

echo 'export EDITOR=vi' >> ~/.bashrc
echo 'export VISUAL=vi' >> ~/.bashrc
source ~/.bashrc

That covers git, crontab, and most CLI tools. For the system-wide default too, run sudo update-alternatives --set editor /usr/bin/vim.basic. Check it with echo $EDITOR → vi.

Why two settings, not one

Ubuntu decides which editor to launch in two independent ways, and different programs read different ones:

  • The system-wide editor alternative — a managed symlink at /usr/bin/editor that tools like sudoedit fall back to.
  • The $EDITOR and $VISUAL environment variables — what git, crontab -e, and most interactive CLI tools actually check first.

Set only the symlink and git still opens nano (it ignores the alternative). Set only the variables and a few system utilities still use the old default. Set both and everything lines up — which is the whole point of doing it once, properly.

Step 1 — Set the system default editor

Ubuntu manages the generic editor command through update-alternatives. Point it at vi/vim interactively:

sudo update-alternatives --config editor

It prints a numbered list; type the number next to /usr/bin/vim.basic (or /usr/bin/vi) and press Enter. Prefer no menu? Set it in one line:

sudo update-alternatives --set editor /usr/bin/vim.basic

Not sure which vi binaries you have? List them first:

which vi vim vim.basic
Set vi as default editor on Ubuntu — update-alternatives plus EDITOR and VISUAL

Step 2 — Set EDITOR and VISUAL

This is the layer most CLI tools actually read. Add both variables to your shell startup so they’re set in every new session:

echo 'export EDITOR=vi' >> ~/.bashrc
echo 'export VISUAL=vi' >> ~/.bashrc
source ~/.bashrc

Programs that distinguish the two prefer $VISUAL for full-screen editors like vi and fall back to $EDITOR for line editors — setting both to vi means it doesn’t matter which one a tool checks. If your login shell is zsh, append the same lines to ~/.zshrc instead.

Step 3 — Don’t forget root

Environment variables are per-user, so setting them for your account does nothing when you’re acting as root. On a server where you run crontab -e or visudo as root, add the same lines to root’s startup file:

echo 'export EDITOR=vi' >> /root/.bashrc
echo 'export VISUAL=vi' >> /root/.bashrc

Make git use vi explicitly

Git reads its own core.editor setting before the environment variables. If you want to be certain — or you set a different editor in git earlier — pin it directly:

git config --global core.editor vi

Now git commit (without -m), interactive rebases, and merge-message edits all open vi.

Verify it worked

echo "$EDITOR"                                  # -> vi
update-alternatives --query editor | grep Value # -> the vi/vim path
crontab -e                                       # should open vi (q! to quit)

If echo $EDITOR prints vi and crontab -e drops you into a modal editor, you’re done. To switch back to nano later, re-run update-alternatives --config editor and change the export EDITOR lines — nothing here is permanent.

Frequently asked questions

What’s the difference between vi and vim on Ubuntu?

vi is the classic editor; vim (“vi improved”) is the modern drop-in with syntax highlighting, undo, and more. On Ubuntu, vi is usually a symlink to a vim build (vim.basic or vim.tiny). Setting either as your default editor gives you the same modal editing — pick vim.basic if it’s installed for the fuller feature set.

Which command sets the default editor in Ubuntu?

sudo update-alternatives --config editor sets the system-wide generic editor that many tools fall back to. Pick the number next to vim.basic (or /usr/bin/vi). To skip the menu: sudo update-alternatives --set editor /usr/bin/vim.basic.

Why does git still open nano after I set the editor?

Git reads its own core.editor first, then the $VISUAL and $EDITOR environment variables — it doesn’t use Ubuntu’s update-alternatives setting. Set it explicitly with git config --global core.editor vi, or export EDITOR=vi so git (and crontab, and others) pick it up.

How do I set vi as the default editor for the root user too?

Environment variables are per-user, so add the same two lines to root’s shell startup: echo 'export EDITOR=vi' >> /root/.bashrc and the same for VISUAL. On servers where you mostly work as root, this is the one that actually matters for crontab -e and visudo.

EDITOR vs VISUAL: which one wins?

Programs that distinguish them prefer $VISUAL for full-screen editors (like vi/vim) and fall back to $EDITOR for line editors. In practice you set both to the same value so it doesn’t matter — that’s why the setup below exports EDITOR and VISUAL together.

How do I switch back to nano later?

Reverse the same two steps: run sudo update-alternatives --config editor and pick nano, and change (or remove) the export EDITOR=... lines in ~/.bashrc, then source ~/.bashrc. Nothing is permanent — the editor default is just a symlink and two environment variables.

Related guides

  • How to migrate a website to a new server with rsync — another Ubuntu server task you’ll do from the terminal.
  • rsync says “ALL DONE” but files are missing — reading command-line output the way you read editor config.

Wrapping up

Two layers — the editor alternative and the EDITOR/VISUAL variables — and every tool in your terminal opens vi. Set both (plus root, plus git) once and you’ll never fight nano again.

Debian’s reference on the editor alternative: debian.org/doc/manuals/debian-reference.

TAGGED:BashBeginnersCommand LineLinuxsysadminterminalUbuntu

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder rsync Says “ALL DONE” but Files Are Missing: How to Verify
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026

You Might Also Like

MySQL connect remote from Ubuntu — mysql-client + mysql -h host
Server Management

How to Connect to a Remote MySQL Database from Ubuntu

7 Min Read
Switch from LiteSpeed to Apache in WHM/cPanel
Server Management

How to Switch from LiteSpeed to Apache in WHM/cPanel

4 Min Read
MariaDB restart on Linux — systemctl restart mariadb
Server Management

How to Restart the MariaDB Server on Linux

6 Min Read
Nginx 502 with recv() failed 104 connection reset — PHP-FPM timeout and memory tuning
Server Management

Fix Nginx ‘recv() failed (104: Connection reset by peer)’ with FastCGI

9 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?