-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.display-modes.vim
104 lines (99 loc) · 3.11 KB
/
init.display-modes.vim
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Functions to cycle/toggle display modes
" Toggle paste
function! TogglePaste()
if exists('b:old_signcolumn')
let &signcolumn = b:old_signcolumn
unlet b:old_signcolumn
elseif &signcolumn != 'no'
let b:old_signcolumn = &signcolumn
set signcolumn=no
endif
if exists('g:coc_running')
let g:coc_git_hide_blame_virtual_text = !&paste
" Clear the virtual text on the current line
call nvim_buf_clear_namespace(bufnr(), -1, line('.') - 1, line('.'))
endif
set invpaste
GitGutterToggle
call CycleEditDisplay(&paste)
set paste?
endfunction
" Cycle textwidth
function! CycleTextwidth()
if &textwidth == 0
set textwidth=78
elseif &textwidth == 78
set textwidth=98
elseif &textwidth == 98
set textwidth=118
else
set textwidth=0
endif
echo "textwidth=" . &textwidth
endfunction
" Toggle virtual movement, which is useful for editing tables
" By default, we have "block" set
function! ToggleVirtualEdit()
if &virtualedit == "block"
nnoremap r gr
nnoremap R gR
nnoremap k gk
nnoremap j gj
nnoremap <Down> j
nnoremap <Up> k
xnoremap <Down> j
xnoremap <Up> k
set virtualedit=all
set virtualedit?
else
nunmap r
nunmap R
nunmap k
nunmap j
nnoremap <Down> gj
nnoremap <Up> gk
noremap <Down> gj
xnoremap <Up> gk
set virtualedit=block
set virtualedit?
endif
endfunction
function! CycleEditDisplay(mode = '')
if a:mode == 'init'
let b:CycleEditDisplay_mode = 'default'
elseif a:mode == '1'
" This is 'paste'
let b:CycleEditDisplay_mode = 'none'
elseif a:mode == '0'
" This is 'nopaste'
let b:CycleEditDisplay_mode = 'default'
elseif exists('b:CycleEditDisplay_mode')
if b:CycleEditDisplay_mode == 'default'
let b:CycleEditDisplay_mode = 'full'
elseif b:CycleEditDisplay_mode == 'full'
let b:CycleEditDisplay_mode = 'none'
else
let b:CycleEditDisplay_mode = 'default'
endif
else
let b:CycleEditDisplay_mode = 'default'
endif
if b:CycleEditDisplay_mode == 'full'
set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»
set list number relativenumber cursorline showbreak=↪ cursorcolumn
set colorcolumn=+1,80,100,120
elseif b:CycleEditDisplay_mode == 'none'
set listchars=tab:→\ ,nbsp:␣,trail:·,precedes:«,extends:»
set nolist nonumber norelativenumber nocursorline showbreak= nocursorcolumn
set colorcolumn=
else
set listchars=tab:→\ ,nbsp:␣,trail:·,precedes:«,extends:»
set list number relativenumber cursorline showbreak=↪ nocursorcolumn
set colorcolumn=+1,80,100,120
endif
if a:mode != 'init'
echo 'b:CycleEditDisplay_mode=' . b:CycleEditDisplay_mode
endif
endfunction
call CycleEditDisplay('init')