unix-commands

Useful UNIX commands

cat file1>>file2: append the content of file1 to file2.

:%s/foo/bar/g: vim command to find and replace all the occurrences of foo with bar globally.

Cut and paste in vim:
Position the cursor where you want to begin cutting.
Press v to select characters (or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks).
Move the cursor to the end of what you want to cut.
Press d to cut (or y to copy).
Move to where you would like to paste.
Press P to paste before the cursor, or p to paste after.

Copy and paste is performed with the same steps except for step 4 where you would press y instead of d:

d stands for delete in Vim, which in other editors is usually called cut
y stands for yank in Vim, which in other editors is usually called copy

Select and delete multiple lines:

Type Shift-v to enter linewise selection mode, then move the cursor down using j (yes, use h, j, k and l to move left, down, up, right respectively, that’s much more efficient than using the arrows) and type d to delete the selection.

gg=G: align and indent the file.

ls -d */: list only directories in a directory.

Advertisements

Powered by WordPress.com.

Up ↑

%d bloggers like this: