readonly - Vim: sync read-only status between buffer and file on disk -
i'm working perforce , files in client read-only default. when i'm browsing source code in vim buffers marked read-only (may not accurate wording: can edit content cannot save without '!'). @ point i'm starting edits , discover have checkout file in perforce. have 'nice' command that:
command pe !p4 edit %
but after finishes vim offers me choice either:
- load content disk (which don't want do, because i'll lost edits).
- or keep buffer is, preserves read-only mode (which don't want either).
of course can change ro manually doing :set noro
want avoid that. i've added pe
command above, doesn't check real status of file, seems little bit dangerous:
command pe !p4 edit % | set noro
what want "true" synchronization of read-only state between file on disk , buffer in vim.
upd: mysteriously, last version works out of box -- if p4 edit
fails ro state on buffer not removed. no ideas how working...
vim has filewritable()
function query file's access state, why don't use that?
command pe execute '!p4 edit %' | let &readonly = !filewritable(expand('%'))
Comments
Post a Comment