I need to refactor some paragraphs from an article.
I would like to have:
- One split with the original version (not editable)
- Another split with the document to edit
Is it possible?
Here is a simpler solution (inspired by the other one)
:let ft=&ft
:vertical new
:setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile
:read ++edit #
:silent 0d_
:setlocal nomodifiable
:execute "set ft=" . ft
:wincmd p
It:
nomodifiable
to :setlocal...
, you can't execute read ++edit #
. It throws that modifiable is off
To edit safely a file you could do:
:set noreadonly
)Diff
custom command to compare with the version saved on disk (see bottom of the question for its definition):w!
[optional]function! Diff(spec)
vertical new
setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile
let cmd = "++edit #"
if len(a:spec)
let cmd = "!git -C " .. shellescape(fnamemodify(finddir('.git', '.;'), ':p:h:h')) .. " show " .. a:spec .. ":#"
endif
execute "read " .. cmd
silent 0d_
diffthis
wincmd p
diffthis
endfunction
command! -nargs=? Diff call Diff(<q-args>)
Remark: If you don't want the two buffer to be compared we can simplify the solution (by dropping the diffthis
calls)
modifiable
is a buffer characteristic. But I'm not sure I understand your workflow. Could elaborate more on how you plan to use the two splits? Do you want to be able to compare your modification with the original without saving it?