Skip to content

Commit

Permalink
feat(neovim): improve dotfiles
Browse files Browse the repository at this point in the history
In addition to a lot of smaller tweaks, here are a few more significant
changes.

1. Prevent LSPs from setting formatexpr.
2. Remove .luarc.json.
3. Simplify my LSP settings for Lua. See this issue for discussion.
   neovim/nvim-lspconfig#3133
4. Use vim.o instead of vim.opt.
5. Add completion via hrsh7th/nvim-cmp.
6. Add ysmb-wtsg/in-and-out.nvim for a simple way to jump out of paired
   character groups.
7. Switch to my own fork of mini.surround in order to get highlighting
   of surround actions.
  • Loading branch information
telemachus committed Jun 28, 2024
1 parent fe92561 commit 48bf06c
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 149 deletions.
5 changes: 0 additions & 5 deletions .luarc.json

This file was deleted.

217 changes: 112 additions & 105 deletions config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ vim.loader.enable()
local HOME = os.getenv("HOME")
local cmd = vim.cmd
local g = vim.g
local opt = vim.opt
local o = vim.o
local join = table.concat
local fmt = string.format
local notify = vim.notify

g.mapleader = " "
g.localmapleader = " "
Expand Down Expand Up @@ -37,61 +40,61 @@ require("paq")(packages)
-- https://github.com/dstein64/vim-startuptime
g.startuptime_tries = 10

opt.scrolloff = 0
opt.number = true
opt.relativenumber = true
opt.statuscolumn = "%=%{v:relnum?v:relnum:v:lnum} "
opt.completeopt = "menuone,noinsert,preview"
opt.signcolumn = "yes"
opt.mouse = ""

opt.showcmd = true
opt.showmode = true

opt.shell = "bash"

opt.wrap = true
opt.linebreak = true
opt.breakindent = true
opt.showbreak = ""
opt.list = true
opt.listchars = {
eol = "",
tab = "»·",
trail = "",
precedes = "",
extends = "",
nbsp = "",
}
o.scrolloff = 0
o.number = true
o.relativenumber = true
o.statuscolumn = "%=%{v:relnum?v:relnum:v:lnum} "
o.completeopt = "menuone,noinsert,preview"
o.signcolumn = "yes"
o.mouse = ""

o.showcmd = true
o.showmode = true

o.shell = "bash"

o.wrap = true
o.linebreak = true
o.breakindent = true
o.showbreak = ""
o.list = true
o.listchars = join({
"eol:",
"tab:»·",
"trail:",
"precedes:",
"extends:",
"nbsp:",
}, ",")

-- t = Autowrap text using textwidth.
-- c = Autowrap comments using textwidth.
-- q = Allow formatting of comments with 'gq'.
-- n = Recognize numbered lists for formatting purposes.
-- 1 = Do not break line after a one-letter word.
opt.formatoptions = "tcqn1"
opt.tabstop = 8
opt.softtabstop = 0
opt.shiftwidth = 8
opt.expandtab = false
opt.foldenable = false

opt.ignorecase = true
opt.smartcase = true
opt.gdefault = true
opt.incsearch = true
opt.hlsearch = false
opt.conceallevel = 0
opt.concealcursor = ""

opt.backup = true
opt.backupcopy = "yes"
opt.backupdir = HOME .. "/.local/share/nvim/backups"
opt.undofile = true
opt.undodir = HOME .. "/.local/share/nvim/undo"

