-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc.new
454 lines (388 loc) · 13.7 KB
/
vimrc.new
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
syntax on
set nocompatible
filetype off
call plug#begin('~/.local/share/nvim/plugged/')
" Plugins {{{
" essential plugins
Plug 'editorconfig/editorconfig-vim'
" eye candy
Plug 'flazz/vim-colorschemes'
Plug 'bling/vim-airline'
" markdown
Plug 'plasticboy/vim-markdown'
" git support
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" language support
Plug 'elixir-editors/vim-elixir'
Plug 'fatih/vim-go'
Plug 'jparise/vim-graphql'
Plug 'pearofducks/ansible-vim'
Plug 'cespare/vim-toml'
Plug 'hashivim/vim-terraform'
" coding aids
Plug 'tpope/vim-commentary'
Plug 'mattn/emmet-vim'
" Completion
" Telescope (file finding / grepping)
if has("nvim")
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
" better code highliting
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/nvim-lsp-installer'
" Auto complete
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
endif
" Navigation
Plug 'scrooloose/nerdtree'
" eye candy
Plug 'ryanoasis/vim-devicons'
" color schemes
" Plug 'NLKNguyen/papercolor-theme'
" }}}
call plug#end()
" general editor options {{{
" These don't require any plugins
set nu
let mapleader=','
set ttimeoutlen=50
set modeline
set noswapfile
set laststatus=2
set relativenumber
set pastetoggle=<F3>
if has('clipboard')
if has('unnamedplus') " When possible use + register for copy-paste
set clipboard=unnamed,unnamedplus
else " On mac and Windows, use * register for copy-paste
set clipboard=unnamed
endif
endif
set hidden
set foldmethod=marker
set foldlevel=99
set encoding=utf-8
if has("nvim")
set diffopt+=vertical
endif
" search
set ignorecase
set smartcase
set incsearch
set hls
set gdefault "default to globl search & replace
set wildmode=longest,list
set showmatch
set showcmd
set shortmess=at
set synmaxcol=800 " don't try to highlight lines longer than 800 characters
set scrolloff=3
set wildignore=*.o,*.obj,*.swp,*.bak,*.pyc,*~,build,cache,*/sites/default/files,tmp,*.class,*.egg-info,__pycache__,
set wildignore+=*/vendor/**
set wildignore+=*/node_modules/**
set cursorline
" set cursorcolumn
" Use Perl's regex on searches
nnoremap / /\v
vnoremap / /\v
inoremap jj <ESC>
""set listchars=tab:▸\ ,eol:¬,trail:·
set list
set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
"map <leader>b :set nu!<CR>
set title " show filename in titlebar / terminal
" general editing tweaks {{{
set backspace=indent,eol,start " allow backspacing over autoindent, linke breaks and start of insert
set nowrap
set autoindent
" default indentation is two spaces
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
" auto-completion {{{
set completeopt=menu,menuone,noselect
" }}}
" disable help key
noremap <F1> <nop>
inoremap <F1> <nop>
set splitright
" }}}
" look and feel {{{
let g:solarized_termcolors=256
set t_Co=256
"colorscheme monokai-phoenix
"set background=dark
" colorscheme Tomorrow
" set background=light
colorscheme desertEx
set background=dark
" Allow to trigger background
function! ToggleBG()
let s:tbg = &background
" Inversion
if s:tbg == "dark"
set background=light
else
set background=dark
endif
endfunction
" noremap <leader>bg :call ToggleBG()<CR>
" }}}
" leader mappings {{{
map <leader>q :q<cr>
map <leader>Q :1,300bd<cr>
map <leader>d :bd<cr>
" Adjust viewports to the same size
map <Leader>= <C-w>=
" Find merge conflict markers
map <leader>c /\v^[<\|=>]{7}( .*\|$)<CR>
" Clean trailing whitespace
nnoremap <leader>w mz:%s/\s\+$//<cr>:let @/=''<cr>`z
" vertical split
noremap <leader>v <C-w>v
" create a new tab
noremap <leader>t :tabnew<CR>
" Telescope shortcuts
if has("nvim")
nnoremap <leader>sf <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>sg <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>sb <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>sh <cmd>lua require('telescope.builtin').help_tags()<cr>
nnoremap <leader>sd <cmd>lua require('telescope.builtin').lsp_document_symbols()<cr>
nnoremap <leader>sw <cmd>lua require('telescope.builtin').lsp_dynamic_workspace_symbols()<cr>
endif
" Adjust viewports to the same size
map <Leader>= <C-w>=
"" NERDTree mappings
map <leader>f :NERDTree<cr>
map <leader>x :NERDTreeFind<cr>
let NERDTreeIgnore = ['\.pyc$', 'venv', '__pycache__']
let NERDTreeQuitOnOpen=0
" URL encode/decode selection
vnoremap <leader>en :!python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'<cr>
vnoremap <leader>de :!python -c 'import sys,urllib;print urllib.unquote(sys.stdin.read().strip())'<cr>
" prettify JSON on current buffer
nmap <leader>jt <Esc>:%!python -m json.tool<CR><Esc>:set filetype=json<CR>
map <leader><space> :noh<cr>
map <leader>l :set list!<cr>
" }}}
map <C-p> <cmd>lua require('telescope.builtin').find_files()<cr>
" editing aids {{{
" use Q to format paragraph
vmap Q gq
nmap Q gqap
" Re-select last pasted text
nnoremap gp `[v`]
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
nnoremap <c-o> <c-o>zz
" }}}
" TMUX integration {{{
if exists('$TMUX')
function! TmuxOrSplitSwitch(wincmd, tmuxdir)
let previous_winnr = winnr()
silent! execute "wincmd " . a:wincmd
if previous_winnr == winnr()
call system("tmux select-pane -" . a:tmuxdir)
redraw!
endif
endfunction
let previous_title = substitute(system("tmux display-message -p '#{pane_title}'"), '\n', '', '')
let &t_ti = "\<Esc>]2;vim\<Esc>\\" . &t_ti
let &t_te = "\<Esc>]2;". previous_title . "\<Esc>\\" . &t_te
nnoremap <silent> <C-h> :call TmuxOrSplitSwitch('h', 'L')<cr>
nnoremap <silent> <C-j> :call TmuxOrSplitSwitch('j', 'D')<cr>
nnoremap <silent> <C-k> :call TmuxOrSplitSwitch('k', 'U')<cr>
nnoremap <silent> <C-l> :call TmuxOrSplitSwitch('l', 'R')<cr>
else
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
endif
map <S-H> gT
map <S-L> gt
" }}}
if has("nvim")
" vim-treesitter
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
custom_captures = {
-- Highlight the @foo.bar capture group with the "Identifier" highlight group.
["foo.bar"] = "Identifier",
},
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
EOF
lua <<EOF
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
--
-- LSP Installer
--
local lsp_installer = require("nvim-lsp-installer")
-- Register a handler that will be called for all installed servers.
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
lsp_installer.on_server_ready(function(server)
local opts = {}
-- (optional) Customize the options passed to the server
-- if server.name == "tsserver" then
-- opts.root_dir = function() ... end
-- end
-- This setup() function is exactly the same as lspconfig's setup function.
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
server:setup(opts)
end)
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['pyright'].setup {
capabilities = capabilities
}
require('lspconfig')['tsserver'].setup {
cmd = {vim.fn.expand("~/.asdf/shims/typescript-language-server"), "--stdio"},
capabilities = capabilities
}
local elixirls_path = vim.fn.expand("~/.local/elixir-ls/release/language_server.sh")
require'lspconfig'.elixirls.setup({
cmd = {elixirls_path},
capabilities = capabilities,
settings = {
elixirLS = {
dialyzerEnabled = false,
fetchDeps = false
}
}
})
EOF
" autocomplete with nvim-cmp
" lua << CMPEOF
" local nvim_lsp = require('lspconfig')
"
" -- 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
"
" -- Enable completion triggered by <c-x><c-o>
" buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
"
" -- 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', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
" buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
" buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
" buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
" buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
" buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
" buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
" buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
" buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
" buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
" buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
" buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
" buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
" buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
" buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
"
" end
"
" -- Use a loop to conveniently call 'setup' on multiple servers and
" -- map buffer local keybindings when the language server attaches
" local servers = { 'pyright', 'tsserver' }
" for _, lsp in ipairs(servers) do
" nvim_lsp[lsp].setup {
" on_attach = on_attach,
" flags = {
" debounce_text_changes = 150,
" }
" }
" end
" CMPEOF
" Code editing using LSP
lua <<CODEEDIT
local function map(mode, lhs, rhs, opts)
local options = {noremap = true}
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
map('n', 'gd', ':lua vim.lsp.buf.definition()<CR>')
map('n', 'gh', ':lua vim.lsp.buf.hover()<CR>')
map('n', 'ga', ':Telescope lsp_code_actions<CR>')
map('n', 'gA', ':Telescope lsp_range_code_actions<CR>')
map('n', 'gD', ':lua vim.lsp.buf.implementation()<CR>')
map('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<CR>')
map('n', 'gr', ':lua vim.lsp.buf.references()<CR>')
map('n', 'gR', ':lua vim.lsp.buf.rename()<CR>')
CODEEDIT
endif