diff options
Diffstat (limited to 'lua/user')
| -rw-r--r-- | lua/user/cmp.lua | 130 | ||||
| -rw-r--r-- | lua/user/keymaps.lua | 68 | ||||
| -rw-r--r-- | lua/user/lsp/handlers.lua | 104 | ||||
| -rw-r--r-- | lua/user/lsp/init.lua | 9 | ||||
| -rw-r--r-- | lua/user/lsp/lsp-installer.lua | 28 | ||||
| -rw-r--r-- | lua/user/lsp/settings/bashls.lua | 0 | ||||
| -rw-r--r-- | lua/user/lsp/settings/ccls.lua | 34 | ||||
| -rw-r--r-- | lua/user/lsp/settings/texlab.lua | 0 | ||||
| -rw-r--r-- | lua/user/options.lua | 51 | ||||
| -rw-r--r-- | lua/user/plugins.lua | 59 |
10 files changed, 483 insertions, 0 deletions
diff --git a/lua/user/cmp.lua b/lua/user/cmp.lua new file mode 100644 index 0000000..5a005e8 --- /dev/null +++ b/lua/user/cmp.lua @@ -0,0 +1,130 @@ +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local snip_status_ok, luasnip = pcall(require, "luasnip") +if not snip_status_ok then + return +end + + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +-- פּ ﯟ some other good icons +local kind_icons = { + Text = "", + Method = "m", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} +-- find more here: https://www.nerdfonts.com/cheat-sheet + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + ["<C-k>"] = cmp.mapping.select_prev_item(), + ["<C-j>"] = cmp.mapping.select_next_item(), + ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "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 }, + ["<Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + vim_item.menu = ({ + nvim_lsp = "[LSP]", + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + nvim_lua = "[NVIM_LUA]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + { name = "nvim-lua" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + experimental = { + ghost_text = false, + native_menu = false, + }, +} diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua new file mode 100644 index 0000000..be9bb45 --- /dev/null +++ b/lua/user/keymaps.lua @@ -0,0 +1,68 @@ +local opts = { noremap = true, silent = true } + +local term_opts = { silent = true } + +-- Shorten function name +local keymap = vim.api.nvim_set_keymap + +--Remap space as leader key +keymap("", "<Space>", "<Nop>", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- Modes +-- normal_mode = "n", +-- insert_mode = "i", +-- visual_mode = "v", +-- visual_block_mode = "x", +-- term_mode = "t", +-- command_mode = "c", + +-- Normal -- +-- Better window navigation +keymap("n", "<C-h>", "<C-w>h", opts) +keymap("n", "<C-j>", "<C-w>j", opts) +keymap("n", "<C-k>", "<C-w>k", opts) +keymap("n", "<C-l>", "<C-w>l", opts) + +-- Resize with arrows +keymap("n", "<C-Up>", ":resize -2<CR>", opts) +keymap("n", "<C-Down>", ":resize +2<CR>", opts) +keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts) +keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts) + +-- Navigate buffers +keymap("n", "<S-l>", ":bnext<CR>", opts) +keymap("n", "<S-h>", ":bprevious<CR>", opts) + +-- Move text up and down +keymap("n", "<A-j>", "<Esc>:m .+1<CR>==gi", opts) +keymap("n", "<A-k>", "<Esc>:m .-2<CR>==gi", opts) + +-- Insert -- +-- Press jk fast to enter +-- keymap("i", "jk", "<ESC>", opts) + +-- Visual -- +-- Stay in indent mode +keymap("v", "<", "<gv", opts) +keymap("v", ">", ">gv", opts) + +-- Move text up and down +keymap("v", "<A-j>", ":m .+1<CR>==", opts) +keymap("v", "<A-k>", ":m .-2<CR>==", opts) +keymap("v", "p", '"_dP', opts) + +-- Visual Block -- +-- Move text up and down +keymap("x", "J", ":move '>+1<CR>gv-gv", opts) +keymap("x", "K", ":move '<-2<CR>gv-gv", opts) +keymap("x", "<A-j>", ":move '>+1<CR>gv-gv", opts) +keymap("x", "<A-k>", ":move '<-2<CR>gv-gv", opts) + +-- Terminal -- +-- Better terminal navigation +-- keymap("t", "<C-h>", "<C-\\><C-N><C-w>h", term_opts) +-- keymap("t", "<C-j>", "<C-\\><C-N><C-w>j", term_opts) +-- keymap("t", "<C-k>", "<C-\\><C-N><C-w>k", term_opts) +-- keymap("t", "<C-l>", "<C-\\><C-N><C-w>l", term_opts) diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua new file mode 100644 index 0000000..76b4572 --- /dev/null +++ b/lua/user/lsp/handlers.lua @@ -0,0 +1,104 @@ +local M = {} + +-- TODO: backfill this to template +M.setup = function() + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + -- disable virtual text + virtual_text = false, + -- show signs + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + }) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "rounded", + }) +end + +local function lsp_highlight_document(client) + -- Set autocommands conditional on server_capabilities + if client.resolved_capabilities.document_highlight then + vim.api.nvim_exec( + [[ + augroup lsp_document_highlight + autocmd! * <buffer> + autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() + autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() + augroup END + ]], + false + ) + end +end + +local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts) + -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>f", "<cmd>lua vim.diagnostic.open_float()<CR>", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts) + vim.api.nvim_buf_set_keymap( + bufnr, + "n", + "gl", + '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ border = "rounded" })<CR>', + opts + ) + vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts) + vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] +end + +M.on_attach = function(client, bufnr) + if client.name == "tsserver" then + client.resolved_capabilities.document_formatting = false + end + lsp_keymaps(bufnr) + lsp_highlight_document(client) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() + +local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not status_ok then + return +end + +M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + +return M diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua new file mode 100644 index 0000000..c218647 --- /dev/null +++ b/lua/user/lsp/init.lua @@ -0,0 +1,9 @@ +local status_ok, _ = pcall(require, "lspconfig") +if not status_ok then + return +end + +require "user.lsp.lsp-installer" +require("user.lsp.handlers").setup() + +require "user.lsp.settings.ccls" diff --git a/lua/user/lsp/lsp-installer.lua b/lua/user/lsp/lsp-installer.lua new file mode 100644 index 0000000..18490ce --- /dev/null +++ b/lua/user/lsp/lsp-installer.lua @@ -0,0 +1,28 @@ +local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer") +if not status_ok then + return +end + +-- 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 = { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + } + + if server.name == "bashls" then + local bashls_opts = require("user.lsp.settings.bashls") + opts = vim.tbl_deep_extend("force", bashls_opts, opts) + end + + if server.name == "texlab" then + local texlab_opts = require("user.lsp.settings.texlab") + opts = vim.tbl_deep_extend("force", texlab_opts, opts) + 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) diff --git a/lua/user/lsp/settings/bashls.lua b/lua/user/lsp/settings/bashls.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lua/user/lsp/settings/bashls.lua diff --git a/lua/user/lsp/settings/ccls.lua b/lua/user/lsp/settings/ccls.lua new file mode 100644 index 0000000..d663f7c --- /dev/null +++ b/lua/user/lsp/settings/ccls.lua @@ -0,0 +1,34 @@ +local status, lspconfig = pcall(require, "lspconfig") +if not status then + return +end + + +vim.notify(vim.fn.expand('%:p')); +local extraArgs_opt = {}; + +if string.match(vim.fn.expand('%:p'),"/home/aleksa/mygit/mykernel/") then + extraArgs_opt = { "--sysroot=/home/aleksa/mygit/mykernel/sysroot", "--gcc-toolchain=/usr/bin/i686-elf-gcc", "-ffreestanding", "-nobuiltininc"}; +else +end + + +lspconfig.ccls.setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }; + init_options = { + compilationDatabaseDirectory = "build"; + cache = { + directory = "/tmp/ccls-cache"; + }; + index = { + threads = 0; + }; + clang = { + excludeArgs = { "-frounding-math"}; + extraArgs = extraArgs_opt; + } + }; +} diff --git a/lua/user/lsp/settings/texlab.lua b/lua/user/lsp/settings/texlab.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lua/user/lsp/settings/texlab.lua diff --git a/lua/user/options.lua b/lua/user/options.lua new file mode 100644 index 0000000..a15e0e4 --- /dev/null +++ b/lua/user/options.lua @@ -0,0 +1,51 @@ +local options = { + backup = false, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 2, -- more space in the neovim command line for displaying messages + completeopt = { "menuone", "noselect" }, -- mostly just for cmp + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a fie + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + -- mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = true, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = false, -- creates a swapfile + -- termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) + undofile = true, -- enable persistent undo + updatetime = 300, -- faster completion (4000ms default) + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = true, -- convert tabs to spaces + shiftwidth = 4, -- the number of spaces inserted for each indentation + tabstop = 4, -- insert 4 spaces for a tab + preserveindent = true, + softtabstop = 0, + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + relativenumber = true, -- set relative numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + scrolloff = 8, -- is one of my fav + sidescrolloff = 8, + guifont = "monospace:h17", -- the font used in graphical neovim applications +} + +vim.opt.shortmess:append "c" + +for k, v in pairs(options) do + vim.opt[k] = v +end + +-- vim.cmd "set whichwrap+=<,>,[,],h,l" +vim.cmd [[set iskeyword+=-]] +vim.cmd [[set formatoptions-=cro]] -- TODO: this doesn't seem to work + +-- Open a file from its last left off position +vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] diff --git a/lua/user/plugins.lua b/lua/user/plugins.lua new file mode 100644 index 0000000..d1e7c69 --- /dev/null +++ b/lua/user/plugins.lua @@ -0,0 +1,59 @@ +local fn = vim.fn +local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim" +if fn.empty(fn.glob(install_path)) > 0 then + packer_bootstrap = fn.system({"git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path}) + vim.cmd [[packadd packer.nvim]] +end + +-- Autocommand that reloads neovim whenever you save the plugins.lua file +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source <afile> | PackerSync + augroup end +]]) + +local status, packer = pcall(require, "packer") +if not status then + return +end + +packer.init { + display = { + open_fn = function() + return require("packer.util").float { border = "rounded" } + end, + }, +} + +return packer.startup(function(use) +-- Packer + use "wbthomason/packer.nvim" + +-- cmp + use "hrsh7th/nvim-cmp" + use "saadparwaiz1/cmp_luasnip" + use "hrsh7th/cmp-nvim-lsp" + use "hrsh7th/cmp-buffer" + use "hrsh7th/cmp-path" + use "hrsh7th/cmp-cmdline" + use "hrsh7th/cmp-nvim-lua" + +-- snippets + use "L3MON4D3/LuaSnip" + +-- LSP + use "neovim/nvim-lspconfig" + use "williamboman/nvim-lsp-installer" + +-- Other + use "kyazdani42/nvim-web-devicons" + use "kyazdani42/nvim-tree.lua" + use "akinsho/bufferline.nvim" + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require("packer").sync() + end +end) |
