0

When I'm coding in nvim, I find myself often wanting to open a job monitoring command line tool my company uses on the side. Basically I want to map a keybinding to the action :open a neovim terminal window, run a sequence of commands, resize/rename/reposition the window.

I think this should be easy to do, but I'm new to writing neovim plugins and find the API pretty confusing. I've tried Googling around, but it would be helpful if someone could point out useful functions or a link to a similar plugin on Github so I can look through the code (I think it's easiest to learn by example).

romainl
  • 186,200
  • 21
  • 280
  • 313

1 Answers1

0

If keeping your workspace(windows size / opened files) arrangement
even after leaving vim is what you want, you do not need plugins for that.

Option 1: Session

'Session' feature of vim (:h session) is what you're looking for.

:mks! filename to save current session to filename.
:so filename to load that session and restore window size / opened files.
If you launch vim with vim -S filename, it'll :so filename on startup.

The default value of filename is Session.vim on all 3 cases.

TL;DR

Given that working directory of your shell is already at the project directory,

  • :mks! to save current workspace.
  • Use vim -S to launch vim and automatically restore last workspace.

Option 2: Job control

If you're on linux, you can use job control feature of the console.
Pressing Ctrl+Z will 'suspend' your current process - which in this case, vim.
Vim will be put in the background and you'll get your command prompt back.
After you're done with using command line tools,
run command fg to bring vim back to the foreground.

TL;DR

  • Ctrl+Z to put vim in the background .
  • fg<Enter> to bring vim back to foreground.
WieeRd
  • 792
  • 1
  • 7
  • 17
  • `vim -S` works find for Neovim as well, just do `nvim -S`. Also there is a Option 3, which is using terminal buffer. It's basically an embedded console inside vim. – WieeRd Apr 11 '22 at 17:54