6

I have a very long vimrc mapping to deal with for example

nnoremap <space>e :exe "!tmux send-keys -t.- 'cd $TEST' Enter"<Cr> :exe "!tmux send-keys -t.- 'source $TEST_NT/bin/activate' Enter"<Cr>

how can I break this long line into several short lines so that I can see everything in one screen

Something like the following style:

 nnoremap <space>e 
     :exe "!tmux send-keys -t.- 'cd $TEST' Enter"<Cr> 
     :exe "!tmux send-keys -t.- 'source $TEST_NT/bin/activate' Enter"<Cr> 
8

You can split your long line by inserting a Vim line continuation character (backslash) at the beginning of each continued line:

nnoremap <space>e 
       \ :exe "!tmux send-keys -t.- 'cd $TEST' Enter"<Cr> 
       \ :exe "!tmux send-keys -t.- 'source $TEST_NT/bin/activate' Enter"<Cr>

This is explained here: :help line-continuation. You should note the comment on leading whitespace, i.e.:

All leading whitespace characters in the line before a backslash are ignored.
Note however that trailing whitespace in the line before it cannot be inserted freely; it depends on the position where a command is split up whether additional whitespace is allowed or not.

  • 1
    You beat me by a couple of seconds. If you add the VimDoc link, then I'll delete my answer. – Karl Yngve Lervåg Sep 6 '18 at 6:45
  • 1
    @KarlYngveLervåg: Hmm, hmm. I am reluctant to add a link to online documentation. If I did that now, I would have to do that forever, and I simply dread the effort. I expect you to answer "fair enough" ;-). – nst0022 Sep 6 '18 at 10:57
  • 1
    I saved you the work. – Karl Yngve Lervåg Sep 6 '18 at 11:40
  • 1
    Fair enough :-). – nst0022 Sep 6 '18 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.