Add a simple neovim config

This commit is contained in:
Konstantin Nazarov 2024-05-11 17:20:32 +01:00
parent 9b210469ed
commit 45186dacb4
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
10 changed files with 302 additions and 36 deletions

View file

@ -167,10 +167,14 @@ in {
dnsutils dnsutils
graphviz graphviz
fzf fzf
fd
nixfmt nixfmt
my_emacs my_emacs
libreoffice libreoffice
gcc gcc
neovim
go
gopls
#network-manager-applet #network-manager-applet
(clang-tools.override { (clang-tools.override {
llvmPackages = llvmPackages_17; llvmPackages = llvmPackages_17;
@ -377,6 +381,7 @@ in {
fonts.fontDir.enable = true; fonts.fontDir.enable = true;
fonts.packages = with pkgs; [ fonts.packages = with pkgs; [
dejavu_fonts dejavu_fonts
(nerdfonts.override { fonts = [ "SourceCodePro" ]; })
source-code-pro source-code-pro
font-awesome # for waybar indicators font-awesome # for waybar indicators
]; ];
@ -505,6 +510,54 @@ in {
}; };
programs.neovim = let
modus-themes = pkgs.vimUtils.buildVimPlugin {
pname = "modus-themes.nvim";
version = "2024-05-06";
src = pkgs.fetchFromGitHub {
owner = "miikanissi";
repo = "modus-themes.nvim";
rev = "705ea8debb9d9afe4e631166fcc6121782dd0b32";
sha256 = "0hs2ylf1rj0655kpwr4blh399r8k7lg0r2a4nbnymy1pbkx1gh1i";
};
meta.homepage = "https://github.com/miikanissi/modus-themes.nvim/";
};
in {
enable = true;
plugins = with pkgs; [
vimPlugins.nvim-treesitter
vimPlugins.nvim-treesitter.withAllGrammars
pkgs.vimPlugins.nvim-treesitter-textobjects
vimPlugins.nvim-lspconfig
vimPlugins.lualine-nvim
vimPlugins.telescope-nvim
vimPlugins.telescope-fzf-native-nvim
vimPlugins.nvim-web-devicons
vimPlugins.nvim-cmp
vimPlugins.cmp-nvim-lsp
vimPlugins.cmp-buffer
vimPlugins.cmp-cmdline
vimPlugins.luasnip
modus-themes
];
extraConfig = ''
lua << EOF
${builtins.readFile nvim/basics.lua}
${builtins.readFile nvim/treesitter.lua}
${builtins.readFile nvim/lualine.lua}
${builtins.readFile nvim/telescope.lua}
${builtins.readFile nvim/completion.lua}
${builtins.readFile nvim/luasnip.lua}
${builtins.readFile nvim/lspconfig.lua}
'';
viAlias = true;
vimAlias = true;
};
wayland.windowManager.sway = { wayland.windowManager.sway = {
enable = true; enable = true;
xwayland = true; xwayland = true;
@ -563,29 +616,27 @@ in {
programs.foot = { programs.foot = {
enable = true; enable = true;
settings = { settings = {
main = { font = "monospace:size=10"; }; main = { font = "Source Code Pro:size=12"; };
colors = { colors = {
background = "feffff"; background = "ffffff";
foreground = "333333"; foreground = "000000";
regular0 = "000000";
regular0 = "333333"; regular1 = "a60000";
regular1 = "bd4436"; regular2 = "005e00";
regular2 = "008700"; regular3 = "813e00";
regular3 = "cdcc42"; regular4 = "0031a9";
regular4 = "0017f5"; regular5 = "721045";
regular5 = "b92cc6"; regular6 = "00538b";
regular6 = "5bbdf9"; regular7 = "bfbfbf";
regular7 = "c7c7c7"; bright0 = "595959";
bright1 = "972500";
bright0 = "333333"; bright2 = "315b00";
bright1 = "bd4436"; bright3 = "70480f";
bright2 = "008700"; bright4 = "2544bb";
bright3 = "cdcc42"; bright5 = "5317ac";
bright4 = "0017f5"; bright6 = "005a5f";
bright5 = "b92cc6"; bright7 = "ffffff";
bright6 = "5bbdf9";
bright7 = "feffff";
}; };
key-bindings = { key-bindings = {
clipboard-copy = "Control+Insert"; clipboard-copy = "Control+Insert";

View file

@ -462,6 +462,10 @@ Enable org-roam
org-gnus org-info org-irc org-mhe org-gnus org-info org-irc org-mhe
org-rmail org-checklist org-mu4e)) org-rmail org-checklist org-mu4e))
;; Enable line wrap by default in org buffers
(setq org-startup-truncated nil)
;; Sometimes I sit at night until 4 AM, and I still want org to treat it ;; Sometimes I sit at night until 4 AM, and I still want org to treat it
;; as "today" ;; as "today"
(setq org-extend-today-until 4) (setq org-extend-today-until 4)
@ -973,6 +977,14 @@ window, unless BACKGROUND (prefix-argument) is non-nil.
)) ))
) )
(defun nix-gopls (int)
(let ((curproj (project-current nil)))
(if (and curproj (file-exists-p (format "%s/flake.nix" (project-root curproj))))
(list "nix" "develop" (format "%s#" (project-root curproj)) "--command" "bash" "-c" "gopls")
(list "gopls")
))
)
(with-eval-after-load 'eglot (with-eval-after-load 'eglot
(add-hook (add-hook
'eglot-managed-mode-hook 'eglot-managed-mode-hook
@ -990,11 +1002,17 @@ window, unless BACKGROUND (prefix-argument) is non-nil.
`(c++-ts-mode . ,#'nix-clangd)) `(c++-ts-mode . ,#'nix-clangd))
(add-to-list 'eglot-server-programs (add-to-list 'eglot-server-programs
`(c-ts-mode . ,#'nix-clanngd)) `(c-ts-mode . ,#'nix-clanngd))
(add-to-list 'eglot-server-programs
`(go-ts-mode . ,#'nix-gopls))
(add-to-list 'eglot-server-programs
`(go-mode . ,#'nix-gopls))
) )
(add-hook 'c++-mode-hook 'eglot-ensure) (add-hook 'c++-mode-hook 'eglot-ensure)
(add-hook 'c++-ts-mode-hook 'eglot-ensure) (add-hook 'c++-ts-mode-hook 'eglot-ensure)
(add-hook 'c-ts-mode-hook 'eglot-ensure) (add-hook 'c-ts-mode-hook 'eglot-ensure)
(add-hook 'go-ts-mode-hook 'eglot-ensure)
(add-hook 'go-mode-hook 'eglot-ensure)
(use-package clang-format) (use-package clang-format)
(use-package clang-format+) (use-package clang-format+)
@ -1017,6 +1035,12 @@ window, unless BACKGROUND (prefix-argument) is non-nil.
(and (file-exists-p try) (and (file-exists-p try)
(cons (file-truename try) 'lcov)))))) (cons (file-truename try) 'lcov))))))
;; Go
(add-hook 'before-save-hook #'gofmt-before-save)
(use-package go-mode)
;; Zig ;; Zig
(use-package zig-mode) (use-package zig-mode)

View file

@ -11,11 +11,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1712108714, "lastModified": 1714669473,
"narHash": "sha256-QzrcwGuuAP1octIcUw/d+Yi5BEXYt1NOwNLpeUrqKTk=", "narHash": "sha256-LuwvRYxFw8bE3b75oun2HjdbnwGArYEDzRdhtxkx95o=",
"owner": "nix-community", "owner": "nix-community",
"repo": "emacs-overlay", "repo": "emacs-overlay",
"rev": "5d0a10938c32f3cb95d1f1f18127948d239c6720", "rev": "8f77253911c7dc3ac829781ac7f37d1d35447c5a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -69,11 +69,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1710888565, "lastModified": 1714043624,
"narHash": "sha256-s9Hi4RHhc6yut4EcYD50sZWRDKsugBJHSbON8KFwoTw=", "narHash": "sha256-Xn2r0Jv95TswvPlvamCC46wwNo8ALjRCMBJbGykdhcM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "f33900124c23c4eca5831b9b5eb32ea5894375ce", "rev": "86853e31dc1b62c6eeed11c667e8cdd0285d4411",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -105,11 +105,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1712159163, "lastModified": 1714679241,
"narHash": "sha256-dOQAAr9adh00rlCg/eq6GwXo+pH0VC7RyE5uWzzAFLo=", "narHash": "sha256-Ufz2WBGCcqeXkVgD7bdc+JCrnyPt6G28Xpq2ussqygs=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "67e2bc037137e4fdcf6b3132a4f54c165726500b", "rev": "a6f8947d5a77b88ff43625408e2685c0be100a9b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -120,11 +120,11 @@
}, },
"nixpkgs-stable": { "nixpkgs-stable": {
"locked": { "locked": {
"lastModified": 1711668574, "lastModified": 1714531828,
"narHash": "sha256-u1dfs0ASQIEr1icTVrsKwg2xToIpn7ZXxW3RHfHxshg=", "narHash": "sha256-ILsf3bdY/hNNI/Hu5bSt2/KbmHaAVhBbNUOdGztTHEg=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "219951b495fc2eac67b1456824cc1ec1fd2ee659", "rev": "0638fe2715d998fa81d173aad264eb671ce2ebc1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -198,11 +198,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1711855048, "lastModified": 1713892811,
"narHash": "sha256-HxegAPnQJSC4cbEbF4Iq3YTlFHZKLiNTk8147EbLdGg=", "narHash": "sha256-uIGmA2xq41vVFETCF1WW4fFWFT2tqBln+aXnWrvjGRE=",
"owner": "Mic92", "owner": "Mic92",
"repo": "sops-nix", "repo": "sops-nix",
"rev": "99b1e37f9fc0960d064a7862eb7adfb92e64fa10", "rev": "f1b0adc27265274e3b0c9b872a8f476a098679bd",
"type": "github" "type": "github"
}, },
"original": { "original": {

17
nvim/basics.lua Normal file
View file

@ -0,0 +1,17 @@
vim.opt.termguicolors = true
vim.cmd[[colorscheme modus_operandi]]
HOME = os.getenv("HOME")
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.scrolloff=10
vim.opt.splitright = true
vim.opt.splitbelow = true
vim.opt.relativenumber = true
vim.opt.clipboard = 'unnamedplus'
vim.g.mapleader = ' '
vim.opt.shortmess :append("I")

84
nvim/completion.lua Normal file
View file

@ -0,0 +1,84 @@
local luasnip = require("luasnip")
local cmp = require'cmp'
cmp.setup({
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-k>'] = cmp.mapping.scroll_docs(-4),
['<C-j>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<C-k>"] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<C-j>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'nvim_lua' },
{ name = 'buffer' },
{ name = 'path' },
},
window = {
completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
formatting = {
},
snippet = {
expand = function(args)
require'luasnip'.lsp_expand(args.body)
end,
},
experimental = {
native_menu = false,
ghost_text = true
},
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})

4
nvim/lspconfig.lua Normal file
View file

@ -0,0 +1,4 @@
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
require'lspconfig'.gopls.setup{capabilities=capabilities}
require'lspconfig'.rnix.setup{capabilities=capabilities}

3
nvim/lualine.lua Normal file
View file

@ -0,0 +1,3 @@
require('lualine').setup({options = {
theme = "onelight"
}})

1
nvim/luasnip.lua Normal file
View file

@ -0,0 +1 @@
local ls = require("luasnip")

21
nvim/telescope.lua Normal file
View file

@ -0,0 +1,21 @@
require('telescope').setup{
extensions = {
fzf = {
fuzzy = true,
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
},
project = {
}
}
}
require('telescope').load_extension('fzf')
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})

61
nvim/treesitter.lua Normal file
View file

@ -0,0 +1,61 @@
require'nvim-treesitter.configs'.setup {
sync_install = false,
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn", -- set to `false` to disable one of the mappings
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
swap = {
enable = true,
swap_next = {
['<leader>a'] = '@parameter.inner',
},
swap_previous = {
['<leader>A'] = '@parameter.inner',
},
},
},
indent = { enable = true }
}