Skip to content

Commit

Permalink
More random things (#31)
Browse files Browse the repository at this point in the history
* Sort

* yamllint: don't complain about missing start or 80+ lines

* Enable experimental lua loader

* Format

* cmp: majorly improve completion

* cmp: sort

* lualine: show relative path

* cmp: map up/down/pgup/pgdown

* cmp: only show 15 lines of suggestion

* lualine: use our lsp

* lsp: enable lua

* treesitter: disable buggy indent

* Move lists out of mkDefault

* Configure undofile

* Enable smartindent
  • Loading branch information
SuperSandro2000 authored Jul 8, 2024
1 parent a9897a9 commit c2b7955
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 91 deletions.
162 changes: 115 additions & 47 deletions modules/cmp.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,125 @@
{
extraConfigLuaPre = /* lua */ ''
local luasnip = require('luasnip')
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
'';

extraConfigLua = /* lua */ ''
vim.api.nvim_create_autocmd({ 'TextChangedI' }, {
callback = function()
if has_words_before() then
cmp.complete()
end
end,
})
'';

plugins = {
cmp = {
enable = true;
autoEnableSources = true;

settings = {
snippet.expand = ''
completion.autocomplete = false;

# https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings
mapping = {
"<CR>" = /* lua */ ''
cmp.mapping({
i = function(fallback)
if cmp.visible() and cmp.get_active_entry() then
if luasnip.expandable() then
luasnip.expand()
else
cmp.confirm({ select = true })
end
else
fallback()
end
end,
s = cmp.mapping.confirm({ select = true }),
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
})
'';
"<C-Space>" = "cmp.mapping.complete()";

"<Tab>" = /* lua */ ''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.locally_jumpable(1) then
luasnip.jump(1)
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" })
'';
"<S-Tab>" = /* lua */ ''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" })
'';

"<Up>" = /* lua */ ''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" })
'';
"<Down>" = /* lua */ ''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.locally_jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" })
'';
"<PageUp>" = /* lua */ ''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ count = 5 })
elseif luasnip.locally_jumpable(-5) then
luasnip.jump(-5)
else
fallback()
end
end, { "i", "s" })
'';
"<PageDown>" = /* lua */ ''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item({ count = 5 })
elseif luasnip.locally_jumpable(5) then
luasnip.jump(5)
else
fallback()
end
end, { "i", "s" })
'';
};

snippet.expand = /* lua */ ''
function(args)
require('luasnip').lsp_expand(args.body)
end
Expand All @@ -22,52 +136,6 @@
#"calc"
"cmdline"
];

mapping = {
"<CR>" = ''
cmp.mapping(function(fallback)
local luasnip = require'luasnip'
if cmp.visible() then
if luasnip.expandable() then
luasnip.expand()
else
cmp.confirm({
select = true,
})
end
else
fallback()
end
end)
'';
"<C-Space>" = "cmp.mapping.complete()";

# TODO: page up/down buttons to scroll multiple times
"<Tab>" = ''
cmp.mapping(function(fallback)
local luasnip = require'luasnip'
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.locally_jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" })
'';
"<S-Tab>" = ''
cmp.mapping(function(fallback)
local luasnip = require'luasnip'
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" })
'';
};
};
};

Expand Down
100 changes: 57 additions & 43 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,66 @@
./which_key.nix
./telescope.nix
];
} // lib.mapAttrsRecursive (_: lib.mkDefault) {
viAlias = true;
vimAlias = true;

extraPlugins = with pkgs.vimPlugins; [
vim-fetch # accept ./path/to/file:123 as line numbers
];

