DEV Community

Cover image for Useful and cool Linux and Vim tricks
Atul Anand Oraon
Atul Anand Oraon

Posted on

Useful and cool Linux and Vim tricks

Hi folks,

I recently joined the community call on the Discord server of the Growin Community. We had a Linux session where we learned some handy tricks with Linux.

If you don’t own a Linux machine, don’t worry! You can use:

  1. Killer Koda β€” Just choose Ubuntu from here.
  2. copy.sh

Alright, you're all set to get your hands on the terminal.

3, 2, 1, Go! πŸ”«πŸš€

LINUX Tricks

  • To execute a previous command:

    • history β€” prints the history of commands.
    • !<cmd_no> β€” executes a command from history based on its number.
  • To copy and paste lines in vim:

    • Esc + 10yy β€” copies 10 lines.
    • Paste with p to insert after the cursor.
  • To perform a reverse search:

    • Ctrl+R β€” reverse search through the command history.
  • To count lines in a file:

    • wc -l aks.txt β€” counts and lists the number of lines.
  • Yanking (copying) in vim:

    • yy β€” yanks (copies) the current line.
    • Esc + 5yy β€” yanks (copies) 5 lines.
    • Paste with p after yanking.
  • Navigating in vim:

    • Esc + :1 β€” jumps to line 1.
    • :set nu β€” enables line numbers.
    • Esc + Shift+G β€” moves to the end of the document.
  • Deleting in vim:

    • Esc + dG β€” deletes everything from the current line to the end of the document.
    • Esc + u β€” undoes the last change.
  • Finding unique adjacent lines in a file:

    • uniq -c β€” looks for unique adjacent lines.
  • Sorting, unique filtering, and counting occurrences:

    • cat aks.txt | sort | uniq -c β€” lists all unique lines in aks.txt with their counts after sorting.

That's it! You’ve learned a lot from this article. Do like it and share any comments you have. Don’t shy away!

See you next time!

Top comments (2)

Collapse
 
fnabinash profile image
Abinash Sahoo

You miss the most important one. 😁😁

Esc + :(colon) + q + Enter to quit vim.

Collapse
 
oatula profile image
Atul Anand Oraon

🀣 I usually do a Esc then :wq Enter