Skip to content

Commit f08dfcd

Browse files
committed
Neovim config tidying and commenting.
1 parent ab395cc commit f08dfcd

15 files changed

Lines changed: 129 additions & 64 deletions

config/nvim/init.lua

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,27 @@
1+
-- Highlights of this config are:
2+
--
3+
-- * Plugin management with lazy.nvim
4+
-- * Automatic installation of language servers and formatters with mason.nvim
5+
-- * Language server support with nvim-lspconfig
6+
-- * Auto-formatting with null-ls
7+
-- * Completion with nvim-cmp
8+
-- * Syntax highlighting with nvim-treesitter
9+
--
10+
-- See the lua/plugin-specs directory for more.
11+
112
-- Don't load all our plugins and stuff in VSCode.
213
if vim.g.vscode then
314
return
415
end
516

617
local colorscheme = "nordfox"
718

8-
-- These need to happen before plugins have loaded:
19+
-- We need to set all our options
920
require("options").configure()
1021

11-
-- Install lazy.nvim from git if it's not already installed.
12-
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
13-
if not vim.uv.fs_stat(lazypath) then
14-
vim.notify("Installing lazy.nvim...")
15-
vim.fn.system({
16-
"git",
17-
"clone",
18-
"--filter=blob:none",
19-
"https://github.com/folke/lazy.nvim.git",
20-
"--branch=stable", -- latest stable release
21-
lazypath,
22-
})
23-
end
24-
25-
vim.opt.rtp:prepend(lazypath)
26-
27-
-- Then we install and load the plugins.
28-
require("lazy").setup({
29-
spec = {
30-
-- Load everything from the lua/plugins directory.
31-
import = "plugins",
32-
},
33-
change_detection = {
34-
-- Don't notify whenever a config file changes. It's not helpful.
35-
enabled = true,
36-
notify = false,
37-
},
38-
install = {
39-
-- Lazy tries to use this colorscheme during installation.
40-
colorscheme = { colorscheme },
41-
},
42-
})
22+
local plugins = require("plugins")
23+
plugins.install_lazy()
24+
plugins.install_and_load_plugins(colorscheme)
4325

4426
-- And these need to happen after the plugins have loaded:
4527
vim.cmd.colorscheme(colorscheme)

config/nvim/lua/actions.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
-- This file wraps up a bunch of useful things that we want to use for key
2+
-- mappings into convenient functions.
3+
14
local gitsigns = require("gitsigns")
25
local neo_tree = require("neo-tree.command")
36
local telescope = require("telescope.builtin")
47

58
return {
9+
-- Open the current project on GitHub in a browsers.
610
browse_on_github = function()
711
vim.cmd("silent !gh browse")
812
end,
913

14+
-- Set the commit against which git differences are shown in both the
15+
-- gutter (using Gitsigns) and the explorer (Neo-tree).
1016
choose_git_base = function()
1117
local callback = function(git_base)
1218
if git_base ~= nil then
@@ -25,10 +31,13 @@ return {
2531
telescope.grep_string({ search = vim.fn.expand("<cword>") })
2632
end,
2733

34+
-- Restore open windows and buffers that were previously saved with
35+
-- save_session_and_quit.
2836
restore_session = function()
2937
vim.cmd.source("Session.vim")
3038
end,
3139

40+
-- Save open windows and buffers to a Session.vim file and quit.
3241
save_session_and_quit = function()
3342
-- Neo-tree buffers don't restore correctly, so close it first.
3443
neo_tree.execute({ action = "close" })
@@ -37,19 +46,24 @@ return {
3746
vim.cmd.quit()
3847
end,
3948

49+
-- Switch to the Files tab in Neo-tree, and focus on the file currently
50+
-- being edited, expanding any necessary directories.
4051
show_current_file_in_neo_tree = function()
4152
neo_tree.execute({ action = "focus", source = "filesystem", reveal = true })
4253
end,
4354

55+
-- Open Neo-tree if it's closed, or close it if it's open.
4456
toggle_neo_tree = function()
4557
neo_tree.execute({ action = "focus", toggle = true })
4658
end,
4759

60+
-- Save every open buffer.
4861
write_all = function()
4962
vim.cmd.wall()
5063
vim.notify("Saved all files.")
5164
end,
5265

66+
-- Save every open buffer and quit Neovim.
5367
write_all_and_quit = function()
5468
vim.cmd("confirm xall")
5569
end,

config/nvim/lua/key-mappings.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
local bufdelete = require("bufdelete")
2-
local gitsigns = require("gitsigns")
3-
local refactoring = require("refactoring")
4-
local repeatable_move = require("nvim-treesitter.textobjects.repeatable_move")
5-
local telescope = require("telescope.builtin")
6-
local treesj = require("treesj")
7-
local which_key = require("which-key")
8-
local actions = require("actions")
9-
101
local map = vim.keymap.set
112

123
-- Set up mappings available in all buffers.
134
local function map_global_keys()
5+
local actions = require("actions")
6+
local bufdelete = require("bufdelete")
7+
local gitsigns = require("gitsigns")
8+
local refactoring = require("refactoring")
9+
local repeatable_move = require("nvim-treesitter.textobjects.repeatable_move")
10+
local telescope = require("telescope.builtin")
11+
local treesj = require("treesj")
12+
local which_key = require("which-key")
13+
1414
-- Things I do often enough get a top-level mapping.
1515
map("", "<leader><leader>", telescope.find_files, { desc = "find files" })
1616
map("", "<leader>*", telescope.grep_string, { desc = "find word under cursor" })
@@ -25,7 +25,8 @@ local function map_global_keys()
2525
map("", "<leader>W", vim.cmd.close, { desc = "close window" })
2626
map("", "<leader>X", bufdelete.bufdelete, { desc = "close buffer" })
2727

28-
-- Make command keys do sensible things.
28+
-- Make command keys do sensible things. There some stuff in kitty.conf to
29+
-- tell Kitty to pass these through to Neovim.
2930
map("v", "<D-c>", '"*y', { desc = "copy to system clipboard" })
3031
map("", "<D-q>", actions.write_all_and_quit, { desc = "save all files and quit" })
3132
map("", "<D-s>", actions.write_all, { desc = "save all files" })
@@ -84,6 +85,8 @@ end
8485
local function map_lsp_keys(args)
8586
local buffer = args.buf
8687

88+
local telescope = require("telescope.builtin")
89+
8790
map({ "n", "x", "o" }, "gd", telescope.lsp_definitions, { buffer = buffer, desc = "Go to defintion" })
8891
map({ "n", "x", "o" }, "gr", telescope.lsp_references, { buffer = buffer, desc = "Go to references" })
8992

File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
return {
22
-- Close buffers without closing the window that contains them.
3+
--
34
-- https://github.com/famiu/bufdelete.nvim
45
"famiu/bufdelete.nvim",
56

67
-- Handle opening file:line.
8+
--
79
-- https://github.com/bogado/file-line
810
"bogado/file-line",
911

12+
-- Show git differences in the gutter to the left of the file being edited,
13+
-- and perform other basic git operations.
14+
--
1015
-- https://github.com/lewis6991/gitsigns.nvim
1116
{ "lewis6991/gitsigns.nvim", config = true },
1217

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
-- I use a set of plugins to provide language server support, which gives me
2+
-- all sorts of good things:
3+
--
4+
-- * Great auto-completion
5+
-- * Hover documentation (hit K to bring it up)
6+
-- * Real-time errors and warnings
7+
-- * Quick navigation to defitions and references
8+
-- * Auto-formatting
9+
--
10+
-- The two key plugins are:
11+
--
12+
-- * nvim-lspconfig configures and runs language servers
13+
-- * null-ls configures and runs formatters
14+
--
15+
-- Underlying this, I use mason to install all language servers and formatters.
16+
--
17+
-- A pair of plugins ties all this this together.
18+
--
19+
-- * mason-lspconfig ties nvim-lspconfig to mason
20+
-- * mason-null-ls ties null-ls to mason
21+
122
-- mason installs language servers and formatters for us.
223
--
324
-- It puts them in ~/.local/share/NVIM_APPNAME/mason, where NVIM_APPNAME
@@ -30,7 +51,7 @@ local lspconfig_spec = {
3051
-- https://github.com/neovim/nvim-lspconfig
3152
"neovim/nvim-lspconfig",
3253
dependencies = { "hrsh7th/cmp-nvim-lsp", mason_lspconfig_spec },
33-
config = require("plugins/lsp/lspconfig-config"),
54+
config = require("plugin-specs.lsp.lspconfig-config"),
3455
}
3556

3657
-- null-ls lets us auto-format files on save.
@@ -42,7 +63,7 @@ local null_ls_spec = {
4263
-- https://github.com/nvimtools/none-ls.nvim
4364
"nvimtools/none-ls.nvim",
4465
dependencies = { "nvim-lua/plenary.nvim" },
45-
config = require("plugins/lsp/null-ls-config"),
66+
config = require("plugin-specs.lsp.null-ls-config"),
4667
}
4768

4869
-- mason-null-ls uses mason to install formatters configured in null-ls.

config/nvim/lua/plugins/lsp/lspconfig-config.lua renamed to config/nvim/lua/plugin-specs/lsp/lspconfig-config.lua

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ return function()
22
local lspconfig = require("lspconfig")
33
local capabilities = require("cmp_nvim_lsp").default_capabilities()
44

5+
local opts = { capabilities = capabilities }
56
local dotfiles_env = os.getenv("DOTFILES_ENV")
67

78
if dotfiles_env == "home" then
8-
lspconfig.bashls.setup({ capabilities = capabilities })
9-
lspconfig.eslint.setup({ capabilities = capabilities })
10-
lspconfig.solargraph.setup({ capabilities = capabilities })
11-
lspconfig.standardrb.setup({ capabilities = capabilities })
12-
lspconfig.tsserver.setup({ capabilities = capabilities })
9+
lspconfig.bashls.setup(opts)
10+
lspconfig.eslint.setup(opts)
11+
lspconfig.solargraph.setup(opts)
12+
lspconfig.standardrb.setup(opts)
13+
lspconfig.tsserver.setup(opts)
1314
end
1415

1516
if dotfiles_env == "work" then
16-
lspconfig.bashls.setup({ capabilities = capabilities })
17-
lspconfig.eslint.setup({ capabilities = capabilities })
18-
lspconfig.relay_lsp.setup({ capabilities = capabilities })
19-
lspconfig.rubocop.setup({ capabilities = capabilities })
20-
lspconfig.sorbet.setup({ capabilities = capabilities })
21-
lspconfig.tsserver.setup({ capabilities = capabilities })
17+
lspconfig.bashls.setup(opts)
18+
lspconfig.eslint.setup(opts)
19+
lspconfig.relay_lsp.setup(opts)
20+
lspconfig.rubocop.setup(opts)
21+
lspconfig.sorbet.setup(opts)
22+
lspconfig.tsserver.setup(opts)
2223
end
2324

2425
-- Set the diagnostic signs shown in the gutter to match lualine's.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)