-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvim_script.vim
More file actions
177 lines (147 loc) · 5.01 KB
/
vim_script.vim
File metadata and controls
177 lines (147 loc) · 5.01 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
" https://vonheikemen.github.io/devlog/tools/configuring-neovim-using-lua/
" put vim scirpts here, which is sourced by keymaps.lua
" for clipboard, https://zhuanlan.zhihu.com/p/419472307
if executable('clipboard-provider')
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
\ '+': 'clipboard-provider copy',
\ '*': 'clipboard-provider copy',
\ },
\ 'paste': {
\ '+': 'clipboard-provider paste',
\ '*': 'clipboard-provider paste',
\ },
\ }
endif
" cppman https://raw.githubusercontent.com/gauteh/vim-cppma
" This is essentially an adapted version of the cppman.vim script that is
" included with cppman. Authored by Wei-Ning Huang (AZ) <aitjcize@gmail.com>
" and others.
"
"
" This program is free software; you can redistribute it and/or modify
" it under the terms of the GNU General Public License as published by
" the Free Software Foundation; either version 3 of the License, or
" (at your option) any later version.
"
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
"
" You should have received a copy of the GNU General Public License
" along with this program; if not, write to the Free Software Foundation,
" Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
function! BackToPrevPage()
if len(g:stack) > 0
let context = g:stack[-1]
call remove(g:stack, -1)
let g:page_name = context[0]
call s:reload()
call setpos('.', context[1])
end
endfunction
function! s:reload()
setl noro
setl ma
echo "Loading..."
exec "%d"
exec "0r! cppman --force-columns " . (winwidth(0) - 2) . " '" . g:page_name . "'"
setl ro
setl noma
setl nomod
endfunction
function! s:Rerender()
if winwidth(0) != s:old_col
let s:old_col = winwidth(0)
let save_cursor = getpos(".")
call s:reload()
call setpos('.', save_cursor)
end
endfunction
function! LoadNewPage()
" Save current page to stack
call add(g:stack, [g:page_name, getpos(".")])
let g:page_name = expand("<cword>")
setl noro
setl ma
call s:reload()
normal! gg
setl ro
setl noma
setl nomod
endfunction
function! s:Cppman(page)
vertical bo new
setlocal buftype=nofile
setlocal bufhidden=delete
setlocal noswapfile
let g:page_name = a:page
setl nonu
setl nornu
setl noma
noremap <buffer> q :q!<CR>
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
syntax on
syntax case ignore
syntax match manReference "[a-z_:+-\*][a-z_:+-~!\*<>]\+([1-9][a-z]\=)"
syntax match manTitle "^\w.\+([0-9]\+[a-z]\=).*"
syntax match manSectionHeading "^[a-z][a-z_ \-:]*[a-z]$"
syntax match manSubHeading "^\s\{3\}[a-z][a-z ]*[a-z]$"
syntax match manOptionDesc "^\s*[+-][a-z0-9]\S*"
syntax match manLongOptionDesc "^\s*--[a-z0-9-]\S*"
syntax include @cppCode runtime! syntax/cpp.vim
syntax match manCFuncDefinition display "\<\h\w*\>\s*("me=e-1 contained
syntax region manSynopsis start="^SYNOPSIS"hs=s+8 end="^\u\+\s*$"me=e-12 keepend contains=manSectionHeading,@cppCode,manCFuncDefinition
syntax region manSynopsis start="^EXAMPLE"hs=s+7 end="^ [^ ]"he=s-1 keepend contains=manSectionHeading,@cppCode,manCFuncDefinition
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_man_syn_inits")
if version < 508
let did_man_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink manTitle Title
HiLink manSectionHeading Statement
HiLink manOptionDesc Constant
HiLink manLongOptionDesc Constant
HiLink manReference PreProc
HiLink manSubHeading Function
HiLink manCFuncDefinition Function
delcommand HiLink
endif
""" Vim Viewer
setl mouse=a
setl colorcolumn=0
let g:stack = []
noremap <buffer> K :call LoadNewPage()<CR>
map <buffer> <CR> K
map <buffer> <C-]> K
map <buffer> <2-LeftMouse> K
noremap <buffer> <C-o> :call BackToPrevPage()<CR>
map <buffer> <RightMouse> <C-o>
let b:current_syntax = "man"
let s:old_col = 0
autocmd VimResized * call s:Rerender()
" Open page
call s:reload()
exec "0"
endfunction
command! -nargs=+ Cppman call s:Cppman(expand(<q-args>))
setl keywordprg=:Cppman
" nnoremap <leader>fw :execute 'Telescope find_files default_text=' . "'" . expand('<cword>')<cr>
nnoremap <leader>fw :execute 'Telescope live_grep default_text=' . expand('<cword>')<cr>
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
command! TrimWhitespace call TrimWhitespace()