working nvim config with nice autocomplete

This commit is contained in:
Anish L 2022-02-26 13:31:21 +10:00
parent 64056cd4a9
commit cc77bf697a

View file

@ -21,18 +21,8 @@ let
sha256 = "000000000000000000000000PJ023iJyMz6vak3qh4="; sha256 = "000000000000000000000000PJ023iJyMz6vak3qh4=";
}; };
}; };
taskwiki-t = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "taskwiki";
version = "2021-09-22";
src = pkgs.fetchFromGitHub {
owner = "tools-life";
repo = "taskwiki";
rev = "c4392c36c01cfffcb06f460d722990b98bc53bdb";
sha256 = "QrxFqu/Y6FykXGqIlK52+nDwmnBhubURl6v2Zc/KwPw=";
};
meta.homepage = "https://github.com/tools-life/taskwiki/";
};
}; };
my-python-packages = python-packages: with python-packages; [ my-python-packages = python-packages: with python-packages; [
tasklib tasklib
pynvim pynvim
@ -65,6 +55,7 @@ in
configure = { configure = {
packages.myPlugins = with pkgs.vimPlugins; { packages.myPlugins = with pkgs.vimPlugins; {
start = [ start = [
# general
vim-nix vim-nix
fzf-vim fzf-vim
vim-elixir vim-elixir
@ -77,6 +68,9 @@ in
rainbow_parentheses-vim rainbow_parentheses-vim
vim-surround vim-surround
vim-devicons vim-devicons
nvim-web-devicons
direnv-vim
# kitaab stuff # kitaab stuff
vimwiki vimwiki
taskwiki taskwiki
@ -84,6 +78,7 @@ in
telescope-nvim telescope-nvim
plenary-nvim plenary-nvim
bufferline-nvim bufferline-nvim
# lsp stuff # lsp stuff
ale ale
nvim-lspconfig nvim-lspconfig
@ -94,10 +89,15 @@ in
cmp-buffer cmp-buffer
cmp-tabnine cmp-tabnine
lspkind-nvim lspkind-nvim
cmp-path
cmp-spell
nvim-autopairs
# git stuff # git stuff
vim-fugitive vim-fugitive
gitsigns-nvim gitsigns-nvim
fzf-checkout-vim fzf-checkout-vim
# Clojure stuff # Clojure stuff
conjure conjure
vim-sexp vim-sexp
@ -133,6 +133,22 @@ in
" set spell " set spell
set spelllang=en_gb set spelllang=en_gb
set ignorecase
set smartcase
set incsearch
" if hidden is not set, TextEdit might fail.
set hidden
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages
set cmdheight=2
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" window " window
nmap <leader>wh :topleft vnew<CR> nmap <leader>wh :topleft vnew<CR>
@ -168,6 +184,7 @@ in
nnoremap <leader>fg <cmd>Telescope live_grep<cr> nnoremap <leader>fg <cmd>Telescope live_grep<cr>
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>
nnoremap <leader>ft <cmd>Telescope tags<cr>
" exit normal mode in terminal " exit normal mode in terminal
:tnoremap <C-n> <C-\><C-n> :tnoremap <C-n> <C-\><C-n>
@ -176,7 +193,7 @@ in
" let g:sexp_filetypes = [ "fennel" ] " let g:sexp_filetypes = [ "fennel" ]
let g:rainbow_active = 0 let g:rainbow_active = 0
autocmd BufReadPost,BufNewFile c,py,nix RainbowParenthesesToggleAll autocmd BufReadPost,BufNewFile c,clj,cljs RainbowParenthesesToggleAll
" general commands " general commands
map <leader>t :NERDTreeToggle<CR> map <leader>t :NERDTreeToggle<CR>
@ -234,29 +251,9 @@ 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
let g:ale_linters = {'clojure': ['clj-kondo'], 'python': ['black', 'pylint']} let g:ale_linters = {'clojure': ['clj-kondo'], 'python': ['black', 'pylint']}
" if hidden is not set, TextEdit might fail.
set hidden
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages
set cmdheight=2
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" lsp commands " lsp commands
nnoremap <leader>vd :lua vim.lsp.buf.definition()<CR> nnoremap <leader>vd :lua vim.lsp.buf.definition()<CR>
nnoremap <leader>vi :lua vim.lsp.buf.implementation()<CR> nnoremap <leader>vi :lua vim.lsp.buf.implementation()<CR>
@ -277,51 +274,80 @@ in
" lua config " lua config
lua <<EOF lua <<EOF
-- Setup nvim-cmp. -- Setup nvim-cmp.
local cmp = require'cmp' local cmp = require('cmp')
cmp.setup({ local t = function(str)
mapping = { return vim.api.nvim_replace_termcodes(str, true, true, true)
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), end
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), local check_back_space = function()
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), local col = vim.fn.col(".") - 1
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping. return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil
['<C-e>'] = cmp.mapping({ end
i = cmp.mapping.abort(), cmp.setup {
c = cmp.mapping.close(), formatting = {
}), format = function(entry, vim_item)
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. -- fancy icons and a name of kind
vim_item.kind = require("lspkind").presets.default[vim_item.kind] ..
" " .. vim_item.kind
-- set a name for each source
vim_item.menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
cmp_tabnine = "[TabNine]",
look = "[Look]",
path = "[Path]",
spell = "[Spell]",
calc = "[Calc]",
})[entry.source.name]
return vim_item
end
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {"i", "s"}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" }),
}, },
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = { sources = {
{ name = 'buffer' }, {name = 'buffer'}, {name = 'nvim_lsp'},
{ name = "nvim_lsp"}, {name = "look"}, {name = "path"},
{ name = "path" }, {name = 'cmp_tabnine'}, {name = "calc"}, {name = "spell"},
{ name = 'conjure'}, {name = 'cmp-conjure'}
{ name = 'cmp_tabnine'}, },
} completion = {completeopt = 'menu,menuone,noinsert'}
}) }
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -- TabNine cmp
cmp.setup.cmdline(':', { local tabnine = require('cmp_tabnine.config')
sources = cmp.config.sources({ tabnine:setup({max_lines = 1000, max_num_results = 20, sort = true})
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- Setup lspconfig. -- Setup lspconfig.
-- local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- require'lspconfig'nvim_lsp.setup {} require'lspconfig'nvim_lsp.setup {}
-- require'lspconfig'clojure_lsp.setup {} require'lspconfig'clojure_lsp.setup {}
-- require'lspconfig'rnix.setup {} require'lspconfig'rnix.setup {}
-- require'lspconfig'pylsp.setup {} require'lspconfig'pylsp.setup {}
-- require'lspconfig'terraform_lsp.setup {} require'lspconfig'terraform_lsp.setup {}
-- Bufferline -- Bufferline
require('bufferline').setup {} require('bufferline').setup {}