As a pentester and hacker we will often work with text – word lists, configuration files, etc. We will do a lot of that on our computer, where we have access to the editor we prefer. The rest will be on remote machines where the editing tools are restricted. When Nano is installed, we have an easy-to-use terminal text editor that is not very powerful.
Luckily, most systems have either Vi or Vim installed. Vi stands for visual and is a powerful, fast-modal text editor that works either in insert mode (where you type in the document) or in normal mode (where you type commands for the session). Switching between sessions is as easy as pressing a button, making it ideal for those who do not like to take their hands off the keyboard.
Vim, which stands for Vi IMproved has all the features of Vi with some excellent additions that are helpful in editing source code. There is also an extensive help system and many customization options. Many systems associate Vi with Vim, including macOS. Personally, Vim is for all my edits on remote hosts.
Vim may seem complicated and uninteresting, but don't worry – it feels like it all when they are just starting. The trick is to stick to it. The longer you use Vim, the better you get it – to the point where you do not even have to take your hands off the keyboard.
This tutorial will be very introductory. There are whole books on Vi / Vim, but I want to make sure that you at least know the basics to get you started.
Our first step is configuring Vim. Since we generally work with code or configuration, we want to emphasize row numbering and syntax. You can configure Vim by editing the file .vimrc in your home directory.
Open a terminal emulator like iTerm and make sure you are at your home directory with the command:
The terminal should display that They are located in / Users / $ yourusername or roughly like root @ kali . If this is not the case, enter the following command, which will change the directory to your home directory.
Your .vimrc file contains your Vim configurations are saved. If you use Vim, you have another custom configuration in your .vimrc file. I keep a copy of my complex .vimrc on my GitHub. However, if you use Vim on a remote host, you generally do not have a custom user . .vimrc Therefore, it is important to be familiar with the basic behavior.
Enter the command in the terminal:
This will prompt Vim to open the file .vimrc . , This file may not exist. In my case, I have not configured .vimrc yet. As you can see below, this is a blank document, and the tilde (~) symbols just show blank lines.
Vim starts in command mode (aka normal mode), not insert mode. This means that pressed keys are interpreted as commands for Vim rather than data entry. To exit command mode, press i on your keyboard. This allows the insert mode. If you press and instead, Vim moves the cursor one field to the left and starts insert mode.