Used notations
Command as user
For commands issued by the user I use dollar sign $ at the beginning.
$ command arg1 arg2 ...
Command as root
For commands issued by the root I use hash sign # at the beginning.
# command arg1 arg2 ...
Commands run after each other
In order to speed up copying and pasting I often connect commands to one block with following notation:
$ command1 arg11 arg12 ; \
command2 arg21 arg22 ; \
command3 arg31 arg32 && \
command4 arg41 arg42
; - runs next command even if the previous one exited with non zero status (was unsuccessful)
\ - continue commands in new line
&& - runs next command only if the previous one exited with status 0 (was successful)
You can copy & paste such commands block in one go to the terminal and all commands should be executed.
Vim Cheat Sheet
In this blog I use vim as text editor. I am a vim beginner, so it's just a preference to challenge myself. Below is a quick Cheat Sheet with commands that I use frequently when editing files.
When typing commands starting with : you can use Tab key for auto-completion. Also keys Arrow Up and Arrow Down can be used to view last commands.
:q - exit from vim :) you need to enter : than q than press Enter and if that's too much use nano ;P
:q! - quit without saving changes
:w - save changes
:wq - save changes and quit
h or Arrow Left - move cursor left
j or Arrow Down - move cursor down
k or Arrow Up - move cursor up
l or Arrow Right - move cursor right
gg - go to the first line of the document
G - go to the last line of the document
i - enter insert mode in which you can write text
Esc or Ctrl + C - exit insert mode
u - undo
A - append at the end of the line (jump to the end of line and enter insert mode)
o - append a new line below the current line
x or Del - delete character
dd or :d - delete line
ciw - replace entire word no matter where is the cursor (it deletes word at cursor and enter insert mode)
cw - replace word from cursor position (it deletes word characters from cursor position and enter insert mode)
cc - replace entire line
C - replace line from cursor position to the end of the line
:%s/oldtext/newtext/g - %s substitue in entire file all occurrences /g of oldtext with newtext
v - visual mode to mark lines for example for copying (aka yank)
V - visual mode fore selecting whole lines
Ctrl + v - visual block mode
Select with mouse - if you have enabled mouse in vim you can select text with that
Esc or Ctrl + C - exit visual mode
y - copy (aka yank) selected text
p - paste copied text after cursor
P - paste copied text before cursor
/pattern - search for pattern
n - repeat search in same direction
N - repeat search in opposite direction
:vsplit /path/to/filename.txt - vertically split window and open file filename.txt; you can open the same file in split window, useful for working and comparing different parts of larger file
Ctrl + w, w - jump to next split window
Ctrl + w, h - jump to split window left
Ctrl + w, j - jump to split window down
Ctrl + w, k - jump to split window up
Ctrl + w, l - jump to split window right
:line_number - jump to line number, for example :46 jumps to line 46
<line_number> + gg - jump to line number, for example 46gg jumps to line 46
^ - move cursor to the beginning of the line (easy to remember because this character in regex means at start of a line)
$ - move cursor to the end of the line with the newline character at the end (easy to remember because this character in regex means at the end of a line)
g_ - move cursor to the end of the line without the newline character at the end