-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc_lsp
227 lines (196 loc) · 6.7 KB
/
vimrc_lsp
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
set nocompatible
filetype indent off
call plug#begin('~/.config/nvim/plugged')
" -- oceanic-next
Plug 'mhartington/oceanic-next'
" -- rainbow
Plug 'luochen1990/rainbow'
let g:rainbow_active = 1
" -- indent detector
Plug 'luochen1990/indent-detector.vim'
" -- nerdtree
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" -- auto-pairs
Plug 'jiangmiao/auto-pairs'
let b:AutoPairs = {"(":")","{":"}","[":"]"}
let g:AutoPairsFlyMode = 0
let g:AutoPairsMultilineClose = 0
let g:AutoPairsSmartMode = 1
let g:AutoPairsMapCh = 0
" -- vim-lsp-cxx-highlight
Plug 'jackguo380/vim-lsp-cxx-highlight'
hi default LspCxxHlGroupEnumConstant ctermfg=176
hi default LspCxxHlGroupNamespace ctermfg=136
hi default LspCxxHlGroupMemberVariable ctermfg=81
hi default LspCxxHlSymFunctionVariable guifg=#26cdca
" -- lightline.vim
Plug 'itchyny/lightline.vim'
function! LspStatus() abort
let sl = ''
if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
let errors = luaeval("vim.lsp.diagnostic.get_count(vim.fn.bufnr('%'), [[Error]])")
let warnings = luaeval("vim.lsp.diagnostic.get_count(vim.fn.bufnr('%'), [[Warning]])")
let info = luaeval("vim.lsp.diagnostic.get_count(vim.fn.bufnr('%'), [[Hint]])")
if errors == 0 && warnings == 0
return 'ok'
endif
"'lsp'.errors . '!' . warnings
return 'lsp × '.errors . ' ! ' . warnings . ' i ' . info
else
return 'busy'
endif
return sl
endfunction
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'lspstatus', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'lspstatus': 'LspStatus',
\ },
\ }
" -- nvim-lspconfig
Plug 'neovim/nvim-lspconfig'
" -- nvim-compe
Plug 'hrsh7th/nvim-compe'
" -- lsp_signature.nvim
Plug 'ray-x/lsp_signature.nvim'
call plug#end()
lua << EOF
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
cfg = {
bind = true, -- This is mandatory, otherwise border config won't get registered.
-- If you want to hook lspsaga or other signature handler, pls set to false
doc_lines = 2, -- will show two lines of comment/doc(if there are more than two lines in doc, will be truncated);
-- set to 0 if you DO NOT want any API comments be shown
-- This setting only take effect in insert mode, it does not affect signature help in normal
-- mode, 10 by default
floating_window = true, -- show hint in a floating window, set to false for virtual text only mode
fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters
hint_enable = true, -- virtual hint enable
hint_prefix = "🐼 ", -- Panda for parameter
hint_scheme = "String",
use_lspsaga = false, -- set to true if you want to use lspsaga popup
hi_parameter = "Search", -- how your parameter will be highlight
max_height = 12, -- max height of signature floating_window, if content is more than max_height, you can scroll down
-- to view the hiding contents
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
handler_opts = {
border = "shadow" -- double, single, shadow, none
},
extra_trigger_chars = {} -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
-- deprecate !!
-- decorator = {"`", "`"} -- this is no longer needed as nvim give me a handler and it allow me to highlight active parameter in floating_window
}
require'lsp_signature'.on_attach(cfg)
end
-- ccls config
require'lspconfig'.ccls.setup {
on_attach = on_attach;
flags = {
debounce_text_changes = 150;
};
init_options = {
cache = {
directory = ".ccls_cache";
};
highlight = {
lsRanges = true;
};
};
}
-- Compe setup
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = true;
source = {
path = true;
nvim_lsp = true;
};
}
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col('.') - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
EOF
filetype plugin indent on
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
if has('python')
map <C-K> :pyf $HOME/.config/nvim/clang-format.py<cr>
imap <C-K> <c-o>:pyf $HOME/.config/nvim/clang-format.py<cr>
elseif has('python3')
map <C-K> :py3f $HOME/.config/nvim/clang-format.py<cr>
imap <C-K> <c-o>:py3f $HOME/.config/nvim/clang-format.py<cr>
endif
set termguicolors
set autoread
set completeopt-=preview
set cursorline
set syntax=on
set autoindent
set cindent
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set smarttab
set mouse=a
set number
set modelineexpr
colorscheme OceanicNext