Let’s explore a few different ways to run commands in our terminal from the comfort of neovim. Trust me, it’s cooler than it sounds! 😎
Here’s a list of commands that I use all the time (and you should too!).
|
|
Hands-on
Hey! This is my absolute favorite command ever! I use it all the time when I’m writing docs or README files because, let’s face it - who wants to manually copy-paste code outputs? Not me! 😅 Instead of doing things the boring way, I use this neat little trick to get things done quickly. Plus, it’s super handy when you want to format text using other tools too like sql queries!
|
|
And check out what happens:
|
|
See what happened there? Instead of switching back and forth between your
terminal and Vim (so annoying, right?), we just ran the ls
command right from
Vim! Pretty neat, huh?
When we use :.!sh
, Vim runs the current line as a shell command and shows us
what happened. It’s like having a mini-terminal inside your editor - how cool
is that?
This is super handy when you’re writing docs or just need to quickly check something without leaving Vim. No more alt-tabbing between windows like a maniac!
Think of it as your editor being your personal assistant - “Hey Vim, could you run this command for me?” And boom! There’s your output, right where you need it.
Simple, right? And trust me, once you start using this, you’ll wonder how you ever lived without it! 🎯
Run a command without replacing the buffer
Let’s see another example where I want to peek at the output without messing up what’s already in my buffer (because hey, sometimes we just want to look, not touch! 😉)
|
|
So what’s happening here? Well, instead of replacing our precious ls
command
with its output (like we did before), we’re just taking a quick look at what’s
in our directory. It’s like opening your fridge to check what’s inside without
actually grabbing anything! 🚀
The command :.w !sh
is basically telling Vim: “Hey buddy, run this line for
me, but don’t mess with my text, just show me what happens!” And Vim’s like
“Sure thing, here’s your file list!”
After it shows you all your files and folders, it politely waits for you to press ENTER before going back to business. How nice is that? 😊
Now, Think out of the box
Hey, imagine you’re writing a Python function (like the one below) and you get
stuck - maybe you forgot a module name (we’ve all been there! 🤪). Instead of
doing the whole open-new-terminal-and-copy-paste dance, you can use this cool
:w !python -c "$(cat)"
trick:
- grab those first 6 lines of code below.
- type
:w !python -c "$(cat)"
(I know, it looks weird, but trust me!) - Boom! You’re done! 🎉
|
|
Here’s another fun one:
|
|
Summary
We saw a bunch of cool ways to run commands from neovim, and I bet you can come up with even more awesome tricks than what we covered here! Go ahead and play around with neovim’s superpowers - before you know it, you’ll be zipping through your code like a Jedi Master! 🚀✨