2

enter image description here

I am currently using tmux to have two terminals on the left and vim on the right. One terminal is running Django server, and the other one is for general usage.

I am trying to find out if I can ditch tmux and use vim/neovim sessions as a solution.

Is there a way for a vim session to automatically change to a specific directory, enable a virtualenv and start the server as I am currently doing with tmux?

  • Your title and question text seem different. Are you trying to save the terminal state like tmux's 'detach?' Or, to just re-run the same command at vim start-up? – Mass May 16 '18 at 18:02
  • @Mass When I rerun the tmux session it keeps the state of the django server running etc. I am asking if there's a way to save that state in the vim session, so when I come back and source it will automatically do all the things I said above (change working dir, enable virtualenv, start the server). – panosl May 16 '18 at 18:33
  • I believe vim sessions can store the pwd, but to enable virtualenv/launch a server would require shelling out and is probably more easily accomplished using a plugin (whether one out there or a simple script you write yourself) – D. Ben Knoble May 16 '18 at 18:43
1

According to :h terminal-session it will relaunch a terminal buffer with a session by running the command which was supplied to :terminal to start with or you can modify it via term_setrestore().

Is there a way for a vim session to automatically change to a specific directory, enable a virtualenv and start the server as I am currently doing with tmux?

I do not use :terminal or such a setup as you do, but I would hazard a guess that you could create a shell/python script which would change your current directory, enable virtualenv, and start your server. Combine it with a custom Vim command to execute it:

command! StartServer execute "terminal start-server.sh " . resolve(expand('%:h'))

In theory doing something like this would allow it restore. That being said if you now have a nice command to start your server, you may not care as much if it restores as you can easily access it.

For more help see:

:h terminal
:h term_setrestore
:h :execute
:h resolve()
:h expand()
:h :terminal

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.