From the previous post about How to Configure UBNT Wireless Devices to Use Licensed Frequency / Compliance Test, we've learn that UBNT use vi as the text editor application in it's firmware. vi text editor is an ancient text editor application that exist in most UNIX based operating systems. Android OS, UBNT devices, Ubuntu Linux, Kali linux, Linux Mint, Fedora, even BSD based like pfSense all have vi text editor application installed.
Although there are many other command line text editor like pico, nano, etc. vi remain irreplaceable just like notepad for Windows. So, if you are a network administrator or system administrator that have to play on terminal most the time, knowing about basic vi command will be very useful.
Basic vi command - Edit, Save and Find text
In this tutorial, I am using UBNT wireless device (Nanostation M2) terminal via ssh as an example of basic vi command.
vi is a modal editor
vi operates on two modes command mode and insert mode. Command mode will interpreted keystroke as command, common command that used in vi like
:
,/
,?
and *
. While in insert mode, every keystroke will change the document just like typing in Microsoft Word or notepad.vi Insert mode indicator |
vi Command mode indicator |
Opening file in vi
vi filename
Example opening /tmp/system.cfg in vi |
Switching from command mode to insert mode
Press
i
or I
or a
or A
or o
or O
, I always use i
Press i or I or a or A or o or O |
Switching from insert mode to command mode
Press
ESC
keyPress 'ESC' key |
Save file and quit vi text editor
Press
ESC
to switch to command mode and press :wq
(:
in common keyboard by pressing SHIFT+;
)Save and quit vi text editor |
Find matching text or pattern in document
Press
ESC
to switch to command mode and press /text
or ?text
Find text or pattern in document |
Find next matching text or pattern
After finding text, to find another matching text or Find Next in notepad, press
n
or N
in command mode, it work like up and down toggle on notepad CTRL+f
.Find next matching text or pattern |
Other useful command
:q! ###to quit without saving really save me in many times :D
u ###undo and redo last activities (I never use this)
U ###capital U, undo all changes (Never use too)
Please watch this video for demo on using Basic vi command - Edit, Save and Find text. It also have an example on changing UBNT country code better than the previous article.