If you’re a pentester and programmer who edits a lot of text, then it’s important to learn an A Serious Text Editor. Which Serious Text Editor you learn is not terribly important and is largely dependent on the types of environments you expect to be editing in. Most of the system comes with per-installed Vi | Vim editor. This tool is fast and frequent and works perfectly even when we’re editing large files.
For me Vim editing tool always felt complicated for me and it was so frustrating because i didn’t spend time learning it. And though it might be difficult to understand So i kept using nano which is another best terminal editor.
The reason is that these editors are highly optimized to perform the kinds of tasks that you will be doing a lot. For example, consider adding the same bit of text to the end of every line. This is trivial in A Serious Text Editor, but ridiculously cumbersome otherwise.
Usually vim’s killer features are considered:
A) that it’s available on pretty much every Unix you’ll ever encounter
B) your fingers very rarely have to leave the home row, which means you’ll be able to edit text very, very quickly. It’s also usually very fast and lightweight even when editing huge files.
There are plenty of alternatives, however. Emacs is the most common example, of course, and it’s much more than just an advanced text editor if you really dig into it. I’m personally a very happy TextMate user now after years of using vim/gvim.
The trick to switching to any of these is to force yourself to use them the way they were intended. For example, in vim, if you’re manually performing every step in a multi-step process or if you’re using the arrow keys or the mouse then there’s probably a better way to do it. Stop what you’re doing and look it up.
If you do nothing else, learn the basic navigation controls for both vim and Emacs since they pop up all over the place. For example, you can use Emacs-style controls in any text input field in Mac OS, in most Unix shells, in Eclipse, etc. You can use vim-style controls in the less(1) command, on Slashdot, on gmail, etc.
So to explain you perfectly and for basics need this guide will be introductory and covering basics.
let’s get started!
Editing the File using Vi or Vim Editor
In the terminal, enter the command:
root[email protected]:~# vi root.py
[email protected]:~# vim root.py
As you can see, this is an empty document. The “~” symbols simply indicate empty lines.
Vim starts up in command mode (aka normal mode), not insert mode. This means that keys pressed will be interpreted as commands for Vim and not data entry. In order to get out of command mode, you will need to press i on your keyboard. This enables insert mode. If you were to press a instead, Vim would move the cursor a space to the left and begin insert mode there.
- How to switch from command mode to insert mode i
- How to switch from insert mode to command mode Esc
- How to navigate up a line in command mode k
- How to navigate down a line in command mode j
- How to navigate left a character in command mode h
- How to navigate right a character l
- How to save a file
- How to exit without saving (in command mode)
- How to Undo u
- How to Redo Ctrl+r
- You can combine writing and quitting (in command mode):
From there the rest will just make you faster.
I have written a sample program, to check some features of vim.
As you can see we didn’t have highlighted text and lining so we’re gonna test some commands.
Some of the basics commands which we’re gonna need is,
syntax on set number