opt.wildmode = { "longest", "list" }
opt.wildignore = {
o.formatoptions = "tcqn1"
o.tabstop = 8
o.softtabstop = 0
o.shiftwidth = 8
o.expandtab = false
o.foldenable = false

o.ignorecase = true
o.smartcase = true
o.gdefault = true
o.incsearch = true
o.hlsearch = false
o.conceallevel = 0
o.concealcursor = ""

o.backup = true
o.backupcopy = "yes"
o.backupdir = HOME .. "/.local/share/nvim/backups"
o.undofile = true
o.undodir = HOME .. "/.local/share/nvim/undo"

o.wildmode = join({ "longest", "list" }, ",")
o.wildignore = join({
"__pycache__",
"*~",
"*DS_Store*",
Expand All @@ -118,18 +121,15 @@ opt.wildignore = {
"*/.ist",
"*/.fdb_latexmk",
"*/build/*",
}
}, ",")

-- opt.hidden = true
opt.title = true
opt.shortmess = "atIF"
opt.statusline =
o.hidden = true
o.title = true
o.shortmess = "atIF"
o.statusline =
"[%<%.20f][%{&fenc==''?&enc:&fenc}]%y%m%r%h%=%([Line: %l Column: %c %P]%)"

opt.spelllang = "en"

-- opt.termguicolors = true
-- opt.background = "light"
o.spelllang = "en"

---Safely require a module.
---@param m string
Expand All @@ -138,23 +138,25 @@ opt.spelllang = "en"
local safe_require = function(m)
local ok, loaded_m = pcall(require, m)
if not ok then
vim.notify(string.format("init.lua: error loading %s", m))
notify(fmt([[init.lua: error loading "%s"]], m))
end
return ok, loaded_m
end

---Safely call setup on a plugin.
---@param plugin string
---@param t table
---@param t table|nil
---@return boolean
local safe_setup = function(plugin, t)
t = t or {}
local ok, loaded_p = safe_require(plugin)
if ok then
loaded_p.setup(t)
end
return ok
end

-- TODO: remove this dependency and create a simpler theme for myself.
local theme_loaded = safe_setup("github-theme", {
theme_style = "light",
sidebars = { "qf", "lf" },
Expand All @@ -179,11 +181,11 @@ else
cmd("colorscheme off")
end

opt.colorcolumn = "89"
o.colorcolumn = "89"

opt.iskeyword = opt.iskeyword + "-"
o.iskeyword = o.iskeyword .. ",-"

opt.grepprg = "rg --vimgrep --smart-case --"
o.grepprg = "rg --vimgrep --smart-case --"

-- https://github.com/dcampos/nvim-snippy.git
safe_setup("snippy", {
Expand All @@ -204,12 +206,6 @@ safe_setup("snippy", {
["<Tab>"] = "cut_text",
},
},
-- virtual_markers = {
-- enabled = true,
-- default = "⚡",
-- empty = "⚡",
-- hl_group = "SnippyPlaceholder",
-- },
})

-- https://github.com/nvim-treesitter/nvim-treesitter.git
Expand Down Expand Up @@ -306,44 +302,26 @@ local lsp_loaded, lspconfig = safe_require("lspconfig")
if lsp_loaded then
lspconfig.gopls.setup({ settings = { gofumpt = true } })
lspconfig.lua_ls.setup({
on_init = function(client)
local path = vim.fn.getcwd(vim.api.nvim_get_current_win())
if
not vim.uv.fs_stat(path .. "/.luarc.json")
and not vim.uv.fs_stat(path .. "/.luarc.jsonc")
then
client.config.settings =
vim.tbl_deep_extend("force", client.config.settings, {
Lua = {
runtime = {
version = "LuaJIT",
},
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
vim.fn.expand(
"~/local/lua/lib/luarocks/rocks-5.1"
),
},
-- This pulls in all of 'runtimepath', and it
-- is much slower. Use with caution.
-- library = vim.api.nvim_get_runtime_file("", true)
},
},
})

client.notify(
"workspace/didChangeConfiguration",
{ settings = client.config.settings }
)
end
return true
end,
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
},
},
format = {
enable = false,
},
},
},
})
end

-- https://github.com/m4xshen/autoclose.nvim.git
-- https://github.com/telemachus/autoclose.nvim.git
safe_setup("autoclose", {
options = {
disable_command_mode = true,
Expand Down Expand Up @@ -382,6 +360,35 @@ safe_setup("refinery", {
-- },
})

-- https://github.com/ysmb-wtsg/in-and-out.nvim
safe_setup("in-and-out", {
additional_targets = { "|", "", "" },
})

-- https://github.com/hrsh7th/nvim-cmp
local cmp_loaded, cmp = safe_require("cmp")
if cmp_loaded then
cmp.setup.filetype({ "markdown", "mail", "text" }, {
mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<C-y>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
["C-n"] = cmp.mapping.select_next_item({
behavior = cmp.SelectBehavior.Insert,
}),
["C-p"] = cmp.mapping.select_prev_item({
behavior = cmp.SelectBehavior.Insert,
}),
}),
completion = { keyword_length = 4 },
sources = cmp.config.sources({ { name = "buffer" } }),
window = { documentation = cmp.config.disable },
})
end

safe_require("filetypes")
safe_require("lsp")
safe_require("autocommands")
Expand Down
Loading

0 comments on commit 48bf06c

Please sign in to comment.