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.
-
In Normal Mode: Type
:set nu
to display line numbers. -
Jump to Specific Line: Type
:10
to jump directly to line 10.
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:
-
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. -
Indent Right: Press
>
to indent the selected text to the right. Press.
to repeat the indentation if needed. -
Indent Left: To indent text to the left, repeat steps 1 and 2, but use
<
instead of>
. -
Highlight Previous Selection: Use
gv
to reselect the previously highlighted text.
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.
-
Copy a Line: Press
yy
to copy the current line. -
Paste Above: Use
Shift + p
to paste the cut line above the current line. -
Paste Below: Use
p
to paste the cut line below the current line. -
Undo Action: Press
u
to undo the previous action.
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.
-
Enter Visual Block Mode: Press
Ctrl + v
to start visual block selection. Use the ↑ ↓ arrows or j k keys to extend the selection. - Insert Text: Press Shift-i to start inserting text.
-
Apply Changes: Press
Esc
to apply the changes to all selected lines.
5 - Run shell command directly within Vim
Did you know you can run shell commands directly from within Vim? Well, now you do 😉
-
In Normal Mode: Press
:!
followed by command to run, e.g: :!k get pods
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
Top comments (0)