keymaps = [
# Use tab as buffer switcher in normal mode
{
mode = "n";
key = "<Tab>";
action = ":bnext<CR>";
}
{
mode = "n";
key = "<S-Tab>";
action = ":bprevious<CR>";
}

# Delete search highlight with backspace
{
mode = "n";
key = "<BS>";
action = ":nohlsearch<CR>";
}
# move line up(n)
{ mode = "n"; key = "<A-j>"; action = ":m .+1<CR>=="; }
# move line down(n)
{ mode = "n"; key = "<A-k>"; action = ":m .-2<CR>=="; }
# move line up(v)
{ mode = "v"; key = "<A-j>"; action = ":m '>+1<CR>gv=gv"; }
# move line down(v)
{ mode = "v"; key = "<A-k>"; action = ":m '<-2<CR>gv=gv"; }
{ mode = "n"; key = "<leader>gb"; action = ":Gitsign blame_line<CR>"; }
];
} // lib.mapAttrsRecursive (_: lib.mkDefault) {
colorschemes.kanagawa.enable = true;
editorconfig.enable = true;
globals.mapleader = " ";
luaLoader.enable = true;

opts = {
expandtab = true;
number = true;
pumheight = 15;
relativenumber = true;
signcolumn = "yes";
scrolloff = 8;
tabstop = 2;
shiftwidth = 2;
expandtab = true;
signcolumn = "yes";
smartindent = true;
tabstop = 2;
# save undo file after quit
undofile = true;
undolevels = 1000;
undoreload = 10000;

# Allow project-specific .vimrc files, but restrict commands to secure ones
exrc = true;
secure = true;
};

extraPlugins = with pkgs.vimPlugins; [
vim-fetch # accept ./path/to/file:123 as line numbers
];

colorschemes.kanagawa.enable = true;

editorconfig.enable = true;

plugins = {
bufferline.enable = true;
commentary.enable = true;
Expand All @@ -47,6 +79,15 @@
lualine = {
enable = true;
globalstatus = true;
# https://github.com/nvim-lualine/lualine.nvim?tab=readme-ov-file#filename-component-options
sections = {
lualine_b = [ {
extraConfig.sources = [ "nvim_diagnostic" "nvim_lsp" ];
} ];
lualine_c = [ {
extraConfig.path = 1;
} ];
};
theme = "onedark";
};
nvim-autopairs.enable = true; # brackets, html, ...
Expand Down Expand Up @@ -77,33 +118,6 @@
};
};

keymaps = [
# Use tab as buffer switcher in normal mode
{
mode = "n";
key = "<Tab>";
action = ":bnext<CR>";
}
{
mode = "n";
key = "<S-Tab>";
action = ":bprevious<CR>";
}

# Delete search highlight with backspace
{
mode = "n";
key = "<BS>";
action = ":nohlsearch<CR>";
}
# move line up(n)
{ mode = "n"; key = "<A-j>"; action = ":m .+1<CR>=="; }
# move line down(n)
{ mode = "n"; key = "<A-k>"; action = ":m .-2<CR>=="; }
# move line up(v)
{ mode = "v"; key = "<A-j>"; action = ":m '>+1<CR>gv=gv"; }
# move line down(v)
{ mode = "v"; key = "<A-k>"; action = ":m '<-2<CR>gv=gv"; }
{ mode = "n"; key = "<leader>gb"; action = ":Gitsign blame_line<CR>"; }
];
viAlias = true;
vimAlias = true;
}
15 changes: 15 additions & 0 deletions modules/lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ in
plugins = {
lint = {
enable = true;
linters.yamllint.args = [
"--config-file ${pkgs.writeText "yamllint-config.yaml" /* yaml */ ''
rules:
document-start:
present: false
line-length:
max: 180
''}"
];
lintersByFt = {
css = [ "eslint_d" ];
scss = [ "eslint_d" ];
Expand Down Expand Up @@ -74,6 +83,12 @@ in
jsonls.enable = true;
# does language correction even on keywords...
#ltex.enable = true;
lua-ls = {
enable = true;
extraOptions.Lua = {
telemetry.enable = false;
};
};
marksman.enable = true;
#nixd.enable = true;
nil-ls = {
Expand Down
1 change: 0 additions & 1 deletion modules/treesitter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"systemverilog"
"verilog"
];
indent = true;
};

# Enable automatically closing and renaming HTML tags
Expand Down

0 comments on commit c2b7955

Please sign in to comment.