Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 29f90dc

Browse files
committedFeb 7, 2025
feat(nix): neovim
Signed-off-by: Leonard Sheng Sheng Lee <leonard.sheng.sheng.lee@gmail.com>
1 parent ce268be commit 29f90dc

16 files changed

+378
-19
lines changed
 

‎home-manager/packages/helix/terraform.nix

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1-
{ lib, pkgs, ... }:
21
{
3-
home.packages = with pkgs; [
4-
terraform # https://search.nixos.org/packages?channel=unstable&type=packages&show=terraform
5-
terraform-ls # https://search.nixos.org/packages?channel=unstable&type=packages&show=terraform-ls
2+
lib,
3+
pkgs,
4+
pkgs-unstable,
5+
...
6+
}:
7+
let
8+
buffer-language-server = pkgs.rustPlatform.buildRustPackage rec {
9+
pname = "buffer-language-server";
10+
version = "main";
11+
12+
src = pkgs.fetchFromGitHub {
13+
owner = "metafates";
14+
repo = "buffer-language-server";
15+
rev = "main";
16+
sha256 = "sha256-5q1dEkKRi8SYTvNyEND0S23xPeqV8b5C2Mm+0jLWIpA=";
17+
};
18+
19+
cargoHash = "sha256-dOJef0yKgzgbt80Ckl/AC/nkT97sBhv/VMxXArftj+k=";
20+
};
21+
in
22+
{
23+
home.packages = with pkgs-unstable; [
24+
# terraform # https://search.nixos.org/packages?channel=unstable&type=packages&show=terraform
25+
# terraform-ls # https://search.nixos.org/packages?channel=unstable&type=packages&show=terraform-ls
26+
buffer-language-server
627
];
728

829
# https://github.com/helix-editor/helix/blob/master/languages.toml
@@ -29,11 +50,11 @@
2950
}
3051
];
3152
language-server = {
32-
# buffer-language-server = {
33-
# command = "buffer-language-server";
34-
# };
53+
buffer-language-server = {
54+
command = "${buffer-language-server}/bin/buffer-language-server";
55+
};
3556
terraform-ls = {
36-
command = lib.getExe pkgs.terraform-ls; # "${pkgs.terraform-ls}/bin/terraform-ls";
57+
command = lib.getExe pkgs-unstable.terraform-ls; # "${pkgs.terraform-ls}/bin/terraform-ls";
3758
args = [ "serve" ];
3859
filetypes = [
3960
"hcl"

‎home-manager/packages/neovim/.vimrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
" colorscheme slate
2+
highlight LineNr ctermfg=White
3+
highlight Normal ctermbg=none
4+
highlight NonText ctermbg=none
5+
filetype on
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
pkgs,
3+
pkgs-unstable,
4+
...
5+
}:
6+
{
7+
home.packages = [
8+
pkgs.nodejs # Required for nvim-copilot
9+
pkgs.ripgrep # For nvim-telescope and nvim-spectre
10+
pkgs.fd # For nvim-telescope
11+
pkgs.tree-sitter # For nvim-treesitter
12+
pkgs.gcc-unwrapped # For nvim-lspconfig
13+
pkgs.typescript # For nvim-lspconfig
14+
pkgs.nixd # For nvim-lspconfig
15+
pkgs.nodePackages.typescript-language-server # For nvim-lspconfig
16+
pkgs.yaml-language-server # For nvim-lspconfig
17+
pkgs-unstable.terraform-ls # For nvim-lspconfig
18+
];
19+
programs.neovim = {
20+
enable = true; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.enable
21+
package = pkgs.neovim-unwrapped; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.package
22+
coc = {
23+
enable = false; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.coc.enable
24+
package = pkgs.vimPlugins.coc-nvim; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.coc.package
25+
pluginConfig = ""; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.coc.pluginConfig
26+
settings = {
27+
"suggest.noselect" = true;
28+
"suggest.enablePreview" = true;
29+
}; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.coc.settings
30+
};
31+
defaultEditor = false; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.defaulteditor
32+
extraConfig = builtins.readFile ./.vimrc; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.extraConfig
33+
extraLuaConfig = builtins.readFile ./init.lua; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.extraLuaConfig
34+
extraLuaPackages = luaPkgs: with luaPkgs; [ luautf8 ]; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.extraLuaPackages
35+
extraPackages = [ pkgs.shfmt ]; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.extraPackages
36+
extraPython3Packages =
37+
pyPkgs: with pyPkgs; [
38+
black
39+
python-lsp-server
40+
]; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.extraPython3Packages
41+
extraWrapperArgs = [ ]; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.extraWrapperArgs
42+
plugins =
43+
let
44+
cmp = [
45+
{
46+
plugin = pkgs.vimPlugins.nvim-cmp;
47+
type = "lua";
48+
config = builtins.readFile ./plugins/nvim-cmp.lua;
49+
}
50+
pkgs.vimPlugins.cmp-nvim-lsp
51+
pkgs.vimPlugins.cmp-buffer
52+
pkgs.vimPlugins.cmp-path
53+
pkgs.vimPlugins.cmp-cmdline
54+
pkgs.vimPlugins.nvim-cmp
55+
pkgs.vimPlugins.cmp-vsnip
56+
pkgs.vimPlugins.vim-vsnip
57+
];
58+
telescope = [
59+
{
60+
plugin = pkgs.vimPlugins.telescope-nvim;
61+
type = "lua";
62+
config = builtins.readFile ./plugins/telescope-nvim.lua;
63+
}
64+
pkgs.vimPlugins.nvim-treesitter
65+
];
66+
searchbox = [
67+
{
68+
plugin = pkgs.vimPlugins.searchbox-nvim;
69+
type = "lua";
70+
config = builtins.readFile ./plugins/searchbox-nvim.lua;
71+
}
72+
pkgs.vimPlugins.nui-nvim
73+
];
74+
in
75+
[ ]
76+
++ cmp
77+
++ searchbox
78+
++ telescope
79+
++ [
80+
{
81+
plugin = pkgs.vimPlugins.diffview-nvim;
82+
}
83+
{
84+
plugin = pkgs.vimPlugins.copilot-vim;
85+
type = "lua";
86+
config = builtins.readFile ./plugins/copilot-vim.lua;
87+
}
88+
{
89+
plugin = pkgs.vimPlugins.nvim-tree-lua;
90+
type = "lua";
91+
config = builtins.readFile ./plugins/nvim-tree-lua.lua;
92+
}
93+
{
94+
plugin = pkgs.vimPlugins.nvim-lspconfig;
95+
type = "lua";
96+
config = builtins.readFile ./plugins/nvim-lspconfig.lua;
97+
}
98+
{
99+
plugin = pkgs.vimPlugins.nvim-spectre;
100+
type = "lua";
101+
config = builtins.readFile ./plugins/nvim-spectre.lua;
102+
}
103+
{
104+
plugin = pkgs.vimPlugins.vim-visual-multi;
105+
}
106+
]; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.plugins
107+
108+
viAlias = true; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.viAlias
109+
vimAlias = true; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.vimAlias
110+
vimdiffAlias = true; # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.vimdiffAlias
111+
};
112+
}

‎home-manager/packages/neovim/init.lua

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
vim.g.mapleader = " "
2+
vim.g.maplocalleader = " "
3+
4+
-- Hide the status line completely
5+
vim.opt.laststatus = 0
6+
7+
-- Line numbers
8+
vim.opt.number = true
9+
vim.opt.relativenumber = true
10+
11+
-- Number width
12+
vim.opt.numberwidth = 1
13+
14+
-- Mouse
15+
vim.opt.mouse = ""
16+
17+
-- Auto-indentation
18+
vim.opt.autoindent = true
19+
20+
-- Tabs and indentation
21+
vim.opt.tabstop = 2
22+
vim.opt.shiftwidth = 2
23+
vim.opt.softtabstop = 2
24+
vim.opt.smarttab = true
25+
26+
-- Case sensitivity
27+
vim.opt.smartcase = true
28+
29+
-- Expand tab to spaces
30+
vim.opt.expandtab = true
31+
32+
-- Encoding
33+
vim.opt.encoding = "utf-8"
34+
35+
-- Clipboard
36+
vim.opt.clipboard:append("unnamedplus")
37+
38+
-- Disable textwidth and colorcolumn for Git commit messages
39+
vim.api.nvim_create_autocmd("FileType", {
40+
pattern = "gitcommit",
41+
callback = function()
42+
vim.opt_local.textwidth = 0
43+
vim.opt_local.colorcolumn = ""
44+
end,
45+
})
46+
47+
-- Make the background transparent
48+
vim.cmd([[
49+
highlight Normal guibg=none
50+
highlight NonText guibg=none
51+
highlight Normal ctermbg=none
52+
highlight NonText ctermbg=none
53+
]])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require("auto-session").setup({
2+
log_level = "info",
3+
auto_session_enable_last_session = false,
4+
auto_session_root_dir = vim.fn.stdpath("data") .. "/sessions/",
5+
auto_session_enabled = true,
6+
auto_save_enabled = true,
7+
auto_restore_enabled = true,
8+
auto_session_supress_dirs = nil,
9+
})
10+
11+
-- https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes#workaround-when-using-rmagattiauto-session
12+
vim.api.nvim_create_autocmd({ "BufEnter" }, {
13+
pattern = "NvimTree*",
14+
callback = function()
15+
local api = require("nvim-tree.api")
16+
local view = require("nvim-tree.view")
17+
18+
if not view.is_visible() then
19+
api.tree.open()
20+
end
21+
end,
22+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vim.g.copilot_filetypes = { gitcommit = true }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- Set up nvim-cmp.
2+
local cmp = require("cmp")
3+
4+
cmp.setup({
5+
snippet = {
6+
-- REQUIRED - you must specify a snippet engine
7+
expand = function(args)
8+
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
9+
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
10+
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
11+
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
12+
end,
13+
},
14+
window = {
15+
-- completion = cmp.config.window.bordered(),
16+
-- documentation = cmp.config.window.bordered(),
17+
},
18+
mapping = cmp.mapping.preset.insert({
19+
["<C-b>"] = cmp.mapping.scroll_docs(-4),
20+
["<C-f>"] = cmp.mapping.scroll_docs(4),
21+
["<C-Space>"] = cmp.mapping.complete(),
22+
["<C-e>"] = cmp.mapping.abort(),
23+
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
24+
}),
25+
sources = cmp.config.sources({
26+
{ name = "nvim_lsp" },
27+
{ name = "vsnip" }, -- For vsnip users.
28+
-- { name = 'luasnip' }, -- For luasnip users.
29+
-- { name = 'ultisnips' }, -- For ultisnips users.
30+
-- { name = 'snippy' }, -- For snippy users.
31+
}, {
32+
{ name = "buffer" },
33+
}),
34+
})
35+
36+
-- Set configuration for specific filetype.
37+
cmp.setup.filetype("gitcommit", {
38+
sources = cmp.config.sources({
39+
{ name = "git" }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
40+
}, {
41+
{ name = "buffer" },
42+
}),
43+
})
44+
45+
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
46+
cmp.setup.cmdline({ "/", "?" }, {
47+
mapping = cmp.mapping.preset.cmdline(),
48+
sources = {
49+
{ name = "buffer" },
50+
},
51+
})
52+
53+
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
54+
cmp.setup.cmdline(":", {
55+
mapping = cmp.mapping.preset.cmdline(),
56+
sources = cmp.config.sources({
57+
{ name = "path" },
58+
}, {
59+
{ name = "cmdline" },
60+
}),
61+
})
62+
63+
-- Set up lspconfig.
64+
local capabilities = require("cmp_nvim_lsp").default_capabilities()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require("lspconfig").dartls.setup({})
2+
require("lspconfig").terraformls.setup({})
3+
require("lspconfig").ts_ls.setup({})
4+
require("lspconfig").yamlls.setup({})
5+
require("lspconfig").nixd.setup({})
6+
7+
require("lspconfig").lua_ls.setup({
8+
settings = {
9+
Lua = {
10+
diagnostics = {
11+
globals = { "vim" },
12+
},
13+
},
14+
},
15+
}) -- https://neovim.discourse.group/t/how-to-suppress-warning-undefined-global-vim/1882/16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
vim.keymap.set("n", "<leader>S", '<cmd>lua require("spectre").toggle()<CR>', {
2+
desc = "Toggle Spectre",
3+
})
4+
vim.keymap.set("n", "<leader>sw", '<cmd>lua require("spectre").open_visual({select_word=true})<CR>', {
5+
desc = "Search current word",
6+
})
7+
vim.keymap.set("v", "<leader>sw", '<esc><cmd>lua require("spectre").open_visual()<CR>', {
8+
desc = "Search current word",
9+
})
10+
vim.keymap.set("n", "<leader>sp", '<cmd>lua require("spectre").open_file_search({select_word=true})<CR>', {
11+
desc = "Search on current file",
12+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require("nvim-tree").setup({})
2+
3+
-- Key mapping for toggling NvimTree
4+
vim.api.nvim_set_keymap("n", "<C-s>", ":NvimTreeToggle<CR>", { noremap = true, silent = true })
5+
6+
-- Autocommand to close Neovim if the NvimTree is the only buffer left
7+
vim.api.nvim_create_autocmd("BufEnter", {
8+
pattern = "*",
9+
callback = function()
10+
if vim.fn.winnr("$") == 1 and vim.b.term_type == "tree" then
11+
vim.cmd("quit")
12+
end
13+
end,
14+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vim.keymap.set("n", "<leader>s", ":SearchBoxIncSearch<CR>")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require("telescope").setup({
2+
pickers = {
3+
find_files = {
4+
find_command = { "rg", "--files", "--hidden", "-g", "!.git/*" },
5+
},
6+
},
7+
})
8+
9+
local builtin = require("telescope.builtin")
10+
vim.keymap.set("n", "<leader>sh", builtin.help_tags, { desc = "[S]earch [H]elp" })
11+
vim.keymap.set("n", "<leader>sk", builtin.keymaps, { desc = "[S]earch [K]eymaps" })
12+
vim.keymap.set("n", "<leader>sf", builtin.find_files, { desc = "[S]earch [F]iles" })
13+
vim.keymap.set("n", "<leader>ss", builtin.builtin, { desc = "[S]earch [S]elect Telescope" })
14+
vim.keymap.set("n", "<leader>sw", builtin.grep_string, { desc = "[S]earch current [W]ord" })
15+
vim.keymap.set("n", "<leader>sg", builtin.live_grep, { desc = "[S]earch by [G]rep" })
16+
vim.keymap.set("n", "<leader>sd", builtin.diagnostics, { desc = "[S]earch [D]iagnostics" })
17+
vim.keymap.set("n", "<leader>sr", builtin.resume, { desc = "[S]earch [R]esume" })
18+
vim.keymap.set("n", "<leader>s.", builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
19+
vim.keymap.set("n", "<leader><leader>", builtin.buffers, { desc = "[ ] Find existing buffers" })
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)