Must Know 5 Vim Tricks (with GIF) for Kubernetes Certification

Puru - Sep 10 - - Dev Community

Today, we’re diving into the world of Vim, and trust me, if you’re gearing up for Kubernetes certifications, these tricks are going to be your best friends.

As we all know, Kubernetes exams (CKA, CKS, and more) are tough and demands strong hands-on command-line skills, and mastering Vim can significantly enhance your efficiency during the exam and level 🆙 your game!

In this post, we’ll reveal five practical Vim tricks that will improve your editing and boost your efficiency, making your exam experience smoother and more effective.

📢 Special Annoucement!

My book Certified Kubernetes Security Specialist (CKS) Handbook, is now available for pre-order with 50% early bird discount! — Use discount code EARLYBIRD during checkout: 👉 Checkout here.

Let’s jump in and sharpen those Vim skills with these essential tricks!


1 - Display Line Number and Use Goto Line

It's crucial to easily navigate and jump to specific lines in YAML manifests as you work on tasks.​ Here's how to show line numbers and use goto to quickly jump into specific line.

  1. In Normal Mode: Type :set nu to display line numbers.
  2. Jump to Specific Line: Type :10 to jump directly to line 10.

GIF: Display Line Number and Goto Line


2 - Smart Indent

When copying and customizing YAML manifests from documentation, proper indentation is crucial for valid YAML syntax. Follow these steps to easily manage indentation in Vim:

  1. Enter Visual Mode: Press Shift + v to select the current line of text. Use the ↑ ↓ arrow or j k keys (recommended) to extend the selection.
  2. Indent Right: Press > to indent the selected text to the right. Press . to repeat the indentation if needed.
  3. Indent Left: To indent text to the left, repeat steps 1 and 2, but use < instead of >.
  4. Highlight Previous Selection: Use gv to reselect the previously highlighted text.

GIF: Smart indent


3 - Effective Cut, copy, paste and undo lines

Quickly rearrange, duplicate, or correct mistakes in your YAML manifests. Here's how you to effectively cut, copy a line and paste it above or below another line and to undo previous action.

  1. Copy a Line: Press yy to copy the current line.
  2. Paste Above: Use Shift + p to paste the cut line above the current line.
  3. Paste Below: Use p to paste the cut line below the current line.
  4. Undo Action: Press u to undo the previous action.

GIF: Cut, Copy, Paste, Undo Lines


4 - Visual block mode to insert text in multiple lines

Visual Block Mode is awesome because it lets you quickly select and edit text across multiple lines simultaneously, making tasks like formatting and adding consistent changes across your YAML files effortless.

  1. Enter Visual Block Mode: Press Ctrl + v to start visual block selection. Use the ↑ ↓ arrows or j k keys to extend the selection.
  2. Insert Text: Press Shift-i to start inserting text.
  3. Apply Changes: Press Esc to apply the changes to all selected lines.

GIF: Visual block mode in action


5 - Run shell command directly within Vim

Did you know you can run shell commands directly from within Vim? Well, now you do 😉

  1. In Normal Mode: Press :! followed by command to run, e.g: :!k get pods

GIF: Run shell command directly within Vim


Summary

And that's a wrap! 🎉 - I hope you're feeling more confident and energized to practice these tricks for your upcoming exams.

👋 If you found this post helpful and want more tips and tricks, don't forget to follow me on Twitter and connect with me on LinkedIn

. . . . . . . . . . . . . . . . . . . . .