How to Use Vim and Nano Text Editors in Termux — Complete Guide
// 01 — Introduction
If you spend any real time in Termux, you will eventually need a text editor. Whether you are writing a Python script, editing a config file, or building something from scratch, having a solid text editor right inside your terminal makes everything faster and smoother. That is exactly where Vim and Nano in Termux come in — two of the most powerful and widely used terminal-based text editors in the Linux world, now fully available on your Android device.
Most beginners who open Termux for the first time rely on simple commands like echo to write to files, or they try to use file manager apps on the side. But that approach gets messy very fast the moment your scripts grow longer. Learning to use a proper terminal editor is one of those skills that genuinely changes how you work inside the command line. It is a skill every serious Termux user eventually picks up — and the sooner you do it, the better.
In this guide, we are going to cover both editors from the ground up. Nano is the friendlier of the two — it shows you keyboard shortcuts right on screen and you can start editing immediately without learning any special modes. Vim is more complex up front, but once it clicks, it is incredibly fast and powerful. Many developers who learn Vim end up preferring it for everything.
You do not need root access for any of this. Both editors install cleanly through Termux's package manager and work perfectly on any modern Android device. This guide was written and tested in 2026 on a fresh Termux install, so every command here is current and working.
By the end of this tutorial you will be able to install both editors, create and edit files confidently, navigate without a mouse, save your work, use find-and-replace, and apply a handful of tricks that most beginners never discover. Let us get into it.
pkg update && pkg upgrade first to avoid any installation issues.// 02 — Installing Vim and Nano in Termux
Installation is straightforward. Termux uses its own package manager called pkg, which is a wrapper around apt. Both Vim and Nano are available in the official Termux repositories, so there is no need to add any external source or download anything manually.
Update Your Package List First
Before installing anything new in Termux, it is always a good habit to refresh your package list. This makes sure you are pulling the latest version of whatever you install.
pkg update
Termux will fetch the latest package index from its servers. You may see a prompt asking whether to keep or replace certain config files — just press Enter to accept the default answer each time.
Install Nano
To install Nano, run this single command:
pkg install nano
Termux will show you the package size and ask you to confirm. Type y and press Enter. Installation usually takes less than ten seconds on a decent connection. Once it finishes, Nano is ready to use immediately.
Install Vim
To install Vim, run:
pkg install vim
Vim is slightly larger than Nano because it includes more features, but it still installs quickly. If you want the enhanced version of Vim with extra features like clipboard support and scripting extensions, you can install vim-python instead:
pkg install vim-python
Install Both at Once
If you want to install Nano and Vim in a single command, you can chain them together like this:
pkg install nano vim
Verify the Installation
After installing, confirm both editors are working by checking their version numbers:
nano --version
vim --version
You should see output similar to this for Nano:
GNU nano, version 7.2
(C) 2023 the Free Software Foundation and various contributors
And for Vim you will see a longer output listing all the features compiled into your version. As long as both commands return version information without errors, you are good to go.
// 03 — Getting Started with Nano in Termux
Nano is the editor most beginners should start with. Unlike Vim, it does not have multiple modes — you open a file and you start typing right away. The bottom of the screen always shows you the available keyboard shortcuts, so you are never completely stuck wondering how to save or exit.
Opening and Creating Files with Nano
To open an existing file with Nano, use:
nano filename.txt
If the file does not exist yet, Nano will create it for you automatically when you save. This means you can use the same command whether you are creating a new file or editing an old one. For example, to create a new Python script:
nano myscript.py
Nano opens and you are immediately in the editing area. Start typing your code. The cursor works exactly as you would expect — use the arrow keys on your Termux keyboard to move around.
Essential Nano Keyboard Shortcuts
In Nano, the ^ symbol means the Control key on your keyboard. So ^X means hold Ctrl and press X. Here are the shortcuts you will use the most:
| Shortcut | Action |
|---|---|
| Ctrl + O | Save the file (Write Out) |
| Ctrl + X | Exit Nano |
| Ctrl + K | Cut the current line |
| Ctrl + U | Paste the cut line |
| Ctrl + W | Search for text (Where Is) |
| Ctrl + \ | Find and replace text |
| Ctrl + G | Open help menu |
| Ctrl + A | Jump to start of line |
| Ctrl + E | Jump to end of line |
| Ctrl + C | Show current cursor position |
Saving a File in Nano
When you are done editing, press Ctrl + O. Nano will show a prompt at the bottom asking you to confirm the filename. If you want to keep the same name, just press Enter. If you want to save it under a different name, type the new name and press Enter. You will see a confirmation message showing how many lines were written.
Exiting Nano
Press Ctrl + X to exit. If you have unsaved changes, Nano will ask whether you want to save them. Press Y for yes, N for no, or Ctrl + C to cancel and go back to editing. This safety prompt means you will never accidentally lose your work.
Searching and Replacing Text in Nano
To search for a word or phrase, press Ctrl + W, type your search term, and press Enter. Nano will jump to the first match. Press Ctrl + W again and then Enter to find the next occurrence.
For find-and-replace, press Ctrl + \. Nano will ask for the search term, then the replacement text, then whether to replace all occurrences or confirm each one individually.
-l flag: nano -l filename.txt. This is very useful when editing code.Enabling Syntax Highlighting in Nano
By default, Nano in Termux may not show syntax highlighting. You can enable it by creating or editing the Nano configuration file:
nano ~/.nanorc
Add this line to include all default syntax highlighting rules:
include "/data/data/com.termux/files/usr/share/nano/*.nanorc"
Save and exit. The next time you open a file with a known extension like .py, .sh, or .html, Nano will colour the syntax automatically.
// 04 — Getting Started with Vim in Termux
Vim has a reputation for being hard to learn, and honestly, that reputation is partly earned. But the difficulty is front-loaded — once you understand how Vim thinks, it starts to feel natural and incredibly efficient. The key concept in Vim is modes. Vim is always in one of several modes, and what your keyboard does depends on which mode you are in.
Understanding Vim Modes
The three modes you will use most are:
- Normal Mode — This is the default mode when you open Vim. Keys are commands, not text input. You navigate, delete, copy, and paste here.
- Insert Mode — This is where you actually type text. Press i to enter Insert mode from Normal mode.
- Command Mode — Activated by pressing : from Normal mode. Used for saving, quitting, find-and-replace, and other operations.
Opening a File with Vim
vim filename.txt
Vim opens in Normal mode. You will see the file content (or an empty buffer for a new file) and a status bar at the bottom. To start typing, press i — you will see -- INSERT -- appear at the bottom of the screen confirming you are now in Insert mode.
Saving and Exiting Vim
This is the part that trips up almost every first-time Vim user. To save and quit, you need to be in Command mode. Here is the step-by-step process:
Press Escape
Make sure you are in Normal mode by pressing the Escape key. You can press it multiple times — it will not cause any harm.
Type the Command
Press : (colon) to enter Command mode. You will see a colon appear at the bottom of the screen.
Save and Quit
Type wq and press Enter. The w means write (save) and q means quit. Together they save the file and close Vim.
Here is a full table of the most important Vim Command mode commands:
| Command | What It Does |
|---|---|
| :w | Save the file without quitting |
| :q | Quit (only works if no unsaved changes) |
| :wq | Save and quit |
| :q! | Quit without saving (force quit) |
| :w filename | Save as a new filename |
| :set number | Show line numbers |
| :set nonumber | Hide line numbers |
| :syntax on | Enable syntax highlighting |
| :u | Undo last action |
Essential Vim Normal Mode Commands
Normal mode is where Vim's real power lives. These are the navigation and editing commands you will use constantly:
| Key | Action |
|---|---|
| h / j / k / l | Move left / down / up / right |
| w | Jump to start of next word |
| b | Jump back to start of previous word |
| gg | Go to the first line of the file |
| G | Go to the last line of the file |
| dd | Delete (cut) the entire current line |
| yy | Yank (copy) the entire current line |
| p | Paste below the current line |
| u | Undo |
| Ctrl + r | Redo |
| / searchterm | Search forward for a term |
| n | Jump to next search result |
| N | Jump to previous search result |
Find and Replace in Vim
Vim's find-and-replace is done in Command mode using this syntax:
:%s/old_text/new_text/g
Breaking this down: the % means apply to the whole file, s means substitute, the slashes separate the search and replacement text, and g at the end means replace all occurrences on each line (not just the first one per line). If you want Vim to ask for confirmation before each replacement, add c at the end:
:%s/old_text/new_text/gc
// 05 — Advanced Tips for Vim and Nano in Termux
Once you are comfortable with the basics, there are quite a few tricks that will make your editing sessions noticeably faster and more pleasant. This section covers the most useful ones for both editors.
Opening Multiple Files
Both editors can open multiple files at once from the command line. With Nano:
nano file1.txt file2.txt
Use Alt + , and Alt + . to switch between files in Nano. With Vim:
vim file1.txt file2.txt
In Vim, use :n to go to the next file and :prev to go back.
Creating a Vim Configuration File
Vim reads a configuration file called .vimrc from your home directory every time it starts. Creating this file lets you set permanent preferences. Here is a solid starter configuration for Termux users:
vim ~/.vimrc
Then add these settings:
set number " Show line numbers
set tabstop=4 " Set tab width to 4 spaces
set shiftwidth=4 " Indent with 4 spaces
set expandtab " Convert tabs to spaces
set autoindent " Auto-indent new lines
set syntax=on " Enable syntax highlighting
set hlsearch " Highlight search results
set ignorecase " Case-insensitive search
set smartcase " Case-sensitive if uppercase used
Save with :wq. Every time you open Vim from now on, these settings will be active automatically.
Indenting Multiple Lines at Once in Vim
To indent several lines at once in Normal mode, go to the first line you want to indent, then type the number of lines followed by >>. For example, to indent 5 lines:
5>>
To un-indent the same number of lines, use 5<<.
Jumping to a Specific Line Number
In Vim, type : followed by the line number and press Enter:
:42
In Nano, use Ctrl + _ (underscore), then type the line number and press Enter.
Using Vim as a Quick File Viewer
You can open a file in Vim in read-only mode so you cannot accidentally edit it:
vim -R filename.txt
This is handy when you want to read through a long config file or log without the risk of changing anything.
Editing Files Owned by Root with Nano
In Termux you generally do not deal with root-owned files unless you are running a rooted device, but on systems where you do have root, you can edit protected files by prefixing with su -c:
su -c "nano /etc/hosts"
// 06 — Practical Workflows: Real Use Cases in Termux
Knowing the commands is one thing. Knowing when and how to apply them in real situations is what turns you from a beginner into someone who actually gets things done efficiently in the terminal. Here are some practical scenarios you will encounter regularly when using Vim and Nano in Termux.
Writing and Running a Bash Script
One of the most common uses for a terminal editor is writing shell scripts. Here is the complete workflow using Nano:
Create the Script File
Open a new file with the .sh extension using Nano.
nano hello.sh
Write Your Script
Type your bash script content directly into the editor.
#!/bin/bash
echo "Hello from Termux!"
echo "Today is: $(date)"
echo "Your home directory is: $HOME"
Save and Exit
Press Ctrl + O to save, then Ctrl + X to exit Nano.
Make It Executable and Run
Give the script execute permission and run it.
chmod +x hello.sh
./hello.sh
You should see output like this:
Hello from Termux!
Today is: Tue Mar 4 10:42:17 UTC 2026
Your home directory is: /data/data/com.termux/files/home
Editing Python Scripts with Vim
Vim works especially well for Python because its indentation handling is excellent once configured. Open a Python file:
vim scanner.py
Press i to enter Insert mode and write your script. When you are done, press Escape, then type :wq to save and exit. Run your script with:
python scanner.py
Editing Config Files
Termux and the tools you install in it often rely on config files in your home directory. For example, editing your .bashrc to add custom aliases:
nano ~/.bashrc
Add a line like this at the bottom:
alias update='pkg update && pkg upgrade'
Save and exit, then reload your shell configuration:
source ~/.bashrc
Now you can just type update instead of the full command every time.
// 07 — Common Errors and Fixes
Error: "bash: vim: command not found"
This means Vim is not installed yet. Run pkg install vim to fix it.
Error: "bash: nano: command not found"
Same issue for Nano. Run pkg install nano.
Vim Stuck — Cannot Type or Exit
Press Escape several times to make sure you are in Normal mode. Then type :q! and press Enter to force quit without saving. If Vim feels completely frozen, press Ctrl + C first, then try :q!.
Nano Shows "[ Error reading /path/to/file ]"
This means the file path you typed does not exist or you do not have permission to read it. Double-check the path with ls before opening.
File Saved but Changes Are Gone After Restart
Make sure you saved to the correct path. In Termux, your home directory is /data/data/com.termux/files/home. Files saved outside this location may not persist. Use pwd to check your current directory before opening a file.
Vim Shows Swapfile Warning on Open
If Vim crashed or was closed improperly last time, it leaves a swap file behind. You will see a warning like Found a swap file by the name ".filename.swp". If you want to recover your last unsaved changes, press R. If you want to delete the swap file and start fresh, press D.
// 08 — Pro Tips for Text Editing in Termux
- Use a physical keyboard if possible. Vim especially becomes much more comfortable with a Bluetooth keyboard. Control key shortcuts are harder to hit on a touchscreen keyboard.
- Install the Termux extra keys row. Go to Termux settings and enable the extra keys row. This gives you quick access to Escape, Ctrl, Tab, and arrow keys — all essential for both editors.
- Learn Vim incrementally. Do not try to learn every Vim command at once. Start with
i,Escape,:wq, and:q!. Add more commands one at a time as you need them. - Use
vimtutorfor built-in Vim training. Vim includes an interactive tutorial. Just typevimtutorin Termux and follow the lessons. It takes about 30 minutes and covers all the fundamentals. - Back up your config files. Before editing any important config file, make a backup copy:
cp ~/.bashrc ~/.bashrc.bak. If something breaks, you can restore the original easily. - Use
catfor quick reads. If you just want to read a short file without editing it,cat filename.txtis faster than opening it in an editor. - Pipe output directly into a file. You can redirect command output into a file for later editing:
ls -la > filelist.txt, then open it withnano filelist.txt.
// 09 — Vim vs Nano: Full Comparison
| Feature | Nano | Vim |
|---|---|---|
| Learning curve | Very low — beginner friendly | Steep at first, but rewarding |
| Shortcut visibility | Always shown on screen | Must be memorised |
| Speed (once learned) | Moderate | Extremely fast |
| Syntax highlighting | Yes (via config) | Yes (built-in) |
| Scripting / macros | No | Yes (Vimscript) |
| Plugin support | Very limited | Extensive ecosystem |
| Multiple file buffers | Basic support | Full buffer management |
| Memory usage | Very low | Low to moderate |
| Best for | Quick edits, beginners | Heavy coding, power users |
| Available in Termux | Yes | Yes |
There is no universally right answer between the two. Many experienced Linux users have both installed and choose based on the task at hand. For a quick config file edit, Nano is faster to open and close. For writing a long script or doing complex refactoring, Vim's speed and features are hard to beat.
// FAQ
:q! and press Enter. The exclamation mark forces Vim to quit without saving, so any unsaved changes will be lost. If you want to save before quitting, type :wq instead.-l flag: nano -l filename.txt. Alternatively, add set linenumbers to your ~/.nanorc file to make it permanent. In Vim, type :set number while in the editor, or add set number to your ~/.vimrc file to enable it by default.vim-python and using Termux's clipboard tools, or by using long-press to select and copy text on your touchscreen. The Termux:API app also provides clipboard access that can be scripted.syntax on to your ~/.vimrc file, or by typing :syntax on inside the editor. Files are identified by their extension, so name your files correctly (e.g., script.py) for automatic detection.// 10 — Conclusion
Learning to use Vim and Nano in Termux is one of the most practical skills you can build as an Android terminal user. These two editors cover every editing scenario you will encounter — from making a quick one-line fix in a config file to writing hundreds of lines of code. They are fast, lightweight, always available, and they require zero root access on your Android device.
Start with Nano if you are brand new to terminal editors. Get comfortable creating, editing, and saving files. Learn the half-dozen shortcuts that matter most and use them until they are automatic. Then, when you are ready, open vimtutor and invest an hour into learning Vim's fundamentals. That investment pays back quickly once you start working on larger projects.
The goal is not to pick a side between Vim and Nano — it is to be fluent enough with both that you reach for whichever one fits the job. That is what experienced terminal users do, and it is completely achievable with a bit of practice.
If you found this guide useful, explore more Termux tutorials right here on HYDRA TERMUX. There are guides covering everything from setting up Python environments to using networking tools — all designed for Android users who want to learn real Linux skills without a computer.
📌 Suggested next read: How to Write and Run Bash Scripts in Termux — Complete Beginner Guide

Comments
Post a Comment