-
-
Save junkblocker/9e9a9105605ec02ff55986ead8a10496 to your computer and use it in GitHub Desktop.
Neovim 0.11 config with builtin autocompletion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---[[HOW TO USE IT? | |
--- 0. Install neovim 0.11 | |
--- 1. Create ~/.config/nvim-experiments directory on your machine (Assuming you are using Linux) | |
--- 2. Copy this init.lua into the nvim-experiments directory | |
--- 3. Launch neovim using `NVIM_APPNAME=nvim-experiments nvim` command | |
--- 4. Install requiring lsp servers via mason (type `:Mason`), relaunch neovim, and open your project to test it | |
--- 5. You may want to install treesitter parsers to get documentation | |
--- highlighting for some languages | |
---]] | |
---[[ Lazy.nvim package manager bootstrap and some essential plugins installation | |
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | |
if not vim.uv.fs_stat(lazypath) then | |
local lazyrepo = "https://github.com/folke/lazy.nvim.git" | |
vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) | |
end | |
vim.opt.rtp:prepend(lazypath) | |
require("lazy").setup({ | |
spec = { | |
{ "williamboman/mason.nvim", opts = {} }, | |
{ "folke/lazydev.nvim", opts = {} }, | |
{ "neovim/nvim-lspconfig" }, | |
{ "williamboman/mason-lspconfig.nvim" }, | |
{ | |
"williamboman/mason.nvim", | |
config = function() | |
require("mason").setup() | |
require("mason-lspconfig").setup() | |
require("mason-lspconfig").setup_handlers({ | |
function(server_name) | |
require("lspconfig")[server_name].setup({}) | |
end, | |
}) | |
end | |
}, | |
{ "j-hui/fidget.nvim", opts = {}, }, | |
{ "folke/tokyonight.nvim", priority = 1000, opts = {} }, | |
}, | |
}) | |
vim.cmd [[colorscheme tokyonight-moon]] | |
vim.o.number = true | |
vim.o.signcolumn = "yes" | |
vim.cmd([[autocmd FileType * set formatoptions-=ro]]) -- disable new line auto comment | |
---]] | |
---[[AUTOCOMPLETION SETUP | |
vim.o.completeopt = "menu,noinsert,popup,fuzzy" | |
---[[ Setup keymaps so we can accept completion using Enter and choose items using arrow keys or Tab. | |
local pumMaps = { | |
['<Tab>'] = '<C-n>', | |
['<S-Tab>'] = '<C-p>', | |
['<Down>'] = '<C-n>', | |
['<Up>'] = '<C-p>', | |
['<CR>'] = '<C-y>', | |
} | |
for insertKmap, pumKmap in pairs(pumMaps) do | |
vim.keymap.set('i', insertKmap, function() | |
return vim.fn.pumvisible() == 1 and pumKmap or insertKmap | |
end, { expr = true }) | |
end | |
---]] | |
vim.api.nvim_create_autocmd('LspAttach', { | |
callback = function(args) | |
---[[Code required to activate autocompletion and trigger it on each keypress | |
local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) | |
client.server_capabilities.completionProvider.triggerCharacters = vim.split("qwertyuiopasdfghjklzxcvbnm. ", "") | |
vim.api.nvim_create_autocmd({ 'TextChangedI' }, { | |
buffer = args.buf, | |
callback = function() | |
vim.lsp.completion.get() | |
end | |
}) | |
vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true }) | |
---]] | |
---[[Code required to add documentation popup for an item | |
local _, cancel_prev = nil, function() end | |
vim.api.nvim_create_autocmd('CompleteChanged', { | |
buffer = args.buf, | |
callback = function() | |
cancel_prev() | |
local info = vim.fn.complete_info({ 'selected' }) | |
local completionItem = vim.tbl_get(vim.v.completed_item, 'user_data', 'nvim', 'lsp', 'completion_item') | |
if nil == completionItem then | |
return | |
end | |
_, cancel_prev = vim.lsp.buf_request(args.buf, | |
vim.lsp.protocol.Methods.completionItem_resolve, | |
completionItem, | |
function(err, item, ctx) | |
if not item then | |
return | |
end | |
local docs = (item.documentation or {}).value | |
local win = vim.api.nvim__complete_set(info['selected'], { info = docs }) | |
if win.winid and vim.api.nvim_win_is_valid(win.winid) then | |
vim.treesitter.start(win.bufnr, 'markdown') | |
vim.wo[win.winid].conceallevel = 3 | |
end | |
end) | |
end | |
}) | |
---]] | |
end | |
}) | |
---AUTOCOMPLETION SETUP END]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment