From c3416367294158095d539b436c9fa7b100ca0047 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 21 Feb 2022 15:15:15 +0100 Subject: [PATCH] feat: finalized config --- .gitignore | 1 + init.lua | 5 +- lua/keymaps.lua | 32 ++++++++ lua/options.lua | 46 +++++++++++ lua/plugins.lua | 156 ++++++++++++++++++++++++------------- lua/plugins/bufferline.lua | 19 +++++ lua/plugins/lspconfig.lua | 97 +++++++++++++++++++++++ lua/plugins/telescope.lua | 12 +++ lua/plugins/treesitter.lua | 21 +++++ lua/settings.lua | 9 --- lua/themes.lua | 2 +- 11 files changed, 333 insertions(+), 67 deletions(-) create mode 100644 .gitignore create mode 100644 lua/keymaps.lua create mode 100644 lua/options.lua create mode 100644 lua/plugins/bufferline.lua create mode 100644 lua/plugins/lspconfig.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/treesitter.lua delete mode 100644 lua/settings.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87553b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/plugin/ diff --git a/init.lua b/init.lua index 3518476..49b81ae 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,4 @@ -require('settings') +require("keymaps") +require('options') require('plugins') require('themes') - -vim.cmd('COQnow -s') diff --git a/lua/keymaps.lua b/lua/keymaps.lua new file mode 100644 index 0000000..4529acc --- /dev/null +++ b/lua/keymaps.lua @@ -0,0 +1,32 @@ +-- source file everytime it changes +vim.cmd([[ + augroup user_keymaps + autocmd! + autocmd BufWritePost keymaps.lua source + augroup end +]]) + +local function nnoremap(key, command) + vim.api.nvim_set_keymap("n",key,command, { noremap = true, silent = true }) +end + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- Move around windows +nnoremap("", "h") +nnoremap("", "j") +nnoremap("", "k") +nnoremap("", "l") + +-- Switch buffers +nnoremap("", ":TablineBufferNext") +nnoremap("", ":TablineBufferPrevious") + +-- fugitive +nnoremap("G", ":tab G") + +-- telescope +nnoremap("ff", "Telescope find_files theme=dropdown") +nnoremap("fb", "Telescope buffers theme=dropdown") +nnoremap("fg", "Telescope git_files theme=dropdown") diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..7c442f9 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,46 @@ +-- source file everytime it changes +vim.cmd([[ + augroup user_options + autocmd! + autocmd BufWritePost options.lua source + augroup end +]]) + +-- termguicolors +vim.opt.termguicolors = true + +-- line numbers +vim.opt.number = true + +-- tabwidth +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 + +-- indent with spaces +vim.opt.expandtab = true + +-- scroll offset +vim.opt.scrolloff = 4 + +-- don't warp lines +vim.opt.wrap = false + +-- split to right/below +vim.opt.splitright = true +vim.opt.splitbelow = true + +-- presistent undo +vim.opt.undofile = true + +-- searching +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- preview commands +vim.opt.inccommand = "split" + +-- enable cursorline +vim.opt.cursorline = true + +-- coq.nvim +vim.g.coq_settings = { auto_start = "shut-up" } diff --git a/lua/plugins.lua b/lua/plugins.lua index fda895d..ec54bce 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,77 +1,125 @@ local fn = vim.fn -local cmd = vim.cmd --- Boostrap Packer -local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' +-- boostrap packer +local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim' local packer_bootstrap if fn.empty(fn.glob(install_path)) > 0 then - packer_bootstrap = fn.system({'git', 'clone','https://github.com/wbthomason/packer.nvim', install_path}) + packer_bootstrap = fn.system({'git', 'clone','https://github.com/wbthomason/packer.nvim', install_path}) end --- Rerun PackerSync everytime plugins.lua is updated -cmd([[ +-- run PackerSync everytime plugins.lua is updated +vim.cmd([[ augroup packer_user_config autocmd! autocmd BufWritePost plugins.lua source | PackerSync augroup end ]]) --- Initialize pluggins +vim.cmd([[packadd packer.nvim]]) + +-- initialize plugins return require('packer').startup(function(use) - -- Let Packer manage itself - use('wbthomason/packer.nvim') + -- let packer manage itself + use({'wbthomason/packer.nvim', opt = true}) - -- Themes - use('altercation/vim-colors-solarized') + -- theme + use("ishan9299/nvim-solarized-lua") - -- session handling - use('tpope/vim-obsession') - use('dhruvasagar/vim-prosession') + -- commenting + use("tpope/vim-commentary") - -- status line - use { - 'nvim-lualine/lualine.nvim', - requires = { 'kyazdani42/nvim-web-devicons', opt = true }, - config = function() - require('lualine').setup() - end - } + -- session handling + use('tpope/vim-obsession') + use('dhruvasagar/vim-prosession') - -- git commands - use({ - "lukas-reineke/indent-blankline.nvim", - config = function () - require("indent_blankline").setup { - char = "┊", - buftype_exclude = {"terminal", "help"} - } - end - }) + -- status line + use { + 'nvim-lualine/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons', opt = true }, + config = function() + require('lualine').setup() + end + } - -- language server - use("neovim/nvim-lspconfig") + -- tabline + use { + 'kdheepak/tabline.nvim', + config = function() + require'tabline'.setup { + enable = true, + options = { + show_filename_only = true, + } + } + end, + requires = { { 'hoob3rt/lualine.nvim' }, {'kyazdani42/nvim-web-devicons', opt = true} } + } - -- autocompletion - use({ - "ms-jpq/coq_nvim", - branch="coq", - }) - use({'ms-jpq/coq.artifacts', branch = 'artifacts'}) + -- blankline + use({ + "lukas-reineke/indent-blankline.nvim", + config = function () + require("indent_blankline").setup { + char = "┊", + buftype_exclude = {"terminal", "help"} + } + end + }) - local language_servers = { "bashls", "rls", "sumneko_lua" } - for _, server in pairs(language_servers) do - require("lspconfig")[server].setup(require("coq").lsp_ensure_capabilities({})) - end + -- git + use('tpope/vim-fugitive') + use ({ + 'lewis6991/gitsigns.nvim', + requires = {'nvim-lua/plenary.nvim'}, + config = function() require('gitsigns').setup() end + }) - use('tpope/vim-fugitive') - use ({ - 'lewis6991/gitsigns.nvim', - requires = {'nvim-lua/plenary.nvim'}, - config = function() require('gitsigns').setup() end - }) + -- autocompletion + use({ + "ms-jpq/coq_nvim", + branch="coq", + requires = { + {'ms-jpq/coq.artifacts', branch = 'artifacts'}, + }, + }) - if packer_bootstrap then - require('packer').sync() - end + -- highlight current symbol + use({ + "nvim-treesitter/nvim-treesitter-refactor", + config = function () require("nvim-treesitter.configs").setup({ + refactor = { + highlight_definitions = { + enable = true, + clear_on_cursor_move = true, + }, + } + }) + end, + }) + + -- language server + use({ + "neovim/nvim-lspconfig", + config = function() require("plugins.lspconfig") end, + }) + + use('williamboman/nvim-lsp-installer') + + -- treesitter + use({ + 'nvim-treesitter/nvim-treesitter', + config = function() require('plugins.treesitter') end, + run = ':TSUpdate' + }) + + -- Telescope + use({ + 'nvim-telescope/telescope.nvim', + requires = {{'nvim-lua/plenary.nvim'}}, + config = function() require('plugins.telescope') end, + }) + + if packer_bootstrap then + require('packer').sync() + end end) - diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..6d4163d --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,19 @@ +require('bufferline') + +-- format as ". " +local tabname_format = function (opts) + return string.format('%s.', opts.ordinal) +end + +require('bufferline').setup({ + options = { + always_show_bufferline = true, + numbers = tabname_format, + show_buffer_icons = true, + show_buffer_close_icons = false, + show_close_icon = false, + --separator_style = 'slant', + }, + -- Don't use italic on current buffer + highlights = {buffer_selected = { gui = "bold" },}, +}) diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..e7d575c --- /dev/null +++ b/lua/plugins/lspconfig.lua @@ -0,0 +1,97 @@ +local coq = require("coq") +local lsp_installer = require("nvim-lsp-installer") + +local nvim_runtime_path = vim.split(package.path, ';') +table.insert(nvim_runtime_path, "lua/?.lua") +table.insert(nvim_runtime_path, "lua/?/init.lua") + +local language_servers = { + "ansiblels", + "bashls", + "dockerls", + "eslint", + "html", + "pyright", + "remark_ls", + "rust_analyzer", + "sumneko_lua", + "svelte", + "taplo", + "tsserver", + "volar", +} + +for _, server_name in pairs(language_servers) do + local server_found, server = lsp_installer.get_server(server_name) + if server_found and not server:is_installed() then + print("Installing " .. server_name) + server:install() + end + +end + +local extra_server_opts = { + ["sumneko_lua"] = function(opts) + opts.settings = { + Lua = { + runtime = { + version = 'LuaJIT', + path = nvim_runtime_path, + }, + diagnostics = { + globals = {'vim'}, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry ={ + enable = false, + }, + }, + } + end +} + +local function custom_on_attach(client, buffer_nr) + -- Helper function + local opts = {noremap = true, silent = true} + local function bufnnoremap(key, action) + vim.api.nvim_buf_set_keymap(buffer_nr, 'n', key, action, opts) + end + + -- Inspect function + bufnnoremap("K", "lua vim.lsp.buf.hover()") + + -- Rename all references of symbol + bufnnoremap("R", "lua vim.lsp.buf.rename()") + + -- Navigate diagnostics + bufnnoremap("", "lua vim.diagnostic.goto_next()") + bufnnoremap("", "lua vim.diagnostic.goto_prev()") + + -- Show line diagnostics + bufnnoremap("d", 'lua vim.diagnostic.open_float(0, {scope = "line"})') + + -- Open local diagnostics in local list + bufnnoremap("D", "lua vim.diagnostic.setloclist()") + + -- Open all project diagnostics in quickfix list + bufnnoremap("", "lua vim.diagnostic.setqflist()") + + if client.resolved_capabilities.document_formatting then + vim.cmd("autocmd BufWritePre lua vim.lsp.buf.formatting_sync()") + end +end + +lsp_installer.on_server_ready(function(server) + local opts = coq.lsp_ensure_capabilities({ + on_attach = custom_on_attach, + capabilities = vim.lsp.protocol.make_client_capabilities(), + }) + + if extra_server_opts[server.name] then + extra_server_opts[server.name](opts) + end + + server:setup(opts) +end) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..eef9e52 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,12 @@ +local actions = require("telescope.actions") + +require('telescope').setup({ + defaults = { + mappings = { + i = { + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + }, + }, + }, +}) diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..c424398 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,21 @@ +require('nvim-treesitter.configs').setup({ + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + indent = { + enable = true, + }, + ensure_installed = { + "bash", + "c", + "cpp", + "json", + "lua", + "markdown", + "python", + "rust", + "vim", + "yaml", + }, +}) diff --git a/lua/settings.lua b/lua/settings.lua deleted file mode 100644 index b6a4fc7..0000000 --- a/lua/settings.lua +++ /dev/null @@ -1,9 +0,0 @@ --- source file everytime it changes -vim.cmd([[ - augroup user_settings - autocmd! - autocmd BufWritePost settings.lua source - augroup end -]]) - -vim.opt.number = true diff --git a/lua/themes.lua b/lua/themes.lua index 676b966..53bc916 100644 --- a/lua/themes.lua +++ b/lua/themes.lua @@ -6,5 +6,5 @@ vim.cmd([[ augroup end ]]) -vim.cmd [[colorscheme solarized]] vim.opt.background = 'dark' +vim.cmd("colorscheme solarized")