Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. class open_in_vim(Command):
  2. """:open_in_vim <filename>
  3.  
  4. Opens a file in a new vim tab, if vim is not already running, opens vim.
  5. """
  6.  
  7. def execute(self):
  8. if self.arg(1):
  9. _open(self.rest(1))
  10. else:
  11. _open(self.fm.thisfile.path)
  12.  
  13.  
  14. def _open(file_name):
  15. regex = re.compile('(^|/)*nvim$')
  16. vim_pane = filter(regex.search, check_output(['tmux', 'list-panes', '-F', ''#{pane_id} #{pane_current_command}'']))[0].split(' ')[0]
  17.  
  18. if vim_pane:
  19. check_output(['tmux', 'send-keys', '-t', vim_pane, 'Escape', 'Escape', ':tab', 'Space', 'drop', 'Space', file_name, 'Enter'])
  20. else:
  21. check_output(['tmux', 'split-window', '-h', '-p', '75', '-c', ''#{pane_current_path}'', '"nvim {}"'.format(file_name)])
  22.  
  23.  
  24. def tab(self, tabnum):
  25. return self._tab_directory_content()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement