[nvim] format: tabstop=8 -> 4 for lua files

This commit is contained in:
David JULIEN 2022-04-27 21:58:12 +02:00
parent bc67eb8ffe
commit d9e7f76a5f
13 changed files with 593 additions and 591 deletions

View File

@ -4,10 +4,10 @@
-- Description : c settings file -- Description : c settings file
local opt = vim.opt local opt = vim.opt
local g = vim.g local g = vim.g
opt.formatoptions = "trq1jp" opt.formatoptions = "trq1jp"
-- Snippets -- Snippets
local ls = require("luasnip") local ls = require("luasnip")
@ -21,14 +21,14 @@ local f = ls.function_node
local copy = utils.copy local copy = utils.copy
ls.snippets = { ls.snippets = {
c = { c = {
s("main", { s("main", {
t({ "int main(int argc, char* argv[])" }), t({ "int main(int argc, char* argv[])" }),
t({ "", "{", "\t" }), t({ "", "{", "\t" }),
i(0), i(0),
t({ "", "\treturn 0;"}), t({ "", "\treturn 0;"}),
t({ "", "}"}), t({ "", "}"}),
}), }),
s("fn", { s("fn", {
-- Simple static text. -- Simple static text.
t("//Parameters: "), t("//Parameters: "),
@ -43,9 +43,9 @@ ls.snippets = {
i(2, "int foo"), i(2, "int foo"),
-- Linebreak -- Linebreak
t({ ")", "{", "\t" }), t({ ")", "{", "\t" }),
i(0), i(0),
t({ "", "\treturn 0;"}), t({ "", "\treturn 0;"}),
t({ "", "}"}), t({ "", "}"}),
}), }),
}, },
} }

View File

@ -6,4 +6,5 @@
local opt = vim.opt local opt = vim.opt
local g = vim.g local g = vim.g
opt.formatoptions = "trq1jp" opt.formatoptions = "trq1jp"
opt.tabstop = 4

View File

@ -4,11 +4,10 @@
-- Description : tex filetype config -- Description : tex filetype config
local opt = vim.opt local opt = vim.opt
local g = vim.g
opt.formatoptions = "trq1jp" opt.formatoptions = "trq1jp"
opt.tabstop = 4 opt.tabstop = 4
-- Caps -- Caps
utils.map("i", "AA", "À") utils.map("i", "AA", "À")
@ -23,15 +22,15 @@ utils.map("i", "<Space>:", "\\,:")
local ls = require("luasnip") local ls = require("luasnip")
-- some shorthands... -- some shorthands...
local s = ls.snippet local s = ls.snippet
local sn = ls.snippet_node local sn = ls.snippet_node
local t = ls.text_node local t = ls.text_node
local i = ls.insert_node local i = ls.insert_node
local f = ls.function_node local f = ls.function_node
local c = ls.choice_node local c = ls.choice_node
local d = ls.dynamic_node local d = ls.dynamic_node
local copy = utils.copy local copy = utils.copy
-- 'recursive' dynamic snippet. Expands to some text followed by itself. -- 'recursive' dynamic snippet. Expands to some text followed by itself.
local function rec_ls() local function rec_ls()
@ -46,85 +45,85 @@ local function rec_ls()
end end
ls.snippets = { ls.snippets = {
tex = { tex = {
-- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many -- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many
-- \item as necessary by utilizing a choiceNode. -- \item as necessary by utilizing a choiceNode.
s("ls", { s("ls", {
t({ "\\begin{itemize}", "\t\\item " }), t({ "\\begin{itemize}", "\t\\item " }),
i(1), i(1),
t({ "" }), t({ "" }),
d(2, rec_ls, {}), d(2, rec_ls, {}),
t({ "", "\\end{itemize}", "" }), t({ "", "\\end{itemize}", "" }),
}), }),
s("lsl", { s("lsl", {
t({ "\\begin{itemize}[label=" }), t({ "\\begin{itemize}[label=" }),
i(1), i(1),
t( { "]", "\t\\item " }), t( { "]", "\t\\item " }),
i(2), i(2),
t({ "" }), t({ "" }),
d(3, rec_ls, {}), d(3, rec_ls, {}),
t({ "", "\\end{itemize}", "" }), t({ "", "\\end{itemize}", "" }),
}), }),
s("frm", { s("frm", {
t({ "\\begin{" }), t({ "\\begin{" }),
i(1), i(1),
t({ "}[" }), t({ "}[" }),
i(2), i(2),
t({ "]{" }), t({ "]{" }),
f(copy, 1), f(copy, 1),
t({ ":" }), t({ ":" }),
i(3, "foo"), i(3, "foo"),
t({ "}", "\t" }), t({ "}", "\t" }),
i(0), i(0),
t({ "", "\\end{" }), t({ "", "\\end{" }),
f(copy, 1), f(copy, 1),
t({ "}", "" }), t({ "}", "" }),
}), }),
s("env", { s("env", {
t({ "\\begin{" }), t({ "\\begin{" }),
i(1, "foo"), i(1, "foo"),
t({ "}", "\t" }), t({ "}", "\t" }),
i(2), i(2),
t({ "", "\\end{" }), t({ "", "\\end{" }),
f(copy,1), f(copy,1),
t({ "}"}), t({ "}"}),
}), }),
s("tikz", { s("tikz", {
t({ "\\begin{center}" }), t({ "\\begin{center}" }),
t({ "", "\t\\begin{tikzpicture}[main/.style = {draw,circle}]", "\t\t" }), t({ "", "\t\\begin{tikzpicture}[main/.style = {draw,circle}]", "\t\t" }),
i(1), i(1),
t({ "", "\t\\end{tikzpicture}", "\\end{center}" }), t({ "", "\t\\end{tikzpicture}", "\\end{center}" }),
}), }),
s("ra", { t( "\\rightarrow" )}), s("ra", { t( "\\rightarrow" )}),
s("Ra", { t("\\Rightarrow" )}), s("Ra", { t("\\Rightarrow" )}),
s("la", { t("\\leftarrow" )}), s("la", { t("\\leftarrow" )}),
s("La", { t("\\Leftarrow" )}), s("La", { t("\\Leftarrow" )}),
s("lra", { t("\\leftrightarrow" )}), s("lra", { t("\\leftrightarrow" )}),
s("Lra", { t("\\Leftrightarrow" )}), s("Lra", { t("\\Leftrightarrow" )}),
s("bb", { s("bb", {
t({ "\\textbf{" }), t({ "\\textbf{" }),
i(1), i(1),
t({ "}"}), t({ "}"}),
}), }),
s("tt", { s("tt", {
t({ "\\texttt{" }), t({ "\\texttt{" }),
i(1), i(1),
t({ "}"}), t({ "}"}),
}), }),
s("ii", { s("ii", {
t({ "\\textit{" }), t({ "\\textit{" }),
i(1), i(1),
t({ "}"}), t({ "}"}),
}), }),
s("uu", { s("uu", {
t({ "\\underline{" }), t({ "\\underline{" }),
i(1), i(1),
t({ "}"}), t({ "}"}),
}), }),
s("fsc", { s("fsc", {
t({ "\\textsc{" }), t({ "\\textsc{" }),
i(1), i(1),
t({ "}"}), t({ "}"}),
}), }),
}, },
} }

View File

@ -9,5 +9,5 @@ local file = os.getenv("XDG_STATE_HOME") .. "/nvim_colorscheme"
local colorscheme = utils.lines_from(file)[0] local colorscheme = utils.lines_from(file)[0]
require("astronomy").setup { require("astronomy").setup {
variant = colorscheme, variant = colorscheme,
} }

View File

@ -6,13 +6,11 @@
local M = {} -- The module to export local M = {} -- The module to export
M = { M = {
lsp_path = vim.fn.stdpath("data").. "/lsp", -- misc
sign_error = "",
-- misc sign_warning = "",
sign_error = "", sign_hint = "",
sign_warning = "", sign_info = "",
sign_hint = "",
sign_info = "",
} }
-- Make it accessible everywhere -- Make it accessible everywhere

View File

@ -8,9 +8,9 @@ vim.g.mapleader = " "
-- Dealing with word wrap -- Dealing with word wrap
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'",
{ expr = true, silent = true }) { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'",
{ expr = true, silent = true }) { expr = true, silent = true })
vim.keymap.set("n", "<leader>y", "\"+y") vim.keymap.set("n", "<leader>y", "\"+y")
vim.keymap.set("n", "<leader>p", "\"+P") vim.keymap.set("n", "<leader>p", "\"+P")
@ -19,14 +19,15 @@ vim.keymap.set("n", "<leader>u", function() require("packer").sync() end)
-- telescope -- telescope
vim.keymap.set("n", "<leader>ff", vim.keymap.set("n", "<leader>ff",
function() require("telescope.builtin").find_files() end) function() require("telescope.builtin").find_files() end)
vim.keymap.set("n", "<leader>fb", vim.keymap.set("n", "<leader>fb",
function() require("telescope.builtin").buffers() end) function() require("telescope.builtin").buffers() end)
vim.keymap.set("n", "<leader>fl", vim.keymap.set("n", "<leader>fl",
function() require("telescope.builtin").live_grep() end) function() require("telescope.builtin").live_grep() end)
-- colorscheme -- colorscheme
vim.keymap.set("n", "<C-s>", function() require("astronomy").toggle_variant() end) vim.keymap.set("n", "<C-s>",
function() require("astronomy").toggle_variant() end)
-- snippets -- snippets
vim.keymap.set({ "i", "s" }, "<C-E>", "<Plug>luasnip-next-choice") vim.keymap.set({ "i", "s" }, "<C-E>", "<Plug>luasnip-next-choice")

