Is it possible to improve this vim mapping that repeats a command on the command line?

So here's my display:

nnoremap <cr> :nnoremap <lt>cr> :w!<lt>cr>:!tmux send-keys -t :1.1 "py.test --cov=." C-m <lt>cr><lt>cr><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left>

      

It's pretty cool. What it does is when I first start a vim session (or after restarting vimrc) and press enter, I can immediately type in the name of the tmux session I am in and press Enter again. Assuming I am editing my files in the zero pane of window 1 and I have a tmux separator (horizontal, in my typical case). Subsequent attempts to enter normal mode keep my active file and run my py.test tests in another window. This means that I can technically continue coding before my tests run out. I forgot who I first got this idea with, but h / t this guy.

Anyway, you no doubt noticed that there is a lot in this mapping <left>

, because I would like to run a command to set the session name. But there might also be times when I edit my code in another window or something, or I need to change my pytest command or something, so I still want to be able to make those changes.

Is there a way to improve this mapping? Maybe this is something completely different?

+3


source to share


1 answer


Your original mapping creates another mapping command and uses it <Left>

to insert the cursor at the correct position for completion and subsequent execution.

An alternative to this would be to define a custom command (for example :TestInSession

) that takes variable parts as argument (s). Then, your original mapping can just build another mapping, leaving the cursor at the end :TestInSession

, and you'll have less command line clutter and easier editing at the end.



If you need the ability to reconfigure a different mapping, you can define an alternate original mapping that will not be overwritten, for example:

:nnoremap <Leader><cr> :nnoremap <lt>cr> ...

      

+1


source







All Articles