-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnano.vim
259 lines (203 loc) · 4.96 KB
/
nano.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
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
set nocompatible
let s:hidden_all = 1
set noshowmode
set noruler
set laststatus=0
set noshowcmd
set hlsearch!
highlight EndOfBuffer ctermfg=0
set shortmess+=I
highlight StatusLine ctermfg=0 ctermbg=0 cterm=NONE
highlight StatusLineNC ctermfg=0 ctermbg=0 cterm=NONE
" Vim8 Specific
highlight StatusLineTerm ctermfg=0 ctermbg=0 cterm=NONE
highlight StatusLineTermNC ctermfg=0 ctermbg=0 cterm=NONE
let g:neoterm_autoscroll = 1
function! DrawLayout()
" Top bar buffer
split
let s:path = expand('<sfile>:p:h')
enew
resize 1
if has('nvim')
call termopen('python '.s:path.'/topbar.py')
else
terminal ++curwin python ./topbar.py
endif
" File display buffer
wincmd j
if @% == ""
enew
endif
" Bottom bar buffer
split
wincmd j
resize 3
enew
if has('nvim')
call termopen('python '.s:path.'/botbar.py')
execute "$"
else
terminal ++curwin python ./botbar.py
endif
" Go back to file display buffer
wincmd k
endfunction
set statusline=%#Normal#
" Trying to draw earlier messes things up
autocmd VimEnter * call DrawLayout()
" Handle resize
function! Resize()
wincmd j
resize 3
wincmd k
wincmd k
resize 1
wincmd j
endfunction
autocmd VimResized * call Resize()
" Disable command key
inoremap <silent> <esc> <nop>
" Hack to make arrow keys work with vim8
if has('nvim')
else
inoremap <esc>x <esc>x
endif
function! ForceExit()
qa!
endfunction
function! PromptSave()
if @% != ""
write
return 1
endif
let l:name = input('File Name to Write: ')
if (l:name == "")
return 0
else
execute "write! ".l:name
return 1
endif
endfunction
" Save file
nnoremap <C-O> :call PromptSave()<cr>
inoremap <silent> <C-O> <C-O>:call PromptSave()<cr>
function! OpenFile()
let l:name = input('File to insert [from ./]: ')
if (l:name == "")
else
execute "read ".l:name
endif
endfunction
" Read file
nnoremap <C-R> :call OpenFile()<cr>
inoremap <silent> <C-R> <C-O>:call OpenFile()<cr>
function! Exit()
if &mod
call inputsave()
let name = confirm('Save modified buffer? (Answering "No" will DISCARD changes.) ', "Yes\nNo\nCancel")
if (name==3)
elseif (name == 2)
call ForceExit()
else
if PromptSave() == 1
call ForceExit()
else
endif
endif
else
call ForceExit()
endif
endfunction
" Exit app
nnoremap <C-X> :call Exit()<cr>
inoremap <silent> <C-X> <C-O>:call Exit()<cr>
function! SearchFile()
let l:name = input('Search: ')
if (name == "")
else
call feedkeys("\<C-\>\<C-o>/".name."\<CR>")
endif
endfunction
" Search file
nnoremap <C-F> :call SearchFile()<cr>
inoremap <silent> <C-F> <C-O>:call SearchFile()<cr>
function! ShowInfo()
let curline = line('.')
let totalline = line('$')
let curcol = col('.')
let totalcol = col('$')
let lineperc = 100 * curline / totalline
let colperc = 100 * curcol / totalcol
echo "[ line ". curline . "/". totalline ." (".lineperc."%), col ".curcol. "/".totalcol." (".colperc."%) ]"
endfunction
" Show cursor info
nnoremap <C-C> :call ShowInfo()<cr>
inoremap <silent> <C-C> <C-O>:call ShowInfo()<cr>
function! GotoLine()
let name = input('Enter line number, column number: ')
if (name == "")
else
let newlist = split(name, "[ ,]")
let cnt = 0
let r = line(".")
let c = col(".")
for i in newlist
if i != ""
if cnt == 0
let r = i
elseif cnt == 1
let c = i
endif
endif
let cnt += 1
endfor
call cursor(r, c)
endif
endfunction
" Goto line, col
nnoremap <C-_> :call GotoLine()<cr>
inoremap <silent> <C-_> <C-O>:call GotoLine()<cr>
" Page up
nnoremap <C-Y> <PageUp>
inoremap <silent> <C-Y> <PageUp>
" Page down
nnoremap <C-V> <PageDown>
inoremap <silent> <C-V> <PageDown>
function! FirstLine()
call feedkeys("\<C-\>\<C-o>gg")
endfunction
function! LastLine()
call feedkeys("\<C-\>\<C-o>G")
endfunction
" First Line
nnoremap <A-\> :call FirstLine()<cr>
inoremap <silent> <A-\> <C-O>:call FirstLine()<cr>
" Last Line
nnoremap <A-/> :call LastLine()<cr>
inoremap <silent> <A-/> <C-O>:call LastLine()<cr>
" Search forward
inoremap <silent> <A-f> <C-O>n
" Match parenthesis
inoremap <silent> <A-]> <C-O>%
function! VisualMode()
call feedkeys("\<C-\>\<C-o>v")
endfunction
" Mark Text
nnoremap <C-^> :call VisualMode()<cr>
inoremap <silent> <C-^> <C-O>:call VisualMode()<cr>
" Copy Text
vnoremap <A-c> y
" Indent
inoremap <silent> <A-}> <C-O>>>
inoremap <silent> <A-{> <C-O><<
" Justify
inoremap <silent> <C-J> <C-O>gqk
" Col nav
inoremap <silent> <C-L> <C-o>l
inoremap <silent> <C-k> <C-o>h
" Word nav
inoremap <silent> <C-q> <C-o>b
inoremap <silent> <C-e> <C-o>w
" Start insert mode
startinsert