Skip to content

Instantly share code, notes, and snippets.

@ricardofalasca
Created July 30, 2020 16:16
Show Gist options
  • Save ricardofalasca/70cf4a34964f441ba2a4bb3c23d17db3 to your computer and use it in GitHub Desktop.
Save ricardofalasca/70cf4a34964f441ba2a4bb3c23d17db3 to your computer and use it in GitHub Desktop.
How to close vim externally on Linux (devpts)
#!/usr/bin/env python3
pts = 15 # set the pts your vim instance is running
""" Run this as super user """
import os, fcntl, termios
fd = os.open(f'/dev/pts/{pts}', os.O_RDWR)
vim_cmd = '\033:wqa!\n'
for i in vim_cmd:
fcntl.ioctl(fd, termios.TIOCSTI, i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment