aboutsummaryrefslogtreecommitdiff
path: root/autoload/copy_linebreak.vim
blob: 8c81133fafd2d9ee8c88fdb10c001e85bc57638f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
" Enable copy-friendly linebreak options
function! copy_linebreak#Enable() abort
  setlocal nolinebreak linebreak?
  let s:colorcolumn_save = &colorcolumn
  setlocal colorcolumn=
  let s:cursorcolumn_save = &cursorcolumn
  setlocal nocursorcolumn
  let s:cursorline_save = &cursorline
  setlocal nocursorline
  let s:showbreak_save = &showbreak
  set showbreak=
  if exists('+breakindent')
    setlocal nobreakindent
  endif
endfunction

" Disable copy-friendly linebreak options
function! copy_linebreak#Disable() abort
  setlocal linebreak linebreak?
  if exists('s:colorcolumn_save')
    let &colorcolumn = s:colorcolumn_save
    unlet s:colorcolumn_save
  endif
  if exists('s:cursorcolumn_save')
    let &cursorcolumn = s:cursorcolumn_save
    unlet s:cursorcolumn_save
  endif
  if exists('s:cursorline_save')
    let &cursorline = s:cursorline_save
    unlet s:cursorline_save
  endif
  if exists('s:showbreak_save')
    let &showbreak = s:showbreak_save
    unlet s:showbreak_save
  endif
  if exists('+breakindent')
    setlocal breakindent<
  endif
endfunction

" Toggle copy-friendly linebreak options, using the current setting for the
" 'linebreak' option as the pivot
function! copy_linebreak#Toggle() abort
  if &linebreak
    call copy_linebreak#Enable()
  else
    call copy_linebreak#Disable()
  endif
endfunction