Vim is one of the most popular text editors in Linux. If you haven’t used yet, these are the basic commands to start.
Table of Contents
- Opening a file with Vim, inserting text, saving and close
- Moving through file
- Replacing text
- Selecting text
- Deleting text
- Undo, copy, cut and paste
- More commands
Opening a file with Vim, inserting text, saving and close
- Open a file or directory (from a terminal).
vim text.txt vim .
- Open a file or directory (inside Vim):
:e text.txt :e .
- Inside Vim, type
iand press Enter to enter “insert mode”. Then you can edit the file.
- To save changes, first exit “insert mode” by pressing Escape. Then, type
:w(and press Enter) to save changes.
- Close Vim typing
:qand pressing Enter. You can save changes and close the file at once by typing
:wq. If you want to close without saving changes, type
Moving through file
- You can use keyboard arrows or
hfor left and
- You can move the cursor to the top of the file with
- To the end of the file with
- To the beginning of the current line with
- To the end of the current line with
- You can search inside a file typing
/and the word (and pressing Enter). Then, you can move to the next ocurrence with
nor the previous with
- You can go to the first ocurrence with
ggnor to the last ocurrence with
# replace current line :s/<pattern>/<replace>/g # replace all lines :%s/<pattern>/<replace>/g
# e.g. :%s/100/500/g
- To select, type
vto enter “visual mode” (first press Escape to exit “insert mode” if you were in it) and use arrows or k,j,h,l to select the text.
- Delete a text selection simply by typing
- You can delete the current line by typing
- You can delete a word with
Undo, copy, cut and paste
- To undo, type
- To redo: Ctrl + r.
- To copy a selection, type
- To copy the current line, type
- To cut a selection, type
- To paste, type
- Split window horizontally: Ctrl + ws
- Split window vertically: Ctrl + wv
- Change to the right window: Ctrl + wl
- Change to left window: Ctrl + wh
- Change to the window above: Ctrl + wk
- Change to the window below: Ctrl + wj
Ato go to the end of the line and enter “insert mode”.
oto create a new line below current line and enter “insert mode”.
cwto delete current word and enter “insert mode”.
It’s a configuration file located in
$HOME. If you create this file, default settings will be disabled. These are some examples of the options you can set in Vim (you can write a comment by starting the line with a
" Enable autoindentation filetype indent on " Use spaces instead of tabs for indentation set expandtab " Set number of spaces (2) for indentation set shiftwidth=2 " Set the size of a tab (2 spaces) set tabstop=2 " Enable syntax highlighting syntax enable " Set encoding (utf-8) set encoding=utf-8 " Ignore case when searching set ignorecase " Show first result while typing the search term set incsearch " Highlight all results when searching set hlsearch
In this new series, we are going to explore useful penetration testing utilities from Kali Linux. The main tool (or set of tools) any pen-tester or ethical hacker should know is Metasploit Framework.
Quickemu is a great QEMU-based program to create and run optimised Linux, Windows and macOS virtual machines.
Learn how to install Virtual Machine Manager on your Arch device following a few simple steps.
Jitsi Meet is an open-source video conferencing platform you can install on your server.
A comprehensive list of Linux-related websites sorted by categories.