From fafb89f62f9939aea2b57fa704a07e3d4748c257 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sat, 29 Jul 2023 16:01:53 -0700 Subject: [PATCH] added basic features for usable nvim --- flake.nix | 1 + modules/neovim.nix | 102 +++++++++++++++++++++++++------ modules/old-neovim.nix | 49 +++++++++++++++ rsrcs/.vimrc | 99 ------------------------------ rsrcs/nvim.lua | 130 ++++++++++++++++++++++++++++++++++++++++ rust-shell-template.nix | 2 + 6 files changed, 265 insertions(+), 118 deletions(-) create mode 100644 modules/old-neovim.nix delete mode 100644 rsrcs/.vimrc create mode 100644 rsrcs/nvim.lua diff --git a/flake.nix b/flake.nix index f878c99..d112aa7 100644 --- a/flake.nix +++ b/flake.nix @@ -96,6 +96,7 @@ users.${user} = { imports = [ (import ./users/${user}.nix) + # Add nixvim to the homemanager inputs.nixvim.homeManagerModules.nixvim ]; }; diff --git a/modules/neovim.nix b/modules/neovim.nix index c85b220..996a227 100644 --- a/modules/neovim.nix +++ b/modules/neovim.nix @@ -6,7 +6,87 @@ in enable = true; viAlias = true; vimAlias = true; - #extraConfigVim = import ./../rsrcs/.vimrc; + + globals = { + mapleader = " "; + }; + + options = { + autoindent = true; + expandtab = true; + foldlevel=20; + guifont = "MesloLGS\ NF\ 10"; + number = true; + shiftwidth = 4; + tabstop = 4; + }; + + # https://github.com/pupbrained/nix-config/blob/29af4835f21940af51b86313c451fb572a29874a/pkgs/nixvim.nix#L8 + # maps. + + plugins = { + + telescope = { + enable = true; + }; + + treesitter = { + enable = true; + folding = true; + indent = true; + ensureInstalled = [ + "rust" + "toml" + "lua" + ]; + }; + treesitter-rainbow = { + enable = true; + }; + treesitter-refactor = { + enable = true; + #highlightCurrentScope.enable = true; + navigation.enable = true; + smartRename.enable = true; + }; + + comment-nvim = { + enable = true; + toggler = { + line = ""; + block = ""; + }; + }; + + floaterm = { + enable = true; + position = "auto"; + keymaps = { + toggle = "t"; + }; + }; + + rust-tools.enable = true; + nvim-cmp.enable = true; + + cmp-nvim-lsp.enable = true; + # Read settings here: https://github.com/mfussenegger/nvim-dap#Usage + # See :help dap.txt, :help dap-mapping and :help dap-api. + cmp-dap.enable = true; + + cmp-vsnip.enable = true; + cmp-buffer.enable = true; + cmp-nvim-lsp-signature-help.enable = true; + cmp-nvim-lua.enable = true; + cmp-path.enable = true; + + nix.enable = true; + airline = { + enable = true; + powerline = true; + }; + }; + extraConfigLua = builtins.readFile ./../rsrcs/nvim.lua; extraPlugins = with pkgs.vimPlugins; let moonfly = pkgs.vimUtils.buildVimPlugin { @@ -20,26 +100,10 @@ in }; in [ # Themes and statusbar - # vim-airline - # vim-airline-themes # moonfly - #QoL features - # telescope-nvim - # nvim-treesitter - - nvchad - nvchad-ui - - # Rust - coc-rust-analyzer - coc-nvim - rust-vim - - # Language support - vim-nix - typescript-vim - vim-javascript + nvim-lspconfig + hop-nvim ]; }; } diff --git a/modules/old-neovim.nix b/modules/old-neovim.nix new file mode 100644 index 0000000..a3f3705 --- /dev/null +++ b/modules/old-neovim.nix @@ -0,0 +1,49 @@ +{ config, pkgs, ... }: + +let + +in +{ + programs.neovim = { + enable = true; + vimAlias = true; + defaultEditor = true; + plugins = with pkgs.vimPlugins; + let + moonfly = pkgs.vimUtils.buildVimPlugin { + name = "moonfly"; + src = pkgs.fetchFromGitHub { + owner = "bluz71"; + repo = "vim-moonfly-colors"; + rev = "d51e3ad78654aa479d59adb81a98f179d595bdee"; + sha256 = "0uHEB8uNQeGpVWuZfyrVAWTyefJMCitTmNpHmKVFOaQ="; + }; + }; + in [ + # Themes and statusbar + # vim-airline + # vim-airline-themes + # moonfly + + #QoL features + # telescope-nvim + # nvim-treesitter + + nvchad + nvchad-ui + + # Rust + coc-rust-analyzer + coc-nvim + rust-vim + + # Language support + vim-nix + typescript-vim + vim-javascript + ]; + +# extraConfig = builtins.readFile ../rsrcs/.vimrc; + }; + +} diff --git a/rsrcs/.vimrc b/rsrcs/.vimrc deleted file mode 100644 index 6450373..0000000 --- a/rsrcs/.vimrc +++ /dev/null @@ -1,99 +0,0 @@ -set autoindent -set expandtab -set tabstop=4 -set shiftwidth=4 -set foldmethod=syntax -set foldlevel=20 -set number -set guifont=MesloLGS\ NF\ 10 -syntax on -syntax enable -filetype plugin indent on - - - " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable - " nvim-treesitter - " delays and poor user experience. - set updatetime=300 - - set signcolumn=number - - let g:airline_powerline_fonts=1 - let g:typescript_compiler_binary = 'npx tsc' - - " Use tab for trigger completion with characters ahead and navigate. - " NOTE: Use command ':verbose imap ' to make sure tab is not mapped by - " other plugin before putting this into your config. - inoremap - \ pumvisible() ? "\" : - \ CheckBackspace() ? "\" : - \ coc#refresh() - - inoremap pumvisible() ? "\" : "\" - inoremap coc#pum#visible() ? coc#pum#confirm() - \: "\u\\=coc#on_enter()\" - - function! CheckBackspace() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' - endfunction - - " Use to trigger completion. - inoremap coc#refresh() - - - " Use `[g` and `]g` to navigate diagnostics - " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. - nmap [g (coc-diagnostic-prev) - nmap ]g (coc-diagnostic-next) - - " GoTo code navigation. - nmap gd (coc-definition) - nmap gy (coc-type-definition) - nmap gi (coc-implementation) - nmap gr (coc-references) - - " Use K to show documentation in preview window. - nnoremap K :call ShowDocumentation() - - function! ShowDocumentation() - if CocAction('hasProvider', 'hover') - call CocActionAsync('doHover') - else - call feedkeys('K', 'in') - endif - endfunction - - " Highlight the symbol and its references when holding the cursor. - autocmd CursorHold * silent call CocActionAsync('highlight') - - " Symbol renaming. - nmap rn (coc-rename) - - " Formatting selected code. - xmap f (coc-format-selected) - nmap f (coc-format-selected) - let g:rustfmt_autosave = 1 - - " Add `:Format` command to format current buffer. - command! -nargs=0 Format :call CocActionAsync('format') - - " Add `:Fold` command to fold current buffer. - command! -nargs=? Fold :call CocAction('fold', ) - - " Add `:OR` command for organize imports of the current buffer. - command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport') - - " Add (Neo)Vim's native statusline support. - " NOTE: Please see `:h coc-status` for integrations with external plugins that - " provide custom statusline: lightline.vim, vim-airline. - set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} - - -" colorscheme moonfly -set number - -" Remove moonfly's background color for the terminal color -" highlight Normal ctermbg=NONE -" highlight LineNr ctermbg=NONE -" highlight CocInlayHint ctermbg=NONE diff --git a/rsrcs/nvim.lua b/rsrcs/nvim.lua new file mode 100644 index 0000000..bcb8ac9 --- /dev/null +++ b/rsrcs/nvim.lua @@ -0,0 +1,130 @@ + +-- Attached rust-analyzer server +local rt = require("rust-tools") + +rt.setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "a", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, +}) + +-- LSP Diagnostics Options Setup +local sign = function(opts) + vim.fn.sign_define(opts.name, { + texthl = opts.name, + text = opts.text, + numhl = '' + }) +end + +sign({name = 'DiagnosticSignError', text = ''}) +sign({name = 'DiagnosticSignWarn', text = ''}) +sign({name = 'DiagnosticSignHint', text = ''}) +sign({name = 'DiagnosticSignInfo', text = ''}) + +vim.diagnostic.config({ + virtual_text = false, + signs = true, + update_in_insert = true, + underline = true, + severity_sort = false, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.cmd([[ +set signcolumn=yes +autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) +]]) + + +--Set completeopt to have a better completion experience +-- :help completeopt +-- menuone: popup even when there's only one match +-- noinsert: Do not insert text until a selection is made +-- noselect: Do not select, force to select one from the menu +-- shortness: avoid showing extra messages when using completion +-- updatetime: set updatetime for CursorHold +vim.opt.shortmess = vim.opt.shortmess + { c = true} +vim.api.nvim_set_option('updatetime', 300) + +-- Fixed column for diagnostics to appear +-- Show autodiagnostic popup on cursor hover_range +-- Goto previous / next diagnostic warning / error +-- Show inlay_hints more frequently +vim.cmd([[ +set signcolumn=yes +autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) +]]) + +-- Completion Plugin Setup +local cmp = require'cmp' +cmp.setup({ + -- Enable LSP snippets + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }) + }, + -- Installed sources: + sources = { + { name = 'path' }, -- file paths + { name = 'nvim_lsp', keyword_length = 3 }, -- from language server + { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized + { name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* + { name = 'buffer', keyword_length = 2 }, -- source current buffer + { name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip + { name = 'calc'}, -- source for math calculation + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon ={ + nvim_lsp = 'λ', + vsnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + item.menu = menu_icon[entry.source.name] + return item + end, + }, +}) + +-- https://github.com/phaazon/hop.nvim/wiki/Advanced-Hop +local hop = require('hop') +hop.setup { + keys = 'etovxqpdygfblzhckisuran', +} +local directions = require('hop.hint').HintDirection +vim.keymap.set('', '', function() + hop.hint_patterns({ multi_windows = true, current_line_only = false }) +end, {remap=true}) diff --git a/rust-shell-template.nix b/rust-shell-template.nix index cb8f09f..f5e01de 100644 --- a/rust-shell-template.nix +++ b/rust-shell-template.nix @@ -12,6 +12,8 @@ in pkgs.mkShell { buildInputs = with pkgs; [ ruststable + rust-analyzer + lldb ]; RUST_BACKTRACE = 1;