Migrate neovim configuration to nixvim

This commit is contained in:
♥ Minnie ♥ 2024-08-04 22:21:23 +08:00
parent 41e97a6fc9
commit bede9baa04
Signed by: jasmine
GPG key ID: 8563E358D4E8040E
12 changed files with 374 additions and 509 deletions

View file

@ -3,6 +3,7 @@
{
imports = [
./git.nix
./nvim.nix
./zsh.nix
];

View file

@ -0,0 +1,7 @@
{ inputs, ... }:
{
# Install our nixvim configuration for neovim.
home.packages = [ inputs.nixvim-config.packages.x86_64-linux.default ];
}

View file

@ -1,31 +0,0 @@
--
-- Bootstrap lazy.nvim
--
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
'git',
'clone',
'--filter=blob:none',
'https://github.com/folke/lazy.nvim.git',
'--branch=stable', -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
--
-- Load our configurations
--
require('configs.options')
--
-- Load our plugin specs
--
require('lazy').setup('plugins')

View file

@ -1,17 +0,0 @@
-- Keybinds
vim.g.mapleader = ' '
-- General
vim.opt.number = true
vim.opt.showmode = false
vim.opt.swapfile = false
vim.opt.clipboard = 'unnamedplus'
-- Tabs & spaces
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.autoindent = true
vim.opt.copyindent = true

View file

@ -1,207 +0,0 @@
return {
--
-- Ollama Workflows
--
{
'nomnivore/ollama.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
'stevearc/dressing.nvim',
},
-- All the user commands added by the plugin
cmd = { "Ollama", "OllamaModel", "OllamaServe", "OllamaServeStop" },
keys = {
-- Sample keybind for prompt menu. Note that the <c-u> is important for selections to work properly.
{
"<leader>oo",
":<c-u>lua require('ollama').prompt()<cr>",
desc = "ollama prompt",
mode = { "n", "v" },
},
-- Sample keybind for direct prompting. Note that the <c-u> is important for selections to work properly.
{
"<leader>oG",
":<c-u>lua require('ollama').prompt('Generate_Code')<cr>",
desc = "ollama Generate Code",
mode = { "n", "v" },
},
},
---@type Ollama.Config
opts = {
model = "llama3:8b",
}
},
--
-- LSP Configuration
--
{
'neovim/nvim-lspconfig',
event = { 'BufReadPost', 'BufNewFile' },
dependencies = {
'hrsh7th/nvim-cmp', -- Autocompletion plugin
'hrsh7th/cmp-nvim-lsp', -- LSP source for nvim-cmp
'saadparwaiz1/cmp_luasnip', -- Snippets source for nvim-cmp
'L3MON4D3/LuaSnip', -- Snippets plugin
},
config = function ()
--
-- Setup language servers.
--
local lspconfig = require('lspconfig')
-- Lua
lspconfig.lua_ls.setup {
on_init = function(client)
local path = client.workspace_folders[1].name
if not vim.loop.fs_stat(path..'/.luarc.json') and not vim.loop.fs_stat(path..'/.luarc.jsonc') then
client.config.settings = vim.tbl_deep_extend('force', client.config.settings, {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
}
})
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
end
return true
end
}
-- Haskell
lspconfig.hls.setup{
filetypes = { 'haskell', 'lhaskell', 'cabal' },
}
-- Nix
lspconfig.nil_ls.setup{}
-- C
lspconfig.clangd.setup{}
-- YAML
lspconfig.yamlls.setup{}
--
-- Global mappings
--
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
--
-- Autocompletion
--
-- Add additional capabilities supported by nvim-cmp
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
}
end
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
end
},
}

View file

@ -1,21 +0,0 @@
return {
--
-- Modified version of gruvbox
--
{
'sainnhe/gruvbox-material',
lazy = false,
priority = 1000,
config = function()
vim.o.termguicolors = true
vim.o.background = 'dark'
vim.g.gruvbox_material_background = 'hard'
vim.g.gruvbox_material_better_performance = 1
vim.cmd([[colorscheme gruvbox-material]])
end,
},
}

