-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
224 lines (180 loc) · 5.68 KB
/
init.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
" TODO: Migrate entire script into lua
"
set exrc
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab
set smartindent
set relativenumber
set number
set nohlsearch
set incsearch
set hidden
" Better completion experience
set completeopt=menuone,noinsert,noselect
" Avoid showing extra message when using completion
set shortmess+=c
set nowrap
set noswapfile
set nobackup
set undodir=~/.config/nvim/undodir
set undofile
set ignorecase
set smartcase
set updatetime=200
set scrolloff=8
call plug#begin('~/.config/nvim/plugged')
Plug 'gruvbox-community/gruvbox'
Plug 'joshdick/onedark.vim'
Plug 'neovim/nvim-lspconfig'
"Plug 'nvim-lua/completion-nvim'
Plug 'hrsh7th/nvim-compe'
Plug 'tzachar/compe-tabnine', { 'do': './install.sh' }
"Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'ryanoasis/vim-devicons'
Plug 'kyazdani42/nvim-web-devicons'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'voldikss/vim-floaterm'
Plug 'mhinz/vim-signify'
call plug#end()
set background=dark
syntax enable
colorscheme onedark
highlight Normal guibg=none
if (empty($TMUX))
if (has("nvim"))
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
if (has("termguicolors"))
set termguicolors
endif
endif
let mapleader=" "
let g:airline_powerline_fonts = 1
" Floating terminal settings
let g:floaterm_autoclose=2
let g:floaterm_title='Terminal'
nnoremap <silent> <leader>t :FloatermToggle<CR>
tnoremap <silent> <leader>t <C-\><C-n>:FloatermToggle<CR>
" Type :Rc to edit init.vim
command Rc :e $HOME/.config/nvim/init.vim
" Window resizing made easy
" nnoremap <silent> <leader>i :vertical resize +2<CR>
" nnoremap <silent> <leader>o :vertical resize -2<CR>
" nnoremap <silent> <leader>= :resize +2<CR>
" nnoremap <silent> <leader>- :resize -2<CR>
" Config
lua << EOF
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;
buffer = true;
calc = true;
nvim_lsp = true;
nvim_lua = true;
vsnip = true;
tabnine = true;
};
}
EOF
" Tab S-Tab completion
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Mappings
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm('<CR>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
" LSP Config
" pyright language server is good enough
" install it with `npm i -g pyright`
" gopls language server for go lang
" install it with `GO111MODULE=on go get golang.org/x/tools/gopls@latest`
" find where gopls installed and export it in path
lua << EOF
require'lspconfig'.pyright.setup{}
require'lspconfig'.gopls.setup{}
EOF
" LSP mappings
nnoremap gd :lua vim.lsp.buf.definition()<CR>
nnoremap gr :lua vim.lsp.buf.references()<CR>
nnoremap <leader>h :lua vim.lsp.buf.signature_help()<CR>
nnoremap <leader>wa :lua vim.lsp.buf.add_workspace_folder()<CR>
nnoremap <leader>wr :lua vim.lsp.buf.remove_workspace_folder()<CR>
nnoremap <leader>wl :lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>
nnoremap K :lua vim.lsp.buf.hover()<CR>
nnoremap rn :lua vim.lsp.buf.rename()<CR>
nnoremap [d :lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap ]d :lua vim.lsp.diagnostic.goto_next()<CR>
" Completion documentation highlight
highlight link CompeDocumentation NormalFloat
"" Autocompletion settings (Deprecated)
"" completion-nvim have not been updated for a while
"" hence moving to nvim-compe
""
"" Use completion-nvim in every buffer even if LSP is not enabled
"" It's okay to setup completion without LSP. It will simply use
"" another completion source instead (Ex: Snippets)
"autocmd BufEnter * lua require'completion'.on_attach()
"
"" Use <Tab> and <S-Tab> to navigate through popup menu
"inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
"inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
"
"" Use <Tab> and <S-Tab> as trigger keys to enable or disable popup menu
"imap <tab> <Plug>(completion_smart_tab)
"imap <s-tab> <Plug>(completion_smart_s_tab)
" Disabling Tree-sitter, Takes too much startup time
"" Tree sitter settings
"" ALl modules are disabled by default and need to be
"" activated explicitly
"lua <<EOF
" require'nvim-treesitter.configs'.setup {
" ensure_installed = "maintained",
" highlight = {
" enable = true,
" disable = {},
" },
" }
"EOF
" Telescope Settings
" find files telescope
nnoremap <leader>ff <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>fg <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>fb <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>fh <cmd>lua require('telescope.builtin').help_tags()<cr>
" Window splitting and movement
" https://breuer.dev/blog/top-neovim-plugins.html
function! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr())
if (match(a:key,'[jk]'))
wincmd v
else
wincmd s
endif
exec "wincmd ".a:key
endif
endfunction
nnoremap <silent> <C-h> :call WinMove('h')<CR>
nnoremap <silent> <C-j> :call WinMove('j')<CR>
nnoremap <silent> <C-k> :call WinMove('k')<CR>
nnoremap <silent> <C-l> :call WinMove('l')<CR>