forked from mpkopec/nvim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-settings.vim
More file actions
283 lines (233 loc) · 6.2 KB
/
Copy pathbasic-settings.vim
File metadata and controls
283 lines (233 loc) · 6.2 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
" TODO Add folding and divide the file into logical blocks
" Colorscheme handling
set termguicolors
augroup color_overrides
autocmd!
autocmd ColorScheme carbonized-dark highlight CursorLine guibg=#3b3b37 gui=underline
augroup END
colorscheme carbonized-dark
" Filetype plugin
filetype on
" Enable mouse in normal and visual mode. Visual mode is included to fix a
" race condition where a buffered terminal mouse-release event from a
" focus-click is misinterpreted as <Esc>, aborting the visual selection.
" With mouse=nv Neovim properly consumes these events; the <nop> mappings in
" basic-maps.vim neutralise the side-effect of click-to-reposition in visual.
set mouse=nv
" Show line numbers properly
set number
set relativenumber
" Switching between buffers without saving
set hidden
" Taller commandline
set cmdheight=2
" Highlight current line
set cursorline
" Turn on the wild menu
set nowildmenu
" By default, ignore case
set ignorecase
" Makes search act like search in modern browsers
set incsearch
" For regular expressions turn magic on
set magic
" Set line wrapping and its navigation
set nowrap linebreak
set showbreak=…
" Don't redraw while executing macros (good performance config)
set lazyredraw
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=5
" No swap, no backup
set noswapfile
set nobackup
" 1 tab == 2 spaces
" except for the files in which it is overriden in the filetype plugin
set shiftwidth=2
set tabstop=2
set sts=2
set expandtab
" Always show the status line
set laststatus=2
" Show and wrap at 80th column
set colorcolumn=88
set textwidth=88
" Wait for 600ms for the next key in the mapping
set timeoutlen=600
" Formatoptions
set formatoptions-=t
set formatoptions+=cro/qn1j
" Folding
set foldlevel=1
set foldcolumn=2
function! CloseFoldsInnerFirst() abort
let lnum = line('.')
let L = foldlevel(lnum)
if L <= 0
return
endif
" Helper: move left boundary across closed folds correctly
let s = lnum
while s > 1
let prev = s - 1
" If prev is inside a closed fold, jump to that fold's start
let fc = foldclosed(prev)
if fc != -1
" If that closed fold is still within our target level, include it and continue
if foldlevel(fc) >= L
let s = fc
continue
else
break
endif
endif
if foldlevel(prev) >= L
let s = prev
else
break
endif
endwhile
" Helper: move right boundary across closed folds correctly
let e = lnum
let last = line('$')
while e < last
let nxt = e + 1
" If nxt is inside a closed fold, jump to that fold's end
let fc = foldclosed(nxt)
if fc != -1
let fe = foldclosedend(nxt)
" If that closed fold belongs to our target fold, include it wholly and continue
if foldlevel(fc) >= L
let e = fe
continue
else
break
endif
endif
if foldlevel(nxt) >= L
let e = nxt
else
break
endif
endwhile
" Collect fold starts inside [s,e], skipping over already-closed children
let starts = []
let i = s
while i <= e
" Skip closed folds entirely (they're already collapsed; also avoids foldlevel()=0 inside)
let fc = foldclosed(i)
if fc != -1
let i = foldclosedend(i) + 1
continue
endif
let prevL = (i > 1 ? foldlevel(i - 1) : 0)
let curL = foldlevel(i)
" A fold "starts" when level increases; only consider folds at/under current depth
if curL > prevL && curL >= L
call add(starts, [curL, i])
endif
let i += 1
endwhile
" Deepest first; for same depth, bottom-up
call sort(starts, {a,b -> a[0] == b[0] ? (b[1] - a[1]) : (b[0] - a[0])})
" Close each fold using :foldclose (no !) semantics via zc
let view = winsaveview()
try
for item in starts
let ln = item[1]
if foldclosed(ln) == -1
call cursor(ln, 1)
silent! normal! zc
endif
endfor
finally
call winrestview(view)
endtry
endfunction
function! CloseFoldsInnerFirst() abort
let lnum = line('.')
let L = foldlevel(lnum)
if L <= 0
return
endif
" Helper: move left boundary across closed folds correctly
let s = lnum
while s > 1
let prev = s - 1
" If prev is inside a closed fold, jump to that fold's start
let fc = foldclosed(prev)
if fc != -1
" If that closed fold is still within our target level, include it and continue
if foldlevel(fc) >= L
let s = fc
continue
else
break
endif
endif
if foldlevel(prev) >= L
let s = prev
else
break
endif
endwhile
" Helper: move right boundary across closed folds correctly
let e = lnum
let last = line('$')
while e < last
let nxt = e + 1
" If nxt is inside a closed fold, jump to that fold's end
let fc = foldclosed(nxt)
if fc != -1
let fe = foldclosedend(nxt)
" If that closed fold belongs to our target fold, include it wholly and continue
if foldlevel(fc) >= L
let e = fe
continue
else
break
endif
endif
if foldlevel(nxt) >= L
let e = nxt
else
break
endif
endwhile
" Collect fold starts inside [s,e], skipping over already-closed children
let starts = []
let i = s
while i <= e
" Skip closed folds entirely (they're already collapsed; also avoids foldlevel()=0 inside)
let fc = foldclosed(i)
if fc != -1
let i = foldclosedend(i) + 1
continue
endif
let prevL = (i > 1 ? foldlevel(i - 1) : 0)
let curL = foldlevel(i)
" A fold "starts" when level increases; only consider folds at/under current depth
if curL > prevL && curL >= L
call add(starts, [curL, i])
endif
let i += 1
endwhile
" Deepest first; for same depth, bottom-up
call sort(starts, {a,b -> a[0] == b[0] ? (b[1] - a[1]) : (b[0] - a[0])})
" Close each fold using :foldclose (no !) semantics via zc
let view = winsaveview()
try
for item in starts
let ln = item[1]
if foldclosed(ln) == -1
call cursor(ln, 1)
silent! normal! zc
endif
endfor
finally
call winrestview(view)
endtry
endfunction
noremap <silent> zC :call CloseFoldsInnerFirst()<CR>