Skip to content

Commit

Permalink
fix(tmp buf): Keep clipboard contents
Browse files Browse the repository at this point in the history
If Vim synchronizes contents in the un-named register and the
system clipboard via setting the `clipboard` option, making a
temporary buffer breaks the clipboard contents because it
overwrites the un-named register with original file contents.
So keep the contents by storing into a temporary variable and
restoring it after file type detection.
  • Loading branch information
alker0 committed Apr 1, 2024
1 parent a35b426 commit ea748af
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions autoload/chezmoi/filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,18 @@ function! s:run_default_detect(detect_target) abort
let evignore_save = &eventignore
let bufhidden_save = &bufhidden
let l:cpo_save = &cpo
let l:clipboard_save = &clipboard
let l:reg_content_save = getreg('"')
let l:reg_type_save = getregtype('"')

let bufnr_org = bufnr()

try
set eventignore=all

" Disable clipboard
set clipboard=

" Enable to move to other buffer.
set bufhidden=hide

Expand Down Expand Up @@ -214,6 +220,8 @@ function! s:run_default_detect(detect_target) abort
let &eventignore = evignore_save
let &bufhidden = bufhidden_save
let &cpo = l:cpo_save
call setreg('""', l:reg_content_save, l:reg_type_save)
let &clipboard = l:clipboard_save
endtry
else
execute 'doau filetypedetect BufRead ' . fnameescape(a:detect_target)
Expand Down

0 comments on commit ea748af

Please sign in to comment.