Quick post! Hopefully useful as it's been for me.
Have you ever been caught in the loop of editing a file in vim (or any other editor), and then testing your changes quickly from the command line, and doing it over and over for dozens of times?
I have, many times. Sometimes you don't even need to do that. For example, vim allows you to invoke a command line tool with :!program-name
.
Still, sometimes one falls into that vicious edit-run-edit cycle without thinking too much. If that's your case, here's a simple tip you can try. Note: you need to be on the console for this to work.
When you're done with your changes, save the file and then use CTRL + Z
to suspend the editor process and drop to the command line, where you will have your command waiting for you already.
Run the command, and then use fg
to return to the editor process exactly as you left it.
The edit-run cycle will be a lot faster.
fg
(foreground) and bg
(background) are useful commands to "control the flow" of the processes you launch from the command line.
Top comments (7)
I prefer to have a second shell open below my editor with file watch running. Just need to save and then my tests will run. There's also an embedded terminal that you can access via
:terminal
, if you aren't using tmux.Is terminal now available in Vim? I've been using Neovim for the past couple of years which has this feature, but I hardly ever use it for fear of committing to muscle memory when it isn't available on remote machines that I work on.
I currently do as Cosimo does but also employ the vim-test plugin for one particular enhancement -- running a specific test in a test file so that I don't have to eyeball the line or test name and provide it as a suffix to my test command.
However, I am curious about the test automation with file watch. How do you have this configured?
Yep, not sure if its the same as neovim though. Personally as I said though, I just use tmux.
Yeah, I'm a huge tmux user as well. I have like 8 projects/repos open at any time (like dotfiles and TIL) that I often make updates to and I love resurrect for the few times that I have to restore those sessions on restart.
Could you share how you've configured file watch to automate test runs?
I use mocha as my test framework, the command line tool has a watch option.
Yes, that is also a great solution I use. Thanks for mentioning it!
Funnily enough I shared this exact tip with someone else on here a moment ago on Dev.to! :D