Skip to content

Instantly share code, notes, and snippets.

@coot
Created December 29, 2016 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coot/12d9d1122447cd7aad5376f7f2a6544f to your computer and use it in GitHub Desktop.
Save coot/12d9d1122447cd7aad5376f7f2a6544f to your computer and use it in GitHub Desktop.
A script which lists all buffers in all running vim instances
#!/usr/bin/python
"""
The %prog (vim buffer ls) lists files hosted on all running vim servers. Star
before file indicates that the buffer is loaded.
"""
"""
Author: Marcin Szamotulski
"""
"""
Copyright Statement:
bls is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any
later version.
bls is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with bls. If not, see <http://www.gnu.org/licenses/>.
"""
import subprocess, re, sys, signal
from optparse import OptionParser
usage = "%prog"
parser = OptionParser(usage=usage, description=__doc__, epilog="Author: Marcin Szamotulski, 2011")
(options, args) = parser.parse_args()
class TimeoutException(Exception):
pass
servers=subprocess.Popen(['gvim', '--serverlist'], stdout=subprocess.PIPE ).communicate()[0].decode()
server_ls=list(filter(lambda s: s != "", servers.split("\n")))
def print_server(server):
def timeout_handler(signum, frame):
raise TimeoutException()
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(1) # send a SIGALRM after 1 second,
# this function is only available on Unix,
# signal.alarm() works only with seconds.
try:
print("*** "+server+" ***")
cmd=['vim', '--servername', server, '--remote-expr \"vim#ls()\"']
subprocess.call(['vim', '--servername', server, '--remote-expr', 'vim#ls()'])
except TimeoutException:
print("--- "+server+" --- is not responding")
if len(server_ls) == 0:
print("no vim/gvim instance is running")
sys.exit(0)
for server in server_ls:
if server != '':
print_server(server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment