Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " for screen use
- " opened in another screen? lets not play where's waldo anymore!
- " this will politely tell me which screen's window it is open in so that I may
- " go close it if I want, but still provide me the normal options
- " this may need paths and command tweaked for your flavor of linux, but it
- " is a great start for most.
- "
- augroup NoSimultaneousEdits
- autocmd!
- autocmd SwapExists * :call PrintScreenWindow()
- augroup END
- "autocmd Bufwritepre,filewritepre * :set fileformat=unix
- set ff=unix
- function! PrintScreenWindow ()
- let fname = expand("%:p")
- " fix fname here, remove the path and leave only the filename/basename
- let fname = fnamemodify(fname, ':t')
- " you might have to fix your path to lsof
- let my_command = "/usr/sbin/lsof | grep '" . fname . ".swp' | grep " . $USER . " | sed -n 's/^vim\\? \\+\\([0-9]\\+\\).*$/\\1/p' "
- let result = substitute(system(my_command), '\n','','')
- if result
- let my_cmd2 = "cat /proc/" . result . "/environ | xargs -0 echo | sed -n 's/.*WINDOW=\\([0-9]*\\).*/\\1/p' "
- let res2 = substitute(system(my_cmd2), '\n','','')
- if res2 || res2 == '0'
- echo 'This file is already opened in window: ' . res2
- else
- echo "command failed: " . my_cmd2
- endif
- else
- echo my_command . " : cmd failed"
- endif
- endfunction
Add Comment
Please, Sign In to add comment