As pentesters and hackers we will work with text often – glossaries, configuration files etc. Many of this we will do on our machine, where we have access to which editor we prefer. The rest of it will be on remote machines, where the tools for editing will be limited. If nano is installed, we have an easy to use terminal text editor, but it is not that powerful.
Fortunately, most systems have either Vi or Vim installed. We stand for visual and are a powerful, fast modal text editor that works in either insert mode (where you type inside the document) or normal mode (where you enter commands for the session). Switching between these sessions is as easy as a keystroke, so it's good for those who don't like to take their hands off the keyboard.
Vim, which stands for We IMproved has all the features of We with some excellent additions that help with editing source code. There is also an extensive help system and many customization options are available. Many systems symbolize Vi to Vim, including macOS. Personally Vim is for all my editing on remote hosts.
Vim can seem complicated and unintuitive, but don't worry – it feels so for everyone when they just start. The trick is to keep it. The longer you use Vim, the better you will bring it – to the point where you don't even have to take your hands off the keyboard.
This guide will be very introductory. There are whole books about Vi / Vim, but I want to make sure you know at least the basics so that you can get started with it.
Our first step is to configure Vim. Since we will generally work with code or configuration, we want to listen to numbering and syntax on. Vim can be configured by editing the .vimrc file 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 show that you are in / User / $ your username or something like root @ kali . If it does not, enter the following command, which will change directories to your home directory.
Your .vimrc file is where your Vim configurations are stored. When using Vim, you begin to have more custom configuration in the file .vimrc . I keep a copy of my complex .vimrc on my GitHub, but generally, when you use Vim on a remote host, if you are not an authorized user, you do not have a custom Vimrc so it is important to be familiar with basic behavior.
In the terminal, enter the command:
This tells Vim to open the file .vimrc . This file may not be available. In my case I have not configured .vimrc yet. As you can see below, there is a blank document and the symbols tilde (~) simply indicate empty lines.
Vim starts in command mode (aka normal mode), not insertion mode. This means that buttons that are pressed will be interpreted as commands for Vim and not data entry. To get out of command mode, press i on the keyboard. This enables the deposit mode. If you were to press a instead, Vim would move the cursor a space to the left and begin to insert the position there.