View File

@ -8,76 +8,76 @@ local luasnip = require("luasnip")
local cmp_autopairs = require('nvim-autopairs.completion.cmp') local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local check_backspace = function() local check_backspace = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]: vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:
sub(col, col):match('%s') == nil sub(col, col):match('%s') == nil
end end
-- If you want insert `(` after select function or method item -- If you want insert `(` after select function or method item
cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } }))
cmp.setup { cmp.setup {
completion = { completion = {
autocomplete = false autocomplete = false
}, },
sources = { sources = {
{ name = "path" }, { name = "path" },
{ name = "luasnip" }, { name = "luasnip" },
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "buffer" }, { name = "buffer" },
{ name = "nvim_lua" }, { name = "nvim_lua" },
{ name = "calc" }, { name = "calc" },
{ name = "spell" }, { name = "spell" },
{ name = "treesitter" }, { name = "treesitter" },
}, },
formatting = { formatting = {
format = function(entry, vim_item) format = function(entry, vim_item)
vim_item.menu = ({ vim_item.menu = ({
nvim_lsp = "[lsp]", nvim_lsp = "[lsp]",
nvim_lua = "[nvim]", nvim_lua = "[nvim]",
luasnip = "[snip]", luasnip = "[snip]",
path = "[path]", path = "[path]",
buffer = "[buff]", buffer = "[buff]",
calc = "[calc]", calc = "[calc]",
spell = "[spel]", spell = "[spel]",
treesitter = "[tree]", treesitter = "[tree]",
})[entry.source.name] })[entry.source.name]
return vim_item return vim_item
end, end,
}, },
snippet = { snippet = {
expand = function(args) expand = function(args)
require("luasnip").lsp_expand(args.body) require("luasnip").lsp_expand(args.body)
end, end,
}, },
mapping = { mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4), ["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4), ["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(), ["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({ ["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true,
}), }),
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
elseif check_backspace() then elseif check_backspace() then
cmp.complete() cmp.complete()
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.jumpable(-1) then elseif luasnip.jumpable(-1) then
luasnip.jump(-1) luasnip.jump(-1)
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
} }
} }

View File

@ -6,72 +6,72 @@
local M = {} local M = {}
vim.fn.sign_define( vim.fn.sign_define(
"DiagnosticSignError", "DiagnosticSignError",
{ {
texthl = "DiagnosticVirtualTextError", texthl = "DiagnosticVirtualTextError",
text = globals.sign_error, text = globals.sign_error,
numhl = "DiagnosticSignError" numhl = "DiagnosticSignError"
} }
) )
vim.fn.sign_define( vim.fn.sign_define(
"DiagnosticSignWarn", "DiagnosticSignWarn",
{ {
texthl = "DiagnosticVirtualTextWarn", texthl = "DiagnosticVirtualTextWarn",
text = globals.sign_warning, text = globals.sign_warning,
numhl = "DiagnosticSignWarn" numhl = "DiagnosticSignWarn"
} }
) )
vim.fn.sign_define( vim.fn.sign_define(
"DiagnosticSignHint", "DiagnosticSignHint",
{ {
texthl = "DiagnosticVirtualTextHint", texthl = "DiagnosticVirtualTextHint",
text = globals.sign_hint, text = globals.sign_hint,
numhl = "DiagnosticSignHint" numhl = "DiagnosticSignHint"
} }
) )
vim.fn.sign_define( vim.fn.sign_define(
"DiagnosticSignInfo", "DiagnosticSignInfo",
{ {
texthl = "DiagnosticVirtualTextInfo", texthl = "DiagnosticVirtualTextInfo",
text = globals.sign_info, text = globals.sign_info,
numhl = "DiagnosticSignInfo" numhl = "DiagnosticSignInfo"
} }
) )
M.icons = { M.icons = {
Class = "", Class = "",
Color = "", Color = "",
Constant = " µ ", Constant = " µ ",
Constructor = "", Constructor = "",
Enum = "", Enum = "",
EnumMember = "", EnumMember = "",
Event = "", Event = "",
Field = "", Field = "",
File = "", File = "",
Folder = "", Folder = "",
Function = "", Function = "",
Keyword = "", Keyword = "",
Interface = "", Interface = "",
Method = "", Method = "",
Module = "", Module = "",
Operator = "", Operator = "",
Property = "", Property = "",
Reference = "", Reference = "",
Snippet = "", Snippet = "",
Struct = "", Struct = "",
Text = "", Text = "",
TypeParameter = "", TypeParameter = "",
Unit = "", Unit = "",
Value = "", Value = "",
Variable = "", Variable = "",
} }
function M.setup() function M.setup()
local kinds = vim.lsp.protocol.CompletionItemKind local kinds = vim.lsp.protocol.CompletionItemKind
for i, kind in ipairs(kinds) do for i, kind in ipairs(kinds) do
kinds[i] = M.icons[kind] or kind kinds[i] = M.icons[kind] or kind
end end
end end
return M return M

View File

@ -41,70 +41,72 @@ table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua") table.insert(runtime_path, "lua/?/init.lua")
local enhance_server_opts = { local enhance_server_opts = {
["clangd"] = function(opts) ["clangd"] = function(opts)
opts.settings = { opts.settings = {
cmd = { clangd_binary, cmd = { clangd_binary,
"--background-index", "--background-index",
"--suggest-missing-includes", "--suggest-missing-includes",
"--clang-tidy", "--clang-tidy",
"--header-insertion=iwyu" "--header-insertion=iwyu"
}, },
} }
end, end,
["sumneko_lua"] = function(opts) ["sumneko_lua"] = function(opts)
opts.settings = { opts.settings = {
Lua = { Lua = {
runtime = { runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) -- Tell the language server which version of Lua you're
version = 'LuaJIT', -- using (most likely LuaJIT in the case of Neovim)
-- Setup your lua path version = 'LuaJIT',
path = runtime_path, -- Setup your lua path
}, path = runtime_path,
diagnostics = { },
-- Get the language server to recognize the `vim` global diagnostics = {
globals = { -- Get the language server to recognize the `vim` global
"vim", globals = {
"globals", "vim",
"utils" "globals",
}, "utils"
}, },
workspace = { },
-- Make the server aware of Neovim runtime files workspace = {
library = -- Make the server aware of Neovim runtime files
vim.api.nvim_get_runtime_file("", true), library =
}, vim.api.nvim_get_runtime_file("", true),
-- Do not send telemetry data containing a randomized but unique identifier },
telemetry = { -- Do not send telemetry data containing a randomized but
enable = false, -- unique identifier
}, telemetry = {
}, enable = false,
} },
end, },
}
end,
} }
local on_attach = function(_, bufnr) local on_attach = function(_, bufnr)
local opts = { buffer = bufnr } local opts = { buffer = bufnr }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<leader>ln", vim.diagnostic.goto_next, opts) vim.keymap.set("n", "<leader>ln", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "<leader>lp", vim.diagnostic.goto_prev, opts) vim.keymap.set("n", "<leader>lp", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "<leader>lf", vim.lsp.buf.formatting, opts) vim.keymap.set("n", "<leader>lf", vim.lsp.buf.formatting, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts) vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<leader>wa", vim.keymap.set("n", "<leader>wa",
vim.lsp.buf.add_workspace_folder, opts) vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<leader>wr", vim.keymap.set("n", "<leader>wr",
vim.lsp.buf.remove_workspace_folder, opts) vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<leader>wl", function() vim.keymap.set("n", "<leader>wl", function()
vim.inspect(vim.lsp.buf.list_workspace_folders()) vim.inspect(vim.lsp.buf.list_workspace_folders())
end, opts) end, opts)
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, opts) vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts) vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<leader>so", vim.keymap.set("n", "<leader>so",
require("telescope.builtin").lsp_document_symbols, opts) require("telescope.builtin").lsp_document_symbols, opts)
end end
-- nvim-cmp supports additional completion capabilities -- nvim-cmp supports additional completion capabilities
@ -112,16 +114,16 @@ local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
lsp_installer.on_server_ready(function(server) lsp_installer.on_server_ready(function(server)
-- Specify the default options which we'll use to setup all servers -- Specify the default options which we'll use to setup all servers
local opts = { local opts = {
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
} }
if enhance_server_opts[server.name] then if enhance_server_opts[server.name] then
-- Enhance the default opts with the server-specific ones -- Enhance the default opts with the server-specific ones
enhance_server_opts[server.name](opts) enhance_server_opts[server.name](opts)
end end
server:setup(opts) server:setup(opts)
end) end)

View File

@ -6,98 +6,99 @@
local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
print("Cloning packer...") print("Cloning packer...")
PACKER_BOOTSTRAP = vim.fn.system({ PACKER_BOOTSTRAP = vim.fn.system({
"git", "git",
"clone", "clone",
"--depth", "--depth",
"1", "1",
"https://github.com/wbthomason/packer.nvim", "https://github.com/wbthomason/packer.nvim",
install_path, install_path,
}) })
vim.cmd([[packadd packer.nvim]]) vim.cmd([[packadd packer.nvim]])
print("Done.") print("Done.")
end end
local use = require("packer").use local use = require("packer").use
return require("packer").startup(function() return require("packer").startup(function()
-- packer manages itself -- packer manages itself
use "wbthomason/packer.nvim" use "wbthomason/packer.nvim"
-- colorscheme -- colorscheme
use { use {
"~/.local/src/astronomy.nvim", "~/.local/src/astronomy.nvim",
config = function() require("colorscheme") end config = function() require("colorscheme") end
} }
-- tree-sitter -- tree-sitter
use { use {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
run = ":TSUpdate", run = ":TSUpdate",
config = function() require("plugin.treesitter") end config = function() require("plugin.treesitter") end
} }
-- fuzzy finder -- fuzzy finder
use { use {
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
requires = { requires = {
{ {
"nvim-lua/plenary.nvim", "nvim-lua/plenary.nvim",
}, },
{'nvim-telescope/telescope-fzf-native.nvim', {
run = 'make' "nvim-telescope/telescope-fzf-native.nvim",
} run = "make"
}, }
} },
}
-- LSP -- LSP
use { use {
"williamboman/nvim-lsp-installer", "williamboman/nvim-lsp-installer",
requires = { requires = {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
config = function() config = function()
require("plugin.lsp_config").setup() end require("plugin.lsp_config").setup() end
}, },
config = function() require("plugin.lsp_installer") end config = function() require("plugin.lsp_installer") end
} }
-- auto completion -- auto completion
use { use {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
requires = { requires = {
{ {
"L3MON4D3/LuaSnip", "L3MON4D3/LuaSnip",
config = function() config = function()
require("plugin.luasnip") end require("plugin.luasnip") end
}, },
"saadparwaiz1/cmp_luasnip", "saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lua", "hrsh7th/cmp-nvim-lua",
"hrsh7th/cmp-buffer", "hrsh7th/cmp-buffer",
"hrsh7th/cmp-path", "hrsh7th/cmp-path",
"hrsh7th/cmp-calc", "hrsh7th/cmp-calc",
"ray-x/cmp-treesitter", "ray-x/cmp-treesitter",
"f3fora/cmp-spell", "f3fora/cmp-spell",
}, },
config = function() require("plugin.cmp") end config = function() require("plugin.cmp") end
} }
-- commenting, simplified -- commenting, simplified
use { use {
"numToStr/Comment.nvim", "numToStr/Comment.nvim",
config = function() require("plugin.comment") end config = function() require("plugin.comment") end
} }
-- autopairs -- autopairs
use { use {
"windwp/nvim-autopairs", "windwp/nvim-autopairs",
config = function() require('nvim-autopairs').setup() end config = function() require("nvim-autopairs").setup() end
} }
-- automatically setup the config after cloning -- automatically setup the config after cloning
if PACKER_BOOTSTRAP then if PACKER_BOOTSTRAP then
require("packer").sync() require("packer").sync()
end end
end) end)

