1

I have a vimrc file. In that file i have the following two lines.

noremap gg :silent exec "!/home/john/gf.sh /home/john/guides/"<enter><C-L>

nmap gh tlet @"=system('perl /home/john/get_buffer.pl')<enter>P<enter>^

The first command runs script gf.sh. Which, long story short, prints a file selected by the user, into /tmp/file.

The second command, gh. Prints /tmp/file, into buffer @". And then prints that buffer, wherever I happen to be in Vim.

What I am trying to achieve, is to execute both of those things with a single command. I just don't understand how to achieve that. I have been trying for well over an hour.

How can I, achieve those two functionalities, at once?

5
  • Is the nmap on gh relevant? The tlet sequence looks a bit odd, so I can't tell if it's another mapping or just some keystrokes you want to have. As for combining, might be easier to use a function. – D. Ben Knoble Mar 5 at 13:54
  • well, now i type gg, run that script where i tell which file should be catted into /tmp/file. Then I have to make the rest happen, somehow. So by typing "gh" in normal mode, I run the buffer perl script and paste its output automatically. – john-jones Mar 5 at 14:02
  • Are you looking for :help :bar? It sounds like you wish to run two commands, one immediately after the other – husB Mar 5 at 14:05
  • Yes i want to run two commands, one after the other. But as you can see, the latter one needs to return its output into the buffer. – john-jones Mar 5 at 14:05
  • Ideally your .sh script would print out content to STDIN then you just do :put=systemlist('script.sh'). Other you just need to run your commands one after another, e.g. script.sh; cat /tmp/foo – Peter Rincker Mar 5 at 14:06
2

From the comments the OP wishes to execute multiple commands in succession. In particular, the commands silent exec ... followed by let @"= .... As D Ben Knoble suggests, this is a typical use case of a function.

function Foo()
  silent exec "!/home/john/gf.sh /home/john/guides/"
  redraw!
  let @"=system('perl /home/john/get_buffer.pl')
  normal! Pj^
endfunction

Then, one can call this function with a mapping

nnoremap gg :call Foo()<CR>
6
  • Thank you very much. I need to read up on some vimscript. – john-jones Mar 5 at 15:12
  • Glad to be of help! I should have mentioned that :normal xxx acts as though xxx was pressed in normal mode by the user. :help :normal will provide more details. – husB Mar 5 at 15:18
  • no wait, the function gets implemented, every time i run vim. i put that function in my vimrc file. – john-jones Mar 5 at 15:19
  • Yes, place both the function and mapping in your vimrc.... or am I missing something? – husB Mar 5 at 15:21
  • I changed the function name, into something that starts in a lowercase. Which caused an error. But its corrected now. – john-jones Mar 5 at 15:31

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.