View file

@ -1,97 +0,0 @@
return {
--
-- Treesitter
--
{
'nvim-treesitter/nvim-treesitter',
build = ":TSUpdate",
config = function()
local configs = require('nvim-treesitter.configs')
configs.setup({
auto_install = true,
highlight = { enable = true },
indent = { enable = true },
})
end
},
--
-- Fuzzy Finder
--
{
'nvim-telescope/telescope.nvim',
tag = '0.1.3',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-tree/nvim-web-devicons',
},
keys = {
{ '<leader>ff', '<cmd>Telescope find_files<cr>', desc = 'Find Files' },
{ '<leader>fg', '<cmd>Telescope live_grep<cr>' , desc = 'Live Grep' },
{ '<leader>fb', '<cmd>Telescope buffers<cr>' , desc = 'Buffers' },
{ '<leader>fh', '<cmd>Telescope help_tags<cr>' , desc = 'Help Tags' },
},
config = function()
require('telescope').setup()
end
},
--
-- Commenting
--
{
'numToStr/Comment.nvim',
config = function()
require('Comment').setup()
end
},
--
-- Git Commands
--
{
'kdheepak/lazygit.nvim',
dependencies = {
'nvim-lua/plenary.nvim'
},
keys = {
{ '<leader>gg', '<cmd>LazyGit<cr>', desc = 'LazyGit' },
}
},
--
-- Display Keybindings
--
{
'folke/which-key.nvim',
event = 'VeryLazy',
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 300
end,
opts = { },
},
--
-- Delete Buffers
--
{
'famiu/bufdelete.nvim',
cmd = { 'Bdelete', 'Bwipeout' },
keys = {
{ '<leader>bd', '<cmd>Bdelete<cr>', desc = 'Buffer Delete' },
{ '<leader>bw', '<cmd>Bwipeout<cr>', desc = 'Buffer Wipeout' },
},
},
}

View file

@ -1,86 +0,0 @@
return {
--
-- File explorer
--
{
'nvim-neo-tree/neo-tree.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-tree/nvim-web-devicons',
'MunifTanjim/nui.nvim',
},
keys = {
{ '\\', '<cmd>Neotree reveal<cr>', desc = 'Neotree' },
},
},
--
-- Statusline
--
{
'nvim-lualine/lualine.nvim',
event = 'VeryLazy',
dependencies = {
'nvim-tree/nvim-web-devicons',
},
config = function()
-- Define a function to check that ollama is installed and working
local function get_condition()
return package.loaded["ollama"] and require("ollama").status ~= nil
end
-- Define a function to check the status and return the corresponding icon
local function get_status_icon()
local status = require("ollama").status()
if status == "IDLE" then
return "OLLAMA IDLE"
elseif status == "WORKING" then
return "OLLAMA BUSY"
end
end
require('lualine').setup {
options = {
icons_enabled = true,
theme = 'gruvbox-material',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
globalstatus = true,
extensions = {
'neotree'
},
},
tabline = {
lualine_a = {'buffers'},
};
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = { { 'filename', path = 1 } },
lualine_x = { get_status_icon, get_condition, 'encoding', 'fileformat', 'filetype' },
lualine_y = { "progress" },
lualine_z = { "location" },
},
}
end,
},
--
-- Git decorations
--
{
'lewis6991/gitsigns.nvim',
config = function()
require('gitsigns').setup()
end
},
}

View file

@ -1,29 +0,0 @@
{ pkgs, ... }:
{
programs.neovim = {
enable = true;
#package = pkgs.neovim-nightly;
defaultEditor = true;
extraPackages = with pkgs; [
# Required for nvim-treesitter
gcc
# Required for telescope.nvim
fd
ripgrep
# Required for markdown-preview.nvim
nodejs
yarn
# Language server packages
nil
haskell-language-server
lua-language-server
clang-tools
yaml-language-server
];
};
home.persistence."/persist/home/sajenim".directories = [ ".local/share/nvim" ];
xdg.configFile.nvim = { source = ./config; recursive = true; };
}