Merge remote-tracking branch 'nvim/main'

This commit is contained in:
mandlm 2022-02-24 20:41:13 +01:00
commit a6156e117d
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
10 changed files with 429 additions and 0 deletions

1
nvim/.gitignore vendored Normal file
View File

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

4
nvim/init.lua Normal file
View File

@ -0,0 +1,4 @@
require("keymaps")
require('options')
require('plugins')
require('themes')

49
nvim/lua/keymaps.lua Normal file
View File

@ -0,0 +1,49 @@
-- 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})
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", ":Git<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>")
nnoremap("<C-f>", "<Cmd>Telescope grep_string<CR>")
nnoremap("<C-g>", "<Cmd>Telescope live_grep<CR>")
-- terminal
function _G.set_terminal_keymaps()
local opts = {noremap = true}
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-h>', [[<C-\><C-n><C-W>h]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-j>', [[<C-\><C-n><C-W>j]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-k>', [[<C-\><C-n><C-W>k]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-l>', [[<C-\><C-n><C-W>l]], opts)
end
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
-- buffer closing
nnoremap("<leader>q", ":Bdelete<CR>")

57
nvim/lua/options.lua Normal file
View File

@ -0,0 +1,57 @@
-- 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"
-- set cursorline in active window
vim.cmd([[
augroup CursorLine
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
augroup END
]])
-- coq.nvim
vim.g.coq_settings = {
auto_start = "shut-up",
keymap = {
jump_to_mark = "" -- prevent <C-h> remapping
}
}

135
nvim/lua/plugins.lua Normal file
View File

@ -0,0 +1,135 @@
local fn = vim.fn
-- 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
})
end
-- run PackerSync everytime plugins.lua is updated
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerSync
augroup end
]])
vim.cmd([[packadd packer.nvim]])
-- initialize plugins
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
use('tpope/vim-obsession')
use('dhruvasagar/vim-prosession')
-- status line
use {
'nvim-lualine/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true},
config = function() require('lualine').setup() end
}
-- 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({
"lukas-reineke/indent-blankline.nvim",
config = function()
require("indent_blankline").setup {
char = "",
buftype_exclude = {"terminal", "help", "nofile"},
filetype_exclude = {'help', 'packer'},
show_trailing_blankline_indent = false
}
end
})
-- git
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'}}
})
-- highlight current symbol
use({"RRethy/vim-illuminate"})
-- 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
})
use({'nvim-telescope/telescope-fzf-native.nvim', run = 'make'})
-- automatic pairs
use({"Raimondi/delimitMate"})
-- markdown preview
use({'iamcco/markdown-preview.nvim'})
-- terminal
use({
"akinsho/nvim-toggleterm.lua",
config = function()
require("toggleterm").setup({size = 32, open_mapping = [[<F4>]]})
end
})
-- buffer closing
use({"sar/bbye.nvim"})
-- ansible filetype
use({"pearofducks/ansible-vim"})
if packer_bootstrap then require('packer').sync() 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" },},
})

View File

@ -0,0 +1,123 @@
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", "efm", "eslint", "html", "pyright",
"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 = {
["efm"] = function(opts)
opts.filetypes = {
"lua", "html", "markdown", "typescript", "typescriptreact"
}
opts.init_options = {documentFormatting = true}
opts.settings = {
rootMarkers = {".git/"},
languages = {
lua = {{formatCommand = "lua-format -i", formatStdin = true}},
html = {
{formatCommand = "yarn run --silent prettier --parser html"}
},
typescript = {
{
formatCommand = "yarn run --silent prettier --parser typescript"
}
},
typescriptreact = {
{
formatCommand = "yarn run --silent prettier --parser typescript"
}
},
markdown = {
{
formatCommand = "yarn run --silent prettier --parser markdown"
}
}
}
-- prettier-parser
-- flow|babel|babel-flow|babel-ts|typescript|espree|meriyah|css|
-- less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|glimmer|html|angular|lwc
}
end,
["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)
-- onmifunc
vim.api.nvim_buf_set_option(buffer_nr, "omnifunc", "v:lua.vim.lsp.omnifunc")
-- 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>")
bufnnoremap("<C-k>", "<Cmd>lua vim.lsp.buf.signature_help()<CR>")
-- Navigation
bufnnoremap("gd", "<Cmd>lua vim.lsp.buf.definition()<CR>")
bufnnoremap("gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>")
bufnnoremap("gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>")
bufnnoremap("gr", "<Cmd>lua vim.lsp.buf.references()<CR>")
bufnnoremap("ga", "<Cmd>Telescope lsp_code_actions theme=cursor<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>")
-- Open diagnostics
bufnnoremap("<leader>d", "<Cmd>Telescope diagnostics<CR>")
-- disable conflicting formatters
if client.name == "tsserver" or client.name == "html" then
client.resolved_capabilities.document_formatting = false
end
if client.resolved_capabilities.document_formatting then
vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
end
-- vim-illuminate
require("illuminate").on_attach(client)
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)

View File

@ -0,0 +1,22 @@
local actions = require("telescope.actions")
require('telescope').setup({
defaults = {
mappings = {
i = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous
},
n = {['<C-c>'] = actions.close}
}
},
extensions = {
fzf = {
fuzzy = true,
override_generic_sorter = true,
override_file_sorter = true
}
}
})
require('telescope').load_extension('fzf')

View File

@ -0,0 +1,9 @@
require('nvim-treesitter.configs').setup({
highlight = {enable = true, additional_vim_regex_highlighting = false},
indent = {enable = true},
ensure_installed = {
"bash", "c", "cpp", "css", "dockerfile", "html", "javascript", "json",
"latex", "lua", "markdown", "python", "rust", "svelte", "toml", "tsx",
"typescript", "vim", "vue", "yaml"
}
})

10
nvim/lua/themes.lua Normal file
View File

@ -0,0 +1,10 @@
-- source file everytime it changes
vim.cmd([[
augroup user_theme_config
autocmd!
autocmd BufWritePost themes.lua source <afile>
augroup end
]])
vim.opt.background = 'dark'
vim.cmd("colorscheme solarized")