Skip to content

Commit

Permalink
feat: add nixvim initial configs
Browse files Browse the repository at this point in the history
  • Loading branch information
glwbr committed Jun 15, 2024
1 parent efa0b75 commit 0a95856
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 9 deletions.
12 changes: 12 additions & 0 deletions home/editors/neovim/autocmds.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_: {
programs.nixvim.autoCmd = [
# Enable spellcheck for some filetypes
{
event = "FileType";
pattern = [
"markdown"
];
command = "setlocal spell spelllang=en,pt-br";
}
];
}
3 changes: 3 additions & 0 deletions home/editors/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
imports = [
inputs.nixvim.homeManagerModules.nixvim
./plugins

./autocmds.nix
./options.nix
./remap.nix
];
home.shellAliases.v = "nvim";
programs.nixvim = {
Expand Down
2 changes: 1 addition & 1 deletion home/editors/neovim/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
};

clipboard = {
# register = "";
providers.wl-copy.enable = true;
};

Expand Down Expand Up @@ -72,6 +71,7 @@

# Status line
laststatus = 3;
showmode = false;

# Text width
textwidth = 0;
Expand Down
16 changes: 16 additions & 0 deletions home/editors/neovim/plugins/colorscheme.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
_: {
programs.nixvim = {
colorschemes = {
rose-pine = {
enable = true;
settings = {
styles = {
italic = true;
bold = true;
transparency = false;
};
};
};
};
};
}
8 changes: 4 additions & 4 deletions home/editors/neovim/plugins/completion.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ _: {
path = "[path]";
luasnip = "[snip]";
buffer = "[buffer]";
neorg = "[neorg]";
cmp_tabby = "[Tabby]";
# neorg = "[neorg]";
# cmp_tabby = "[Tabby]";
};
};
};
Expand All @@ -41,14 +41,14 @@ _: {
sources = [
{name = "path";}
{name = "nvim_lsp";}
{name = "cmp_tabby";}
# {name = "cmp_tabby";}
{name = "luasnip";}
{
name = "buffer";
# Words from other open buffers can also be suggested.
option.get_bufnrs.__raw = "vim.api.nvim_list_bufs";
}
{name = "neorg";}
# {name = "neorg";}
];
};
};
Expand Down
9 changes: 9 additions & 0 deletions home/editors/neovim/plugins/copilot.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_: {
programs.nixvim = {
plugins = {
copilot-lua = {
enable = false;
};
};
};
}
11 changes: 7 additions & 4 deletions home/editors/neovim/plugins/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
_: {
imports = [
./colorscheme.nix
./completion.nix
./copilot.nix
./harpoon.nix
./lsp.nix
./lualine.nix
./telescope.nix
./treesitter.nix
];

programs.nixvim = {
colorschemes.rose-pine.enable = true;
};
}
20 changes: 20 additions & 0 deletions home/editors/neovim/plugins/harpoon.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
_: {
programs.nixvim = {
plugins.harpoon = {
enable = true;

keymapsSilent = true;

keymaps = {
addFile = "<leader>a";
toggleQuickMenu = "<C-e>";
navFile = {
"1" = "<C-h>";
"2" = "<C-t>";
"3" = "<C-n>";
"4" = "<C-s>";
};
};
};
};
}
34 changes: 34 additions & 0 deletions home/editors/neovim/plugins/lsp.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
_: {
programs.nixvim = {
plugins = {
lsp = {
enable = true;

keymaps = {
silent = true;
diagnostic = {
# Navigate in diagnostics
"<C-p>" = "goto_prev";
"<C-n>" = "goto_next";
"<C-y>" = "confirm";
"<C-space>" = "complete";
};

lspBuf = {
gd = "definition";
gD = "references";
gt = "type_definition";
gi = "implementation";
K = "hover";
"<F2>" = "rename";
};
};

servers = {
clangd.enable = true;
lua-ls.enable = true;
};
};
};
};
}
46 changes: 46 additions & 0 deletions home/editors/neovim/plugins/lualine.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
programs.nixvim.plugins.lualine = {
enable = true;

globalstatus = true;

# +-------------------------------------------------+
# | A | B | C X | Y | Z |
# +-------------------------------------------------+
sections = {
lualine_a = ["mode"];
lualine_b = ["branch"];
lualine_c = ["filename" "diff"];

lualine_x = [
"diagnostics"

# Show active language server
{
name.__raw = ''
function()
local msg = ""
local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
local clients = vim.lsp.get_active_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end
'';
icon = "";
color.fg = "#ffffff";
}
"encoding"
"fileformat"
"filetype"
];
};
};
}
28 changes: 28 additions & 0 deletions home/editors/neovim/plugins/telescope.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
_: {
programs.nixvim = {
plugins.telescope = {
enable = true;

keymaps = {
# Find files using Telescope command-line sugar.
"<leader>sf" = "find_files";
"<leader>sh" = "help_tags";
"<leader>sg" = "git_files";
"<leader>sd" = "diagnostics";
"<leader><leader>" = "buffers";

# FZF like bindings
#"<C-p>" = "git_files";
"<leader>s." = "oldfiles";
"<leader>s/" = "live_grep";
};

settings.defaults = {
file_ignore_patterns = [
"^.git/"
];
set_env.COLORTERM = "truecolor";
};
};
};
}
23 changes: 23 additions & 0 deletions home/editors/neovim/plugins/treesitter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
_: {
programs.nixvim.plugins = {
treesitter = {
enable = true;

nixvimInjections = true;

folding = true;
indent = true;
};

treesitter-refactor = {
enable = true;
highlightDefinitions = {
enable = true;
# Set to false if you have an `updatetime` of ~100.
clearOnCursorMove = false;
};
};

hmts.enable = true;
};
}
80 changes: 80 additions & 0 deletions home/editors/neovim/remap.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
config,
lib,
...
}: {
programs.nixvim = {
globals = {
mapleader = " ";
maplocalleader = " ";
};

keymaps = let
# Normal mode key mappings
normal =
lib.mapAttrsToList (key: action: {
mode = "n";
inherit action key;
})
{
# Movement modifications with Alt key
"<M-k>" = ":move-2<CR>";
"<M-j>" = ":move+<CR>";

# Project view
"<leader>pv" = "<cmd>Ex<CR>";

# Search and replace the word under cursor
"<leader>s" = ":%s/\\<<C-r><C-w>\\>/<C-r><C-w>/gI<Left><Left><Left>";

# Movement reminders
"<left>" = ''<cmd>echo "Use h to move!!"<CR>'';
"<right>" = ''<cmd>echo "Use l to move!!"<CR>'';
"<up>" = ''<cmd>echo "Use k to move!!"<CR>"'';
"<down>" = ''<cmd>echo "Use j to move!!"<CR>"'';

# Center the view on next and previous searches
"<n>" = "nzzzv";
"<N>" = "Nzzzv";

# Clipboard operations
"<leader>y" = "\"+y";
"<leader>Y" = "\"+Y";

# Delete without yanking
"<leader>d" = "\"_d";

# Make the current file executable
"<leader>x" = "<cmd>!chmod +x %<CR>";

# Disable the Q shortcut
"Q" = "<nop>";
};

# Visual mode key mappings
visual =
lib.mapAttrsToList (key: action: {
mode = "v";
inherit action key;
})
{
# Indenting operations
">" = ">gv";
"<" = "<gv";
"<TAB>" = ">gv";
"<S-TAB>" = "<gv";

# Clipboard operations in visual mode
"<leader>y" = "\"+y";
"<leader>p" = "\"_dP";

# Move selected lines up and down
"K" = ":m '<-2<CR>gv=gv";
"J" = ":m '>+1<CR>gv=gv";
};
in
config.nixvim.helpers.keymaps.mkKeymaps
{options.silent = true;}
(normal ++ visual);
};
}

0 comments on commit 0a95856

Please sign in to comment.