View File

@ -4,12 +4,12 @@
-- Description : treesitter config file -- Description : treesitter config file
require("nvim-treesitter.configs").setup { require("nvim-treesitter.configs").setup {
ensure_installed = { "c", "lua", "python", "bash" }, ensure_installed = { "c", "lua", "python", "bash" },
ignore_install = { "javascript" }, ignore_install = { "javascript" },
highlight = { highlight = {
enable = true, enable = true,
}, },
indent = { indent = {
enable = true, enable = true,
}, },
} }

View File

@ -7,7 +7,7 @@ local opt = vim.opt
local g = vim.g local g = vim.g
-- general -- general
opt.wildignore = { opt.wildignore = {
".git", ".git",
"*.o", "*.class", "*.o", "*.class",
"*.jpg", "*.jpeg", "*.png", "*.jpg", "*.jpeg", "*.png",
@ -18,41 +18,41 @@ opt.wildmode = { "longest", "full" }
opt.wildoptions = "pum" opt.wildoptions = "pum"
-- editor -- editor
opt.lazyredraw = true opt.lazyredraw = true
opt.splitright = true opt.splitright = true
opt.splitbelow = true opt.splitbelow = true
opt.scrolloff = 4 opt.scrolloff = 4
opt.termguicolors = true opt.termguicolors = true
opt.background = "dark" opt.background = "dark"
opt.cursorline = true opt.cursorline = true
opt.shortmess = opt.shortmess:append { c = true } opt.shortmess = opt.shortmess:append { c = true }
opt.number = true opt.number = true
opt.relativenumber = true opt.relativenumber = true
opt.signcolumn = "yes" opt.signcolumn = "yes"
opt.listchars = { opt.listchars = {
tab = "<->", tab = "<->",
nbsp = "", nbsp = "",
trail = "·", trail = "·",
extends = ">", extends = ">",
precedes = "<", precedes = "<",
} }
opt.showmatch = true opt.showmatch = true
opt.ignorecase = true opt.ignorecase = true
opt.smartcase = true opt.smartcase = true
opt.inccommand = "split" opt.inccommand = "split"
opt.completeopt = { "menuone", "noselect" } opt.completeopt = { "menuone", "noselect" }
-- statusline -- statusline
opt.laststatus = 2 opt.laststatus = 2
opt.showmode = false opt.showmode = false
-- text, tabs, indents -- text, tabs, indents
opt.textwidth = 79 opt.textwidth = 79
opt.shiftwidth = 8 opt.shiftwidth = 8
opt.softtabstop = -1 opt.softtabstop = -1
opt.expandtab = true opt.expandtab = true
opt.shiftwidth = 0 opt.shiftwidth = 0
opt.backspace = { "indent", "eol", "start" } opt.backspace = { "indent", "eol", "start" }
-- augroups -- augroups
utils.create_augroup({ utils.create_augroup({

View File

@ -6,204 +6,204 @@
local function gen_section(hl_string, items) local function gen_section(hl_string, items)
local out = "" local out = ""
for _, item in pairs(items) do for _, item in pairs(items) do
if item ~= "" then if item ~= "" then
out = out .. " " .. item out = out .. " " .. item
end
end
if out ~="" then
return hl_string .. out .. " "
else
return out
end end
end
if out ~="" then
return hl_string .. out .. " "
else
return out
end
end end
-- sensible names for vim modes -- sensible names for vim modes
local function get_mode(m) local function get_mode(m)
local mode_group = { local mode_group = {
["n"] = "Normal", ["n"] = "Normal",
["no"] = "O-Pending", ["no"] = "O-Pending",
["nov"] = "O-Pending", ["nov"] = "O-Pending",
["noV"] = "O-Pending", ["noV"] = "O-Pending",
["no"] = "O-Pending", ["no"] = "O-Pending",
["niI"] = "Normal", ["niI"] = "Normal",
["niR"] = "Normal", ["niR"] = "Normal",
["niV"] = "Normal", ["niV"] = "Normal",
["v"] = "Visual", ["v"] = "Visual",
["V"] = "V-Line", ["V"] = "V-Line",
[""] = "V-Block", [""] = "V-Block",
["s"] = "Select", ["s"] = "Select",
["S"] = "S-Line", ["S"] = "S-Line",
[""] = "S-Block", [""] = "S-Block",
["i"] = "Insert", ["i"] = "Insert",
["ic"] = "Insert", ["ic"] = "Insert",
["ix"] = "Insert", ["ix"] = "Insert",
["R"] = "Replace", ["R"] = "Replace",
["Rc"] = "Replace", ["Rc"] = "Replace",
["Rv"] = "V-Replace", ["Rv"] = "V-Replace",
["Rx"] = "Replace", ["Rx"] = "Replace",
["c"] = "Command", ["c"] = "Command",
["cv"] = "Ex", ["cv"] = "Ex",
["ce"] = "Ex", ["ce"] = "Ex",
["r"] = "Prompt", ["r"] = "Prompt",
["rm"] = "Prompt", ["rm"] = "Prompt",
["r?"] = "Prompt", ["r?"] = "Prompt",
["!"] = "Shell", ["!"] = "Shell",
["t"] = "Terminal", ["t"] = "Terminal",
} }
return mode_group[m] or "None" return mode_group[m] or "None"
end end
local function get_mode_display_name(m) local function get_mode_display_name(m)
local mode = { local mode = {
["Normal"] = "[ NRM ]", ["Normal"] = "[ NRM ]",
["O-Pending"] = "[ OTR ]", ["O-Pending"] = "[ OTR ]",
["Visual"] = "[ VSL ]", ["Visual"] = "[ VSL ]",
["V-Line"] = "[ V·L ]", ["V-Line"] = "[ V·L ]",
["V-Block"] = "[ V·B ]", ["V-Block"] = "[ V·B ]",
["Select"] = "[ SEL ]", ["Select"] = "[ SEL ]",
["S-Line"] = "[ S·L ]", ["S-Line"] = "[ S·L ]",
["S-Block"] = "[ S·B ]", ["S-Block"] = "[ S·B ]",
["Insert"] = "[ INS ]", ["Insert"] = "[ INS ]",
["Replace"] = "[ RPL ]", ["Replace"] = "[ RPL ]",
["Command"] = "[ CMD ]", ["Command"] = "[ CMD ]",
["Prompt"] = "[ PMT ]", ["Prompt"] = "[ PMT ]",
["Shell"] = "[ SHL ]", ["Shell"] = "[ SHL ]",
["Terminal"] = "[ TRM ]", ["Terminal"] = "[ TRM ]",
["None"] = "[ --- ]" ["None"] = "[ --- ]"
} }
return mode[m] return mode[m]
end end
-- get the highlight group for a mode group -- get the highlight group for a mode group
local function get_mode_color(m) local function get_mode_color(m)
local color = { local color = {
["Normal"] = "%#NormalMode#", ["Normal"] = "%#NormalMode#",
["O-Pending"] = "%#NormalMode#", ["O-Pending"] = "%#NormalMode#",
["Visual"] = "%#VisualMode#", ["Visual"] = "%#VisualMode#",
["V-Line"] = "%#VisualMode#", ["V-Line"] = "%#VisualMode#",
["V-Block"] = "%#VisualMode#", ["V-Block"] = "%#VisualMode#",
["Select"] = "%#NormalMode#", ["Select"] = "%#NormalMode#",
["S-Line"] = "%#NormalMode#", ["S-Line"] = "%#NormalMode#",
["S-Block"] = "%#NormalMode#", ["S-Block"] = "%#NormalMode#",
["Insert"] = "%#InsertMode#", ["Insert"] = "%#InsertMode#",
["Replace"] = "%#ReplaceMode#", ["Replace"] = "%#ReplaceMode#",
["Command"] = "%#CommandMode#", ["Command"] = "%#CommandMode#",
["Prompt"] = "%#NormalMode#", ["Prompt"] = "%#NormalMode#",
["Shell"] = "%#NormalMode#", ["Shell"] = "%#NormalMode#",
["Terminal"] = "%#NormalMode#", ["Terminal"] = "%#NormalMode#",
["None"] = "%#NormalMode#" ["None"] = "%#NormalMode#"
} }
return color[m] return color[m]
end end
-- from https://github.com/nvim-lua/lsp-status.nvim/blob/master/lua/lsp-status/diagnostics.lua -- from https://github.com/nvim-lua/lsp-status.nvim/blob/master/lua/lsp-status/diagnostics.lua
local function get_lsp_diagnostics(bufnr) local function get_lsp_diagnostics(bufnr)
local result = {} local result = {}
local levels = { local levels = {
errors = "Error", errors = "Error",
warnings = "Warn", warnings = "Warn",
info = "Info", info = "Info",
hints = "Hint" hints = "Hint"
} }
for k, level in pairs(levels) do for k, level in pairs(levels) do
local count = 0 local count = 0
local diags = vim.diagnostic.get(bufnr, { severity = level }) local diags = vim.diagnostic.get(bufnr, { severity = level })
for _, _ in pairs(diags) do for _, _ in pairs(diags) do
count = count + 1 count = count + 1
end
result[k] = count
end end
result[k] = count
end
return result return result
end end
local function process_diagnostics(prefix, n, hl) local function process_diagnostics(prefix, n, hl)
if n > 0 then if n > 0 then
return hl .. prefix .. n return hl .. prefix .. n
else else
return "" return ""
end end
end end
local function spell_check() local function spell_check()
if vim.wo.spell then if vim.wo.spell then
local lang = vim.o.spelllang local lang = vim.o.spelllang
return "[SPELL=" .. lang .. "]" return "[SPELL=" .. lang .. "]"
else else
return "" return ""
end end
end end
local function statusline_focused() local function statusline_focused()
local diagnostics = get_lsp_diagnostics() local diagnostics = get_lsp_diagnostics()
local mode = vim.fn.mode() local mode = vim.fn.mode()
local mg = get_mode(mode) local mg = get_mode(mode)
local accent_color = get_mode_color(mg) local accent_color = get_mode_color(mg)
local left = table.concat { local left = table.concat {
gen_section(accent_color, {get_mode_display_name(mg)}), gen_section(accent_color, {get_mode_display_name(mg)}),
gen_section("%#Middle#", {"%f"}), gen_section("%#Middle#", {"%f"}),
gen_section("%#Bottom#", {"%m", "%r"}), gen_section("%#Bottom#", {"%m", "%r"}),
gen_section( gen_section(
"%#Alert#", "%#Alert#",
{ {
process_diagnostics( process_diagnostics(
globals.sign_error .. " ", globals.sign_error .. " ",
diagnostics.errors, diagnostics.errors,
"%#DiagnosticVirtualTextError#" "%#DiagnosticVirtualTextError#"
), ),
process_diagnostics( process_diagnostics(
globals.sign_warning .. " ", globals.sign_warning .. " ",
diagnostics.warnings, diagnostics.warnings,
"%#DiagnosticVirtualTextWarn#" "%#DiagnosticVirtualTextWarn#"
), ),
process_diagnostics( process_diagnostics(
globals.sign_info .. " ", globals.sign_info .. " ",
diagnostics.info, diagnostics.info,
"%#DiagnosticVirtualTextInfo#" "%#DiagnosticVirtualTextInfo#"
) )
}
)
} }
local right = table.concat { )
gen_section( }
"%#Bottom#", local right = table.concat {
{ gen_section(
spell_check(), "%#Bottom#",
vim.bo.filetype {
} spell_check(),
), vim.bo.filetype
gen_section("%#Middle#", {"%03.p%%"}),
gen_section("%#Top#", {"-%03.c-"})
} }
),
gen_section("%#Middle#", {"%03.p%%"}),
gen_section("%#Top#", {"-%03.c-"})
}
return table.concat { return table.concat {
left, left,
"%#Statusline#", "%#Statusline#",
"%=", "%=",
right right
} }
end end
local function statusline_not_focused() local function statusline_not_focused()
return table.concat { return table.concat {
gen_section("%#StatuslineNF#", {"%f", "%m"}), gen_section("%#StatuslineNF#", {"%f", "%m"}),
"%=", "%=",
gen_section("%#StatuslineNF#", {"%03.p%%"}), gen_section("%#StatuslineNF#", {"%03.p%%"}),
gen_section("%#StatuslineNF#", {"-%03.c-"}) gen_section("%#StatuslineNF#", {"-%03.c-"})
} }
end end
function _G.gen_statusline() function _G.gen_statusline()
if vim.g.statusline_winid == vim.fn.win_getid() then if vim.g.statusline_winid == vim.fn.win_getid() then
return statusline_focused() return statusline_focused()
else else
return statusline_not_focused() return statusline_not_focused()
end end
end end
vim.o.statusline = "%!luaeval(\"gen_statusline()\")" vim.o.statusline = "%!luaeval(\"gen_statusline()\")"