Vim is a highly efficient and customizable text editor that is widely used by developers, system administrators, and Linux enthusiasts. It’s lightweight, works directly in the terminal, and supports plugins, macros, and syntax highlighting—making it perfect for programming tasks.
In this comprehensive guide, we’ll cover everything—from installation to advanced tips and tricks—to help you make the most of Vim in Termux.
📥 1. Installing Vim in Termux
Before we start, let's set up Vim properly in Termux.
1.1 Update Packages 🔄
Make sure all Termux packages are up-to-date:
pkg update && pkg upgrade
1.2 Install Vim 📦
Use the following command to install Vim:
pkg install vim
1.3 Verify Installation ✅
Check the version of Vim to confirm successful installation:
vim --version
You should see details about the Vim version, including compiled features and support for scripting languages.
📝 2. Opening Vim and Creating Files
2.1 Open an Existing File 📂
vim filename
2.2 Create a New File 🆕
If the file doesn’t exist, Vim will create it:
vim newfile.txt
🔄 3. Understanding Vim Modes
Vim works with 3 primary modes, each designed for specific tasks:
- Normal Mode 😎 – For navigation and executing commands. *(Default mode)*
- Insert Mode ✍️ – For directly typing and editing text.
- Command Mode 🛠️ – For saving, exiting, and advanced operations.
Switching Modes:
i
– Enter Insert Mode to edit text.Esc
– Return to Normal Mode.:
– Access Command Mode for saving, exiting, and more.
📚 4. Essential Commands and Shortcuts
4.1 Editing Text ✂️
Command | Action |
---|---|
i | Insert text at the cursor position. |
a | Append text after the cursor. |
x | Delete the character under the cursor. |
dd | Delete (cut) the current line. |
yy | Copy (yank) the current line. |
p | Paste copied/cut text after the cursor. |
u | Undo the last action. |
Ctrl + r | Redo the last undone action. |
4.2 Saving and Exiting 💾
:w | Save the file without exiting. |
:q | Quit Vim if no changes were made. |
:wq or ZZ | Save and exit the file. |
:q! | Exit without saving changes. |
4.3 Navigation 📍
Command | Action |
---|---|
h | Move left by one character. |
l | Move right by one character. |
k | Move up by one line. |
j | Move down by one line. |
0 | Jump to the start of the line. |
$ | Jump to the end of the line. |
gg | Go to the start of the file. |
G | Go to the end of the file. |
: | Go to a specific line (e.g., :10 ). |
/word | Search for a word forward. 🔍 |
?word | Search for a word backward. 🔍 |
n | Jump to the next search match. |
⚡ 5. Advanced Editing Techniques
5.1 Visual Mode – Text Selection 🔧
- Enter Visual Mode:
v
- Select Line:
V
- Block Selection (Column Mode):
Ctrl + v
Once selected, you can copy (y
), cut (d
), or replace text easily.
5.2 Search and Replace 🔄
Replace all occurrences of a word in the entire file:
:%s/old/new/g
%
– Apply to the whole file.g
– Replace globally (all occurrences).
Replace only the first occurrence per line:
:%s/old/new/
5.3 Split Windows 🖥️
- Horizontal Split:
:split filename
- Vertical Split:
:vsplit filename
- Navigate Between Splits:
Ctrl + w + w
🎨 6. Customizing Vim with .vimrc
6.1 Create and Edit .vimrc 🛠️
vim ~/.vimrc
6.2 Add Basic Settings 📑
syntax on " Enable syntax highlighting 🌈
set number " Show line numbers 🔢
set tabstop=4 " Set tab width to 4 spaces 📏
set shiftwidth=4 " Set indent width to 4 spaces ✏️
set expandtab " Use spaces instead of tabs ␣
set autoindent " Maintain indentation automatically 🔄
Save and exit using :wq
.
🔌 7. Extending Vim with Plugins
7.1 Install Vim-Plug Plugin Manager 🛠️
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
7.2 Add Plugins to .vimrc
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree' " File explorer 📁
Plug 'junegunn/fzf' " Fuzzy finder 🔍
Plug 'itchyny/lightline.vim' " Status bar 🎛️
call plug#end()
7.3 Install Plugins
Open Vim and type:
:PlugInstall
🛡️ 8. Troubleshooting Common Issues
- Vim Won’t Open Files?
Check file permissions:chmod 644 filename
- Plugins Not Working?
Update vim-plug::PlugUpdate
- Slow Performance?
Disable unnecessary plugins in.vimrc
.
🌟 9. Tips for Becoming a Vim Pro
- Practice Commands Daily: Vim is muscle memory-based. The more you use it, the faster you get.
- Learn Shortcuts: Focus on shortcuts to speed up your workflow.
- Master Macros: Record and replay sequences of commands using
q
and@
. - Try Vim Tutorials: Use
vimtutor
for interactive learning within Vim.
📣 Final Thoughts
Vim is more than just a text editor; it’s a powerful IDE replacement when customized correctly. With its lightning-fast performance and support for plugins, Vim in Termux becomes an unstoppable tool for coding on the go.
Take your time to explore Vim’s features, customize it to fit your workflow, and practice regularly to unlock its full potential! 💻
For more tips, tutorials, and updates—stay tuned to this blog! 📚
0 Comments