2

I am trying to combine several commands into a single mapping - (i) open a split window with a height of 15 lines, (ii) open an existing file in that window, (iii) move to the last line and char of that file, (iv) create a new blank line thereafter, (v) and enter insert mode.

This achieves (i) and (ii):

nnoremap <leader>n :15sp +$ $HOME/_notes/n0w<cr>

I've tried to extend upon it with:

nnoremap <leader>n :15sp +$A $HOME/path/to/file<cr>
nnoremap <leader>n :15sp +$ +A $HOME/path/to/file<cr>
nnoremap <leader>n :15sp +A +$  $HOME/path/to/file<cr>
nnoremap <leader>n :15sp +GA  $HOME/path/to/file<cr>

which has given the respective results:

E464: ambiguous use of user-defined command +$A
+A $/HOME/path/to/file [NEW DIRECTORY]
+S $/HOME/path/to/file [NEW DIRECTORY]
E492: not an editor command

I've also tried similar variations with +startinsert and +normal but not getting the desired result.

Would greatly appreciate help.

1

No need to embed commands in the split. You can use multiple commands in a single mapping.

nnoremap <leader>n :15sp $HOME/_notes/n0w<cr>Go

After the split command is submitted with <cr>, this being nmap we can just specify Normal mode commands. Specifically, G for step (iii) (go to end of file) and o for steps (iv) and (v) (add a new line and enter Insert mode).

That's it.

(An assist to @JürgenKrämer for a shorter command and subsequent revelation that I have config/plugin issues.)

| improve this answer | |
  • Having said that about norm, Go is basically $put ='', right? – D. Ben Knoble Aug 27 '19 at 4:10
  • 2
    Why use exe, norm and startinsert at all? nnoremap <leader>n :15sp $HOME/_notes/n0w<cr>Go works just as well. – Jürgen Krämer Aug 27 '19 at 6:32
  • @JürgenKrämer Hmmm. Because that doesn't leave me in Insert mode. Maybe somethings wack here. Since I had to use startInsert I just kept it verbose but if I'm just bugged and don't need it then I agree that what you propose is much better. Looking into it. Thanks. – B Layer Aug 27 '19 at 9:56
  • Just disabled all plugins and don't need startInsert. Wth?! I'm updating my answer b4 anything else. Thanks again. – B Layer Aug 27 '19 at 9:59
  • Thank you. @BLayer answer has the brevity I had hoped for. Changed the ending Go for '<cr>GA<cr>` ,as the former moved the cursor one place in from the start of the line. – user2962912 Aug 27 '19 at 11:24

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.