I want vim to launch rails console(it's like relp) within terminal windows when vim is launched on my project directory. To launch rails console, I need to run three commands like below and it's tedious.

vagrant up # launch virtual server. 
ssh xxxx@example.hoge # ssh into virtual server
cd xxxx/xxxx/ && bundle exec rails c # launch rails console. It runs on virtual server.

I could achieve this by adding some vimscript to vimrc.

  1. run vagrant up by jobstart
  2. :term in on_exit handler
  3. send the commands to the terminal by chansend in on_exit handler

But this approach has a problem. In this way :term create a window on the foreground. so if I edit files, they're hidden when :term is executed.

How could I create a terminal window in the background?


I can work around this problem like this.

vsplit | term | close

See the function term_start(); it creates a terminal window, which you can then :hide. I suppose :terminal followed by :hide also works. :vsplit should not be necessary, as :terminal and term_start() both create their own windows. If you want to avoid messing with the layout of the current tab, :tab terminal followed by :tabclose might be cleaner.

  • Thanks for your reply. Sorry I didn't mention I use neovim. If I used vim, this solution is perfect! Jan 11 at 7:11
  • Everything except term_start() should be portable between the two. IIRC neovim’s :terminal just opens a new terminal window…
    – D. Ben Knoble
    Jan 11 at 13:34

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.