Learning NVim, TryHackMe, Resources

This post will be a walkthrough of the Vim room on TryHackMe, in addition to various learning resources I find helpful.  As I encounter helpful examples for penetration testing, I will post those as well. 

  • TryHackMe room: https://tryhackme.com/room/toolboxvim
    • This room teaches you to reference the vim documentation or search the web for answers to questions about basic commands. 
  • Daniel Miessler’s  (author of infamous SecLists repo) Vim study guide: https://danielmiessler.com/study/vim/
    • This article breaks down the verb-modifier-noun language of Vim, along with an abundance of examples to reference.
  • Vim-Adventures browser game: https://vim-adventures.com/
    • Vim-Adventures is a level-based game that requires the purchase of a $25 license after Level 3.  This game focuses on a couple commands in each level (14 levels!), and makes practicing and learning Vim fun!

Installation

Neovim came preinstalled on ParrotOS, but can be installed on all operating systems from their github page: https://github.com/neovim/neovim/wiki/Installing-Neovim

Configuration

The documentation for neovim says the config file is located at `$XDG_CONFIG_HOME/nvim/init.vim` but the environment variable $XDG_CONFIG_HOME was not set by default on my OS.  Instead, the configuration file can be found in my home directory: /home/.config/nvim/init.vim

Here are the contents of my configuration file:

set number

set expandtab
set autoindent
set softtabstop=4
set shiftwidth=2
set tabstop=4

"Enable mouse click for nvim
set mouse=a
"Fix cursor replacement after closing nvim
set guicursor=
"Shift + Tab does inverse tab
inoremap

"See invisible characters
set list listchars=tab:>\ ,trail:+,eol:$

"set the absolute path for swap files
set directory^=$HOME/.config/nvim/tmp//
"highlight search results
set hlsearch
"ignore case in search results
set ignorecase
"show search results as you type
set incsearch

 

Some of these configuration settings are recommended by Daniel Miessler.  He also recommended to swap the ESC key for ‘jk’ so that your fingers never leave the home-row, but because I am learning this for pentesting, and would likely use the preinstalled vim or vi on target machines, I did not want to modify any keys from default.  Another recommendation is to remap the modifier key ‘/’ to the single quote (‘) but I am choosing to leave the key mappings as default.  

TryHackMe | Toolbox: Vim Room

Most of the answers were found by referencing the vim help documentation (:help command) which has a web version on https://vimhelp.org/.  The other answers were found by referencing https://vim.famdom.com/wiki/.  

Task 2

https://vimhelp.org/usr_02.txt.html

How do we enter “INSERT” mode?
i
How do we start entering text into our new Vim document?
typing
How do we return to command mode?
esc

How do we move the cursor?
h left
j down
k up
l right

How do we jump to the start of a word?
w
How do we jump to the end of a word?
e

How do we insert (before the cursor)
i
How do we insert (at the beginning of the line?)
I
How do we append (after the cursor)
a
How do we append (at the end of the line)
A
 How do we make a new line under the current line?
o

TASK 3

https://vimhelp.org/editing.txt.html (writing, write-quit)
How do we write the file, but don’t exit?
:w
How do we write the file, but don’t exit- as root? https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work
:w !sudo tee %
How do we write and quit?
:wq
How do we quit?
:q
How do we force quit?
:q!
How do we save and quit, for all active tabs?
:wqa

Task 4

https://vimhelp.org/usr_04.txt.html
How do we copy a line?
yy
how do we copy 2 lines?
2yy
How do we copy to the end of the line?
y$
How do we paste the clipboard contents after the cursor?
p
How do we paste the clipboard contents before the cursor?
P
How do we cut a line?
d
How do we cut two lines?
2dd
How do we cut to the end of the line?
D
How do we cut a character?
x

Task 5

https://vimhelp.org/pattern.txt.html
How do we search forwards for a pattern (use “pattern” for your answer)
/pattern
How do we search backwards for a pattern (use “pattern” for your answer)
?pattern
How do we repeat this search in the same direction?
n
How do we repeat this search in the opposite direction?
N
How do we search for “old” and replace it with “new” https://vim.fandom.com/wiki/Search_and_replace
:%s/old/new/g
How do we use “grep” to search for a pattern in multiple files?
:vimgrep

Leave a Reply