feat: finalized config

This commit is contained in:
Michael Mandl 2022-02-21 15:15:15 +01:00
parent 28057baf5f
commit c341636729
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
11 changed files with 333 additions and 67 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/plugin/

View file

@ -1,5 +1,4 @@
require('settings') require("keymaps")
require('options')
require('plugins') require('plugins')
require('themes') require('themes')
vim.cmd('COQnow -s')

32
lua/keymaps.lua Normal file
View file

@ -0,0 +1,32 @@
-- source file everytime it changes
vim.cmd([[
augroup user_keymaps
autocmd!
autocmd BufWritePost keymaps.lua source <afile>
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("<C-h>", "<C-w>h")
nnoremap("<C-j>", "<C-w>j")
nnoremap("<C-k>", "<C-w>k")
nnoremap("<C-l>", "<C-w>l")
-- Switch buffers
nnoremap("<TAB>", ":TablineBufferNext<CR>")
nnoremap("<S-TAB>", ":TablineBufferPrevious<CR>")
-- fugitive
nnoremap("<leader>G", ":tab G<CR>")
-- telescope
nnoremap("<leader>ff", "<Cmd>Telescope find_files theme=dropdown<CR>")
nnoremap("<leader>fb", "<Cmd>Telescope buffers theme=dropdown<CR>")
nnoremap("<leader>fg", "<Cmd>Telescope git_files theme=dropdown<CR>")

46
lua/options.lua Normal file
View file

@ -0,0 +1,46 @@
-- source file everytime it changes
vim.cmd([[
augroup user_options
autocmd!
autocmd BufWritePost options.lua source <afile>
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" }

View file

@ -1,28 +1,32 @@
local fn = vim.fn local fn = vim.fn
local cmd = vim.cmd
-- Boostrap Packer -- boostrap packer
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'
local packer_bootstrap local packer_bootstrap
if fn.empty(fn.glob(install_path)) > 0 then 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 end
-- Rerun PackerSync everytime plugins.lua is updated -- run PackerSync everytime plugins.lua is updated
cmd([[ vim.cmd([[
augroup packer_user_config augroup packer_user_config
autocmd! autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerSync autocmd BufWritePost plugins.lua source <afile> | PackerSync
augroup end augroup end
]]) ]])
-- Initialize pluggins vim.cmd([[packadd packer.nvim]])
return require('packer').startup(function(use)
-- Let Packer manage itself
use('wbthomason/packer.nvim')
-- Themes -- initialize plugins
use('altercation/vim-colors-solarized') return require('packer').startup(function(use)
-- let packer manage itself
use({'wbthomason/packer.nvim', opt = true})
-- theme
use("ishan9299/nvim-solarized-lua")
-- commenting
use("tpope/vim-commentary")
-- session handling -- session handling
use('tpope/vim-obsession') use('tpope/vim-obsession')
@ -37,7 +41,21 @@ return require('packer').startup(function(use)
end end
} }
-- git commands -- 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} }
}
-- blankline
use({ use({
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",
config = function () config = function ()
@ -48,21 +66,7 @@ return require('packer').startup(function(use)
end end
}) })
-- language server -- git
use("neovim/nvim-lspconfig")
-- autocompletion
use({
"ms-jpq/coq_nvim",
branch="coq",
})
use({'ms-jpq/coq.artifacts', branch = 'artifacts'})
local language_servers = { "bashls", "rls", "sumneko_lua" }
for _, server in pairs(language_servers) do
require("lspconfig")[server].setup(require("coq").lsp_ensure_capabilities({}))
end
use('tpope/vim-fugitive') use('tpope/vim-fugitive')
use ({ use ({
'lewis6991/gitsigns.nvim', 'lewis6991/gitsigns.nvim',
@ -70,8 +74,52 @@ return require('packer').startup(function(use)
config = function() require('gitsigns').setup() end config = function() require('gitsigns').setup() end
}) })
-- autocompletion
use({
"ms-jpq/coq_nvim",
branch="coq",
requires = {
{'ms-jpq/coq.artifacts', branch = 'artifacts'},
},
})
-- 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 if packer_bootstrap then
require('packer').sync() require('packer').sync()
end end
end) end)

View file

@ -0,0 +1,19 @@
require('bufferline')
-- format as "<id>. <file-name>"
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" },},
})

97
lua/plugins/lspconfig.lua Normal file
View file

@ -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", "<Cmd>lua vim.lsp.buf.hover()<CR>")
-- Rename all references of symbol
bufnnoremap("<leader>R", "<Cmd>lua vim.lsp.buf.rename()<CR>")
-- Navigate diagnostics
bufnnoremap("<C-n>", "<Cmd>lua vim.diagnostic.goto_next()<CR>")
bufnnoremap("<C-p>", "<Cmd>lua vim.diagnostic.goto_prev()<CR>")
-- Show line diagnostics
bufnnoremap("<leader>d", '<Cmd>lua vim.diagnostic.open_float(0, {scope = "line"})<CR>')
-- Open local diagnostics in local list
bufnnoremap("<leader>D", "<Cmd>lua vim.diagnostic.setloclist()<CR>")
-- Open all project diagnostics in quickfix list
bufnnoremap("<leader><C-d>", "<Cmd>lua vim.diagnostic.setqflist()<CR>")
if client.resolved_capabilities.document_formatting then
vim.cmd("autocmd BufWritePre <buffer> 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)

12
lua/plugins/telescope.lua Normal file
View file

@ -0,0 +1,12 @@
local actions = require("telescope.actions")
require('telescope').setup({
defaults = {
mappings = {
i = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
},
},
},
})

View file

@ -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",
},
})

View file

@ -1,9 +0,0 @@
-- source file everytime it changes
vim.cmd([[
augroup user_settings
autocmd!
autocmd BufWritePost settings.lua source <afile>
augroup end
]])
vim.opt.number = true

View file

@ -6,5 +6,5 @@ vim.cmd([[
augroup end augroup end
]]) ]])
vim.cmd [[colorscheme solarized]]
vim.opt.background = 'dark' vim.opt.background = 'dark'
vim.cmd("colorscheme solarized")