modernizing my nvim config. uses a lot of lua now, and also

cmp,lspconfig,bufferline
This commit is contained in:
Anish L 2022-02-26 03:32:15 +10:00
parent c19a9a5705
commit a317a0e85f

View file

@ -37,9 +37,10 @@ let
tasklib tasklib
pynvim pynvim
six six
#pyls-mypy python-lsp-server
#pyls-isort pylsp-mypy
#pyls-black python-lsp-black
pylint
# other python packages you want # other python packages you want
]; ];
python-with-my-packages = pkgs.python3.withPackages my-python-packages; python-with-my-packages = pkgs.python3.withPackages my-python-packages;
@ -55,10 +56,9 @@ in
python-with-my-packages python-with-my-packages
clojure-lsp clojure-lsp
rnix-lsp rnix-lsp
#python3Packages.pynvim terraform-lsp
#python3Packages.six nodePackages.typescript-lsp-server
#python3Packages.tasklib # Other LSPs
#python3
( neovim.override { ( neovim.override {
vimAlias = true; vimAlias = true;
withPython3 = true; withPython3 = true;
@ -71,38 +71,46 @@ in
vim-elixir vim-elixir
emmet-vim emmet-vim
nerdtree nerdtree
ayu-vim
goyo-vim goyo-vim
vim-sneak vim-sneak
lightline-vim
csv-vim csv-vim
vimwiki
coc-nvim
coc-json
ale
coc-pyright
coc-pairs
coc-emmet
LanguageClient-neovim
ayu-vim
rainbow_parentheses-vim rainbow_parentheses-vim
vim-surround vim-surround
vim-fugitive bufferline-nvim
vim-signify feline-nvim
fzf-checkout-vim nvim-webdev-icons
#nvim-colorizer
vim-devicons vim-devicons
# testing # kitaab stuff
#vim-processing vimwiki
#vim-tidal
taskwiki taskwiki
vim-zettel vim-zettel
#vimwiki-sync
telescope-nvim telescope-nvim
plenary-nvim plenary-nvim
# lsp stuff
ale
black-vim
nvim-lspconfig
nvim-cmp
nvim-cmp-lsp
nvim-lsp-ts-utils
cmp-conjure
cmp-buffer
cmp-tabnine
lspkind-nvim
luasnip
cmp_luasnip
# git stuff
vim-fugitive
gitsigns-nvim
fzf-checkout-vim
# Clojure stuff # Clojure stuff
conjure conjure
vim-sexp vim-sexp
vim-sexp-mappings-for-regular-people vim-sexp-mappings-for-regular-people
# testing
#vim-processing
#vim-tidal
]; ];
}; };
@ -112,6 +120,7 @@ in
set shiftwidth=2 set shiftwidth=2
set noexpandtab set noexpandtab
set autoindent set autoindent
set undofile
" set foldmethod=indent " fold based on indent " set foldmethod=indent " fold based on indent
set number set number
@ -143,11 +152,6 @@ in
let mapleader = "\<Space>" let mapleader = "\<Space>"
let maplocalleader = "," let maplocalleader = ","
" lightline colorscheme
let g:lightline = {
\ 'colorscheme': 'seoul256',
\ }
" moving splits with vim movements. " moving splits with vim movements.
:tnoremap <A-h> <C-\><C-N><C-w>h :tnoremap <A-h> <C-\><C-N><C-w>h
:tnoremap <A-j> <C-\><C-N><C-w>j :tnoremap <A-j> <C-\><C-N><C-w>j
@ -171,15 +175,9 @@ in
nnoremap <leader>fb <cmd>Telescope buffers<cr> nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr> nnoremap <leader>fh <cmd>Telescope help_tags<cr>
" exit normal mode in terminal " exit normal mode in terminal
:tnoremap <C-n> <C-\><C-n> :tnoremap <C-n> <C-\><C-n>
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" Sexp in Conjure (since it's fennel) " Sexp in Conjure (since it's fennel)
" let g:sexp_filetypes = [ "fennel" ] " let g:sexp_filetypes = [ "fennel" ]
@ -215,6 +213,10 @@ in
inoremap <c-k> <esc>:m .-2<CR>== inoremap <c-k> <esc>:m .-2<CR>==
nnoremap <leader>j <esc>:m .+1<CR>== nnoremap <leader>j <esc>:m .+1<CR>==
nnoremap <leader>k <esc>:m .-2<CR>== nnoremap <leader>k <esc>:m .-2<CR>==
" Pasting
:map <leader>sy :!xclip -i<CR><CR>
:vmap <leader>sy "*y
:map <leader>sp :r!xclip -o<CR>
" git " git
nmap <leader>gd :SignifyDiff<CR> nmap <leader>gd :SignifyDiff<CR>
@ -238,13 +240,8 @@ in
" fzf " fzf
let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } } let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } }
" ALE + clj-kondo " ALE + clj-kondo
let g:ale_linters = {'clojure': ['clj-kondo']} let g:ale_linters = {'clojure': ['clj-kondo'], 'python': ['black', 'pylint']}
" coc
" conjure extension
let g:coc_global_extensions = ['coc-conjure']
" if hidden is not set, TextEdit might fail. " if hidden is not set, TextEdit might fail.
set hidden set hidden
@ -265,129 +262,444 @@ in
" always show signcolumns " always show signcolumns
set signcolumn=yes set signcolumn=yes
" note that if you are using Plug mapping you should not use `noremap` mappings.
nmap <F5> <Plug>(lcn-menu)
" Or map each action separately
nmap <silent>K <Plug>(lcn-hover)
nmap <silent> gd <Plug>(lcn-definition)
nmap <silent> <F2> <Plug>(lcn-r
" Use tab for trigger completion with characters ahead and navigate. " lsp commands
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin. nnoremap <leader>vd :lua vim.lsp.buf.definition()<CR>
inoremap <silent><expr> <TAB> nnoremap <leader>vi :lua vim.lsp.buf.implementation()<CR>
\ pumvisible() ? "\<C-n>" : nnoremap <leader>vsh :lua vim.lsp.buf.signature_help()<CR>
\ <SID>check_back_space() ? "\<TAB>" : nnoremap <leader>vrr :lua vim.lsp.buf.references()<CR>
\ coc#refresh() nnoremap <leader>vrn :lua vim.lsp.buf.rename()<CR>
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" nnoremap <leader>vh :lua vim.lsp.buf.hover()<CR>
nnoremap <leader>vca :lua vim.lsp.buf.code_action()<CR>
nnoremap <leader>vsd :lua vim.lsp.diagnostic.show_line_diagnostics(); vim.lsp.util.show_line_diagnostics()<CR>
nnoremap <leader>vn :lua vim.lsp.diagnostic.goto_next()<CR>
nnoremap <leader>vll :call LspLocationList()<CR>
augroup THE_PRIMEAGEN_LSP
autocmd!
autocmd! BufWrite,BufEnter,InsertLeave * :call LspLocationList()
augroup END
function! s:check_back_space() abort "bufferline
let col = col('.') - 1 " These commands will navigate through buffers in order regardless of which mode you are using
return !col || getline('.')[col - 1] =~# '\s' nnoremap <silent>[b :BufferLineCycleNext<CR>
endfunction nnoremap <silent>b] :BufferLineCyclePrev<CR>
" Use <c-space> to trigger completion. " lua config
inoremap <silent><expr> <c-space> coc#refresh() lua <<EOF
-- luasnip
M.luasnip = function(override_flag)
local present, luasnip = pcall(require, "luasnip")
if present then
local default = {
history = true,
updateevents = "TextChanged,TextChangedI",
}
if override_flag then
default = require("core.utils").tbl_override_req("luasnip", default)
end
luasnip.config.set_config(default)
require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path }
require("luasnip/loaders/from_vscode").load()
end
end
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position. -- Setup nvim-cmp.
" Coc only does snippet and additional edit on confirm. local cmp = require'cmp'
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" cmp.setup({
" Or use `complete_info` if your vim support it, like: snippet = {
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
formatting = {
format = function(entry, vim_item)
local icons = require "plugins.configs.lspkind_icons"
vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)
vim_item.menu = ({
nvim_lsp = "[LSP]",
clojure_lsp = "[CLJ]",
buffer = "[BUF]",
terraform_lsp = "[TER]",
pylsp = "[PY]",
rnix-lsp = "[NIX]",
})[entry.source.name]
return vim_item
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(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
{ name = "nvim_lsp"},
{ name = "path" },
{ name = 'conjure'},
{ name = 'cmp_tabnine'},
}
})
-- 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' }
})
})
" Use `[g` and `]g` to navigate diagnostics -- Setup lspconfig.
nmap <silent> [g <Plug>(coc-diagnostic-prev) local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
nmap <silent> ]g <Plug>(coc-diagnostic-next) require('lspconfig')['nvim_lsp', clojure_lsp', 'rnix-lsp', 'pylsp', 'terraform_lsp', 'tsserver'].setup {
capabilities = capabilities
}
" Remap keys for gotos -- Feline
nmap <silent> gd <Plug>(coc-definition) local colors = require 'theme.colors'
nmap <silent> gy <Plug>(coc-type-definition) local lsp = require 'feline.providers.lsp'
nmap <silent> gi <Plug>(coc-implementation) local vi_mode_utils = require 'feline.providers.vi_mode'
nmap <silent> gr <Plug>(coc-references) local vi_mode_colors = {
NORMAL = colors.green,
INSERT = colors.red,
VISUAL = colors.magenta,
OP = colors.green,
BLOCK = colors.blue,
REPLACE = colors.violet,
['V-REPLACE'] = colors.violet,
ENTER = colors.cyan,
MORE = colors.cyan,
SELECT = colors.orange,
COMMAND = colors.green,
SHELL = colors.green,
TERM = colors.green,
NONE = colors.yellow
}
local icons = {
linux = ' ',
macos = ' ',
windows = ' ',
errs = ' ',
warns = ' ',
infos = ' ',
hints = ' ',
lsp = ' ',
git = ''
}
local function file_osinfo()
local os = vim.bo.fileformat:upper()
local icon
if os == 'UNIX' then
icon = icons.linux
elseif os == 'MAC' then
icon = icons.macos
else
icon = icons.windows
end
return icon .. os
end
local function lsp_diagnostics_info()
return {
errs = lsp.get_diagnostics_count('Error'),
warns = lsp.get_diagnostics_count('Warning'),
infos = lsp.get_diagnostics_count('Information'),
hints = lsp.get_diagnostics_count('Hint')
}
end
local function diag_enable(f, s)
return function()
local diag = f()[s]
return diag and diag ~= 0
end
end
local function diag_of(f, s)
local icon = icons[s]
return function()
local diag = f()[s]
return icon .. diag
end
end
local function vimode_hl()
return {
name = vi_mode_utils.get_mode_highlight_name(),
fg = vi_mode_utils.get_mode_color()
}
end
-- LuaFormatter off
local comps = {
vi_mode = {
left = {
provider = '',
hl = vimode_hl,
right_sep = ' '
},
right = {
provider = '',
hl = vimode_hl,
left_sep = ' '
}
},
file = {
info = {
provider = 'file_info',
hl = {
fg = colors.blue,
style = 'bold'
}
},
encoding = {
provider = 'file_encoding',
left_sep = ' ',
hl = {
fg = colors.violet,
style = 'bold'
}
},
type = {
provider = 'file_type'
},
os = {
provider = file_osinfo,
left_sep = ' ',
hl = {
fg = colors.violet,
style = 'bold'
}
}
},
line_percentage = {
provider = 'line_percentage',
left_sep = ' ',
hl = {
style = 'bold'
}
},
scroll_bar = {
provider = 'scroll_bar',
left_sep = ' ',
hl = {
fg = colors.blue,
style = 'bold'
}
},
diagnos = {
err = {
provider = diag_of(lsp_diagnostics_info, 'errs'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'errs'),
hl = {
fg = colors.red
}
},
warn = {
provider = diag_of(lsp_diagnostics_info, 'warns'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'warns'),
hl = {
fg = colors.yellow
}
},
info = {
provider = diag_of(lsp_diagnostics_info, 'infos'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'infos'),
hl = {
fg = colors.blue
}
},
hint = {
provider = diag_of(lsp_diagnostics_info, 'hints'),
left_sep = ' ',
enabled = diag_enable(lsp_diagnostics_info, 'hints'),
hl = {
fg = colors.cyan
}
},
},
lsp = {
name = {
provider = 'lsp_client_names',
left_sep = ' ',
icon = icons.lsp,
hl = {
fg = colors.yellow
}
}
},
git = {
branch = {
provider = 'git_branch',
icon = icons.git,
left_sep = ' ',
hl = {
fg = colors.violet,
style = 'bold'
},
},
add = {
provider = 'git_diff_added',
hl = {
fg = colors.green
}
},
change = {
provider = 'git_diff_changed',
hl = {
fg = colors.orange
}
},
remove = {
provider = 'git_diff_removed',
hl = {
fg = colors.red
}
}
}
}
local properties = {
force_inactive = {
filetypes = {
'NvimTree',
'dbui',
'packer',
'startify',
'fugitive',
'fugitiveblame'
},
buftypes = {'terminal'},
bufnames = {}
}
}
local components = {
left = {
active = {
comps.vi_mode.left,
comps.file.info,
comps.lsp.name,
comps.diagnos.err,
comps.diagnos.warn,
comps.diagnos.hint,
comps.diagnos.info
},
inactive = {
comps.vi_mode.left,
comps.file.info
}
},
mid = {
active = {},
inactive = {}
},
right = {
active = {
comps.git.add,
comps.git.change,
comps.git.remove,
comps.file.os,
comps.git.branch,
comps.line_percentage,
comps.scroll_bar,
comps.vi_mode.right
},
inactive = {}
}
}
-- LuaFormatter on
require'feline'.setup {
default_bg = colors.bg,
default_fg = colors.fg,
components = components,
properties = properties,
vi_mode_colors = vi_mode_colors
}
" Use K to show documentation in preview window -- Buffeline
nnoremap <silent> K :call <SID>show_documentation()<CR> require('bufferline').setup {
options = {
function! s:show_documentation() numbers = "ordinal",
if (index(['vim','help'], &filetype) >= 0) --- @deprecated, please specify numbers as a function to customize the styling
execute 'h '.expand('<cword>') number_style = "superscript",
else close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
call CocAction('doHover') right_mouse_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
endif left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions"
endfunction middle_mouse_command = nil, -- can be a string | function, see "Mouse actions"
-- NOTE: this plugin is designed with this icon in mind,
" Highlight symbol under cursor on CursorHold -- and so changing this is NOT recommended, this is intended
autocmd CursorHold * silent call CocActionAsync('highlight') -- as an escape hatch for people who cannot bear it for whatever reason
indicator_icon = '',
" Remap for rename current word buffer_close_icon = '',
nmap <leader>rn <Plug>(coc-rename) modified_icon = '',
close_icon = '',
" Remap for format selected region left_trunc_marker = '',
xmap <leader>f <Plug>(coc-format-selected) right_trunc_marker = '',
nmap <leader>f <Plug>(coc-format-selected) --- name_formatter can be used to change the buffer's label in the bufferline.
--- Please note some names can/will break the
augroup mygroup --- bufferline so use this at your discretion knowing that it has
autocmd! --- some limitations that will *NOT* be fixed.
" Setup formatexpr specified filetype(s). name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr"
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') -- remove extension from markdown files for example
" Update signature help on jump placeholder if buf.name:match('%.md') then
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') return vim.fn.fnamemodify(buf.name, ':t:r')
augroup end end
end,
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph max_name_length = 18,
xmap <leader>a <Plug>(coc-codeaction-selected) max_prefix_length = 15, -- prefix used when a buffer is de-duplicated
nmap <leader>a <Plug>(coc-codeaction-selected) tab_size = 18,
diagnostics = "nvim_lsp",
" Remap for do codeAction of current line diagnostics_update_in_insert = false,
nmap <leader>ac <Plug>(coc-codeaction) diagnostics_indicator = function(count, level, diagnostics_dict, context)
" Fix autofix problem of current line return "("..count..")"
nmap <leader>qf <Plug>(coc-fix-current) end,
-- NOTE: this will be called a lot so don't do any heavy processing here
" Create mappings for function text object, requires document symbols feature of languageserver. custom_filter = function(buf_number, buf_numbers)
xmap if <Plug>(coc-funcobj-i) -- filter out filetypes you don't want to see
xmap af <Plug>(coc-funcobj-a) if vim.bo[buf_number].filetype ~= "<i-dont-want-to-see-this>" then
omap if <Plug>(coc-funcobj-i) return true
omap af <Plug>(coc-funcobj-a) end
-- filter out by buffer name
" Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python if vim.fn.bufname(buf_number) ~= "<buffer-name-I-dont-want>" then
nmap <silent> <C-d> <Plug>(coc-range-select) return true
xmap <silent> <C-d> <Plug>(coc-range-select) end
-- filter out based on arbitrary rules
" Use `:Format` to format current buffer -- e.g. filter out vim wiki buffer from tabline in your work repo
command! -nargs=0 Format :call CocAction('format') if vim.fn.getcwd() == "<work-repo>" and vim.bo[buf_number].filetype ~= "wiki" then
return true
" Use `:Fold` to fold current buffer end
command! -nargs=? Fold :call CocAction('fold', <f-args>) -- filter out by it's index number in list (don't show first buffer)
if buf_numbers[1] ~= buf_number then
" use `:OR` for organize import of current buffer return true
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') end
end,
" Add status line support, for integration with other plugin, checkout `:h coc-status` -- offsets = {{filetype = "NvimTree", text = "File Explorer" | function , text_align = "left" | "center" | "right"}},
" set statusline^=%{coc#status()}%{get(b:,'coc_current_function',"")} show_buffer_icons = true, -- disable filetype icons for buffers
show_buffer_close_icons = false,
" Using CocList show_close_icon = false,
" Show all diagnostics show_tab_indicators = true,
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr> persist_buffer_sort = true, -- whether or not custom sorted buffers should persist
" Manage extensions -- can also be a table containing 2 custom separators
nnoremap <silent> <space>e :<C-u>CocList extensions<cr> -- [focused and unfocused]. eg: { '|', '|' }
" Show commands separator_style = "thick",
nnoremap <silent> <space>c :<C-u>CocList commands<cr> enforce_regular_tabs = true,
" Find symbol of current document always_show_bufferline = true,
nnoremap <silent> <space>o :<C-u>CocList outline<cr> sort_by = 'relative_directory'
" Search workspace symbols end
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr> }
" Do default action for next item. }
nnoremap <silent> <space>j :<C-u>CocNext<CR> EOF
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
au BufNewFile,BufRead *.frag,*.vert,*.fp,*.vp,*.glsl setf glsl
" TODO Ugly map
:map <F7> :!xclip -i<CR><CR>
:vmap <F7> "*y
:map <S-F7> :r!xclip -o<CR>
''; '';
}; };
} }