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:

  1. load content disk (which don't want do, because i'll lost edits).
  2. 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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -