Save file and run tests on Enter in Vim
1 min readSep 1, 2019
TL:DR
:nmap <CR> :w<CR> :!{your_test_command_here}<CR>
example where testfile is test/bottles_test.rb
:nmap <CR> :w<CR> :!ruby test/bottles_test.rb<CR>
The first time I saw this was in one of Gary Bernhardt’s videos and I was so enamoured with it.
When in normal mode in Vim hitting the Enter key will save your file and run your tests. This small addition to how I write code has made my life so much better.
Here’s a gif of me saving a file and running tests by hitting enter. My keystrokes appear in the bottom left hand corner.