Terminal & Vim

Terminal & Vim


Linux

  1. Linux Journey
  1. Over the wire

Commands

  • Terminal is used to interact with our system with commands
  • The other mode of interaction is called the GUI which is graphical
  • Many dev tools are only command based and their GUIs don’t exist
ls # To list all the files & folders ls *.js # View all the js files in the folder pwd # tells Current Working Directory mkdir # Create a folder (directory) cd # Navigate to a folder cd ~ # Takes to home cd / # Takes to root head # first few lines from a file tail # last few lines from a file wc filename # view linecount, wordcount, charactercount of a file history # Tells history of commands touch # Create new file echo "Hi" > file.txt # Creates file.txt with "Hi" content rm file # Deletes the file rm -rf folder # Deletes the folder (rf: recursive force) cat file.txt # Concatenate, shows the file content man git # Used to show manual cp # To copy mv # To copy & move nano # Cli based text-editor vi # Cli based code-editor :wq! (To exit) open/start # To open a file # Tricks curl parrot.live # Dancing Parrot curl wttr.in # Weather info curl rate.sx # Crypto info
notion image

Making HTTP Requests

The curl command can be used to make network requests
curl url # GET Request curl -X POST url -H "HEADERS" -d '{JSON}' curl -O url # Download wget url # Used for Downloading ping url # Used to check server latency

Advanced Commands

  • grep → Searches for text or patterns in files.
  • chmod → Changes file or folder permissions.
  • sed → Edits text in a file (like find and replace).
  • awk → Extracts and processes data from text (like columns).
chmod ugo-rwx # to add permissions to a file chmod -R ugo-rwx # to add permissions to a folder grep "one" filename # where "one" has been used in the file. sed -n '/ERROR/ p' filename # to print lines with ERROR text. awk '/ERROR/{print $0}' filename # to print lines with ERROR text.

Vim

  • It is a full blown editor in terminal built in 1991 which was an improved version of another editor named Vi
  • Some of the qualities of Vim are customization, performance and no-mouse control! 🔥
  • To enter vim type vi in terminal
  • Plain vim is not used alone, an improved version of vim called neovim is used instead
  • Neovim can be made into a full blown IDE that uses Lua as it’s programming language 🤺
  • Another alternative is NvChad that comes with all the good stuff out of the box on top of Neovim
notion image

Modes

  • It is called a modal editor as with Vim we are always using some modes.
  • There are three common modes in Vim:
      1. Normal: Navigate with the keyboard
      1. Visual: Used to select and delete text
      1. Insert: Used to insert and edit (much like what VS Code gives by default)
  • Vim is notorious to exit, simply do ESC + :wq! to write and quit

Normal Mode

  • Normal mode is the default that is used to move in our code
  • All these commands to move our cursor is called motion command
  • Navigating using the H Left J Down K Up L Right
  • 0 to go at top and $ to go at bottom
  • e to end of the current word, b to beginning of the previous word
  • gg to go at the top and G to go at the bottom
  • p to paste
  • y to copy (yank)
notion image

Visual Mode

  • It is used to copy paste and delete text, much like what we do with our mouse
  • All the same motion commands (cursor movement)
  • y to copy (yank)
  • d to cut (it deletes and also copies it to clipboard for pasting)

Insert Mode

  • Type anything buddy!
  • Used to type and edit text directly.
  • Enter it with i (insert before), a (after), o (open new line below), etc.
  • Exit insert mode with ESC.

Specials (Commands)

  • Press ESC to go in Normal Mode
  • :w to write
  • :q to quit
  • / to find
  • :line-number to go to a line number
  • u to undo and ctrl + r to redo

🐈 echo “Bye”