diff --git a/init.lua b/init.lua index 812cf61..7707117 100644 --- a/init.lua +++ b/init.lua @@ -14,6 +14,8 @@ local set = vim.opt -- set options set.tabstop = 8 set.softtabstop = 8 set.shiftwidth = 8 +-- Disable tab settings being overriden +vim.cmd("filetype plugin indent off") -- Terminal Config -- Exit terminal mode with Esc @@ -198,6 +200,30 @@ require('neogen').setup { -- jump_map = "" -- (DROPPED SUPPORT, see [here](#cycle-between-annotations) !) The keymap in order to jump in the annotation fields (in insert mode) } +-- Built in tabcomplete/autocomplete setup +function check_for_whitespace() + -- Get the current cursor position (row and column) + local row, col = unpack(vim.api.nvim_win_get_cursor(0)) + -- Get the text of the current line + local linetext = vim.api.nvim_get_current_line() + -- Neovim's column is 0-based, Lua's string indices are 1-based. + + -- Return true if we are at the start of the line (col == 0) + -- OR if the character before the cursor is a whitespace character (%s) + -- linetext:sub(col, col) gets the character at the column index + return col == 0 or string.match(linetext:sub(col, col), '%s') ~= nil +end +-- Tabcomplete: +vim.api.nvim_set_keymap('i', '', "pumvisible() ? '' : v:lua.check_for_whitespace() ? '' : ''", { expr = true, silent = true }) +-- Autocomplete: +-- vim.api.nvim_create_autocmd("InsertCharPre", { +-- callback = function(ev) +-- if vim.bo[ev.buf].buftype == '' and not (vim.fn.pumvisible() == 1) then +-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), 'i', false) +-- end +-- end, +-- }) + -- LSP Configuration local lsp_zero = require('lsp-zero') -- https://lsp-zero.netlify.app/v3.x/language-server-configuration.html#default-keybindings @@ -217,15 +243,11 @@ lsp_zero.on_attach(function(client, bufnr) vim.lsp.inlay_hint.enable(true, { 0 }) - vim.cmd("set tabstop=8") - vim.cmd("set shiftwidth=8") - vim.cmd("set softtabstop=8") + -- Override default omnifunc completer with LSP completion for LSP buffer + -- Tabcomplete: + -- vim.api.nvim_set_keymap('i', '', "pumvisible() ? '' : v:lua.check_for_whitespace() ? '' : 'lua vim.lsp.completion.get()'", { expr = true, silent = true }) end) --- LSP Autocompletion settings -vim.keymap.set('i', '', function() - vim.lsp.completion.get() -end) --local lspconfig = require("lspconfig") vim.lsp.enable("lua_ls")