feat(nvim): move into nvim dir
This commit is contained in:
commit
d00bf0d21c
455
default.nix
Normal file
455
default.nix
Normal file
@ -0,0 +1,455 @@
|
|||||||
|
{ config, pkgs, lib, ... }: with lib; let
|
||||||
|
rust-analyzer = if (pkgs ? rust-analyzer-nightly && config.class ? dev) then pkgs.rust-analyzer-nightly else pkgs.rust-analyzer;
|
||||||
|
rust-sdk = with pkgs; if config.class ? dev then
|
||||||
|
symlinkJoin
|
||||||
|
{
|
||||||
|
name = "nvim-fenix";
|
||||||
|
paths = [
|
||||||
|
(fenix.latest.withComponents [
|
||||||
|
"cargo"
|
||||||
|
"clippy-preview"
|
||||||
|
"rust-src"
|
||||||
|
"rust-std"
|
||||||
|
"rustc"
|
||||||
|
"rustfmt-preview"
|
||||||
|
])
|
||||||
|
cargo-watch
|
||||||
|
];
|
||||||
|
} else symlinkJoin { name = "nvim-rust"; paths = [ rustc cargo rustfmt clippy cargo-watch ]; };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
|
||||||
|
programs.neovim = {
|
||||||
|
|
||||||
|
# https://github.com/nix-community/home-manager/blob/master/modules/programs/neovim.nix
|
||||||
|
enable = true;
|
||||||
|
vimAlias = true;
|
||||||
|
withNodeJs = true;
|
||||||
|
extraPackages = with pkgs; [ fzf xclip fish ];
|
||||||
|
plugins = with pkgs.vimPlugins; [
|
||||||
|
vim-fugitive
|
||||||
|
neogit diffview-nvim
|
||||||
|
vim-airline
|
||||||
|
zephyr-nvim
|
||||||
|
vim-nix
|
||||||
|
vim-toml
|
||||||
|
elm-vim
|
||||||
|
vim-markdown
|
||||||
|
split-term-vim
|
||||||
|
# vim-grammarous
|
||||||
|
markdown-preview-nvim
|
||||||
|
rainbow
|
||||||
|
nerdtree
|
||||||
|
nerdtree-git-plugin
|
||||||
|
fzf-vim
|
||||||
|
coc-sh
|
||||||
|
coc-nvim
|
||||||
|
coc-rust-analyzer
|
||||||
|
coc-json
|
||||||
|
coc-yaml
|
||||||
|
coc-tsserver
|
||||||
|
coc-prettier
|
||||||
|
coc-pyright
|
||||||
|
coc-diagnostic
|
||||||
|
vimtex
|
||||||
|
coc-vimtex
|
||||||
|
coc-html
|
||||||
|
coc-go
|
||||||
|
coc-spell-checker
|
||||||
|
editorconfig-nvim
|
||||||
|
# tmuxline-vim
|
||||||
|
nvim-dap
|
||||||
|
nvim-dap-ui
|
||||||
|
nvim-notify
|
||||||
|
rust-tools-nvim
|
||||||
|
crates-nvim
|
||||||
|
nvim-lspconfig
|
||||||
|
telescope-nvim
|
||||||
|
telescope-undo-nvim
|
||||||
|
oil-nvim
|
||||||
|
distant-nvim
|
||||||
|
];
|
||||||
|
extraConfig = let pkgBin = pkg: "${pkgs.${pkg}}/bin/${pkg}"; in
|
||||||
|
''
|
||||||
|
let mapleader = ","
|
||||||
|
|
||||||
|
|
||||||
|
set hidden
|
||||||
|
|
||||||
|
" disable mouse
|
||||||
|
set mouse=
|
||||||
|
|
||||||
|
" GoTo code navigation.
|
||||||
|
nmap <silent> gd <Plug>(coc-definition)
|
||||||
|
nmap <silent> gy <Plug>(coc-type-definition)
|
||||||
|
nmap <silent> gi <Plug>(coc-implementation)
|
||||||
|
nmap <silent> gr <Plug>(coc-references)
|
||||||
|
|
||||||
|
|
||||||
|
" Rename
|
||||||
|
nmap <leader>rn <Plug>(coc-rename)
|
||||||
|
|
||||||
|
" Use K to show documentation in preview window.
|
||||||
|
nnoremap <silent> K :call ShowDocumentation()<CR>
|
||||||
|
|
||||||
|
nmap <leader>ac <Plug>(coc-codeaction)
|
||||||
|
nmap <leader>as <Plug>(coc-codeaction-cursor)
|
||||||
|
nmap <leader>cl <Plug>(coc-codelens-action)
|
||||||
|
|
||||||
|
nmap <silent> [G <Plug>(coc-diagnostic-next-error)
|
||||||
|
nmap <silent> ]G <Plug>(coc-diagnostic-prev-error)
|
||||||
|
|
||||||
|
nmap <silent> [g <Plug>(coc-diagnostic-next)
|
||||||
|
nmap <silent> ]g <Plug>(coc-diagnostic-prev)
|
||||||
|
|
||||||
|
" NERDTree config
|
||||||
|
" autocmd VimEnter * NERDTree
|
||||||
|
autocmd BufEnter * NERDTreeMirror
|
||||||
|
|
||||||
|
"CTRL-t to toggle tree view with CTRL-t
|
||||||
|
nmap <silent> <C-t> :NERDTreeToggle<CR>
|
||||||
|
"Set F2 to put the cursor to the nerdtree
|
||||||
|
nmap <silent> <F2> :NERDTreeFind<CR>
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
" Formatting selected code.
|
||||||
|
xmap <leader>f <Plug>(coc-format-selected)
|
||||||
|
nmap <leader>f <Plug>(coc-format-selected)
|
||||||
|
nmap <leader>F <Plug>(coc-format)
|
||||||
|
|
||||||
|
|
||||||
|
" " Copy to clipboard
|
||||||
|
vnoremap <leader>y "+y
|
||||||
|
nnoremap <leader>Y "+yg_
|
||||||
|
nnoremap <leader>y "+y
|
||||||
|
nnoremap <leader>yy "+yy
|
||||||
|
|
||||||
|
" " Paste from clipboard
|
||||||
|
nnoremap <leader>p "+p
|
||||||
|
nnoremap <leader>P "+P
|
||||||
|
vnoremap <leader>p "+p
|
||||||
|
vnoremap <leader>P "+P
|
||||||
|
|
||||||
|
" " Tabbing https://webdevetc.com/blog/tabs-in-vim/
|
||||||
|
map <leader>tn :tabnew<cr>
|
||||||
|
map <leader>t<leader> :tabnext
|
||||||
|
map <leader>tm :tabmove
|
||||||
|
map <leader>tc :tabclose<cr>
|
||||||
|
map <leader>to :tabonly<cr>
|
||||||
|
|
||||||
|
" Display line numbers
|
||||||
|
set number relativenumber
|
||||||
|
|
||||||
|
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#_select_confirm()
|
||||||
|
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
|
||||||
|
|
||||||
|
map <F3> :mksession! .nvim_session <cr> " Quick write session with F3
|
||||||
|
map <F4> :source .nvim_session <cr> " And load session with F4
|
||||||
|
|
||||||
|
set undofile
|
||||||
|
set undodir=~/.vim/undodir
|
||||||
|
" Remember last posistion
|
||||||
|
|
||||||
|
" split-term-vim
|
||||||
|
let g:split_term_default_shell = "fish"
|
||||||
|
set splitright
|
||||||
|
|
||||||
|
" Airline
|
||||||
|
let g:airline#extensions#tabline#enabled = 1
|
||||||
|
let g:airline#extensions#tabline#show_tab_nr = 1
|
||||||
|
let g:airline#extensions#tabline#tab_nr_type = 1
|
||||||
|
|
||||||
|
" DAP
|
||||||
|
nnoremap <silent> <F5> <Cmd>lua require'dap'.continue()<CR>
|
||||||
|
nnoremap <silent> <F10> <Cmd>lua require'dap'.step_over()<CR>
|
||||||
|
nnoremap <silent> <F11> <Cmd>lua require'dap'.step_into()<CR>
|
||||||
|
nnoremap <silent> <F12> <Cmd>lua require'dap'.step_out()<CR>
|
||||||
|
nnoremap <silent> <Leader>b <Cmd>lua require'dap'.toggle_breakpoint()<CR>
|
||||||
|
nnoremap <silent> <Leader>B <Cmd>lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
|
||||||
|
nnoremap <silent> <Leader>lp <Cmd>lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
|
||||||
|
nnoremap <silent> <Leader>dr <Cmd>lua require'dap'.repl.open()<CR>
|
||||||
|
nnoremap <silent> <Leader>dl <Cmd>lua require'dap'.run_last()<CR>
|
||||||
|
|
||||||
|
|
||||||
|
if has("autocmd")
|
||||||
|
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
|
||||||
|
endif
|
||||||
|
'';
|
||||||
|
extraLuaConfig = ''
|
||||||
|
vim.opt.termguicolors = true
|
||||||
|
vim.notify = require("notify")
|
||||||
|
vim.notify.setup({
|
||||||
|
background_colour = "#000000"
|
||||||
|
})
|
||||||
|
local distant = require('distant')
|
||||||
|
distant:setup()
|
||||||
|
require("oil").setup()
|
||||||
|
local telescope = require('telescope.builtin')
|
||||||
|
vim.keymap.set('n', '<leader>ff', telescope.find_files, {})
|
||||||
|
vim.keymap.set('n', '<leader>fg', telescope.live_grep, {})
|
||||||
|
vim.keymap.set('n', '<leader>fb', telescope.buffers, {})
|
||||||
|
vim.keymap.set('n', '<leader>fh', telescope.help_tags, {})
|
||||||
|
require("telescope").setup({
|
||||||
|
extensions = {
|
||||||
|
undo = {
|
||||||
|
side_by_side = true,
|
||||||
|
layout_strategy = "vertical",
|
||||||
|
layout_config = {
|
||||||
|
preview_height = 0.8,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require('telescope').load_extension("undo")
|
||||||
|
local neogit = require('neogit')
|
||||||
|
-- git commit
|
||||||
|
-- vim.keymap.set('n', '<leader>gc', neogit.open, { "commit" })
|
||||||
|
-- git neo -> Neogit
|
||||||
|
vim.keymap.set('n', '<leader>gN', neogit.open, {})
|
||||||
|
neogit.setup({
|
||||||
|
git_services = {
|
||||||
|
["github.com"] = "https://github.com/''${owner}/''${repository}/compare/''${branch_name}?expand=1",
|
||||||
|
["bitbucket.org"] = "https://bitbucket.org/''${owner}/''${repository}/pull-requests/new?source=''${branch_name}&t=1",
|
||||||
|
["gitlab.com"] = "https://gitlab.com/''${owner}/''${repository}/merge_requests/new?merge_request[source_branch]=''${branch_name}",
|
||||||
|
["apps.terminal"] = "http://apps.terminal/''${owner}/''${repository}/merge_requests/new?merge_request[source_branch]=''${branch_name}",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
local dap, dapui = require("dap"), require("dapui")
|
||||||
|
dap.adapters.lldb = {
|
||||||
|
type = "executable",
|
||||||
|
command = "${pkgs.lldb}/bin/lldb-vscode",
|
||||||
|
name = "lldb",
|
||||||
|
}
|
||||||
|
local lldb = {
|
||||||
|
name = "Launch lldb",
|
||||||
|
type = "lldb", -- matches the adapter
|
||||||
|
request = "launch", -- could also attach to a currently running process
|
||||||
|
program = function()
|
||||||
|
return vim.fn.input(
|
||||||
|
"Path to executable: ",
|
||||||
|
vim.fn.getcwd() .. "/",
|
||||||
|
"file"
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
cwd = "$${workspaceFolder}",
|
||||||
|
stopOnEntry = false,
|
||||||
|
args = {},
|
||||||
|
console = internalConsole,
|
||||||
|
runInTerminal = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
dap.configurations.rust = {
|
||||||
|
lldb -- different debuggers or more configurations can be used here
|
||||||
|
}
|
||||||
|
--[[ local opts = {
|
||||||
|
dap = {
|
||||||
|
adapter = require("rust-tools.dap").get_codelldb_adapter("${pkgs.lldb}/bin/lldb-vscode", "${pkgs.lldb.lib}/lib/liblldb.so"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require("rust-tools").setup { opts } ]]
|
||||||
|
local dap_breakpoint = {
|
||||||
|
error = {
|
||||||
|
text = "🟥",
|
||||||
|
texthl = "LspDiagnosticsSignError",
|
||||||
|
linehl = "",
|
||||||
|
numhl = "",
|
||||||
|
},
|
||||||
|
rejected = {
|
||||||
|
text = "",
|
||||||
|
texthl = "LspDiagnosticsSignHint",
|
||||||
|
linehl = "",
|
||||||
|
numhl = "",
|
||||||
|
},
|
||||||
|
stopped = {
|
||||||
|
text = "⭐️",
|
||||||
|
texthl = "LspDiagnosticsSignInformation",
|
||||||
|
linehl = "DiagnosticUnderlineInfo",
|
||||||
|
numhl = "LspDiagnosticsSignInformation",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.fn.sign_define("DapBreakpoint", dap_breakpoint.error)
|
||||||
|
vim.fn.sign_define("DapStopped", dap_breakpoint.stopped)
|
||||||
|
vim.fn.sign_define("DapBreakpointRejected", dap_breakpoint.rejected)
|
||||||
|
|
||||||
|
dapui.setup()
|
||||||
|
|
||||||
|
-- Auto open and close dapUI
|
||||||
|
dap.listeners.after.event_initialized["dapui_config"] = function()
|
||||||
|
dapui.open()
|
||||||
|
end
|
||||||
|
dap.listeners.before.event_terminated["dapui_config"] = function()
|
||||||
|
dapui.close()
|
||||||
|
end
|
||||||
|
dap.listeners.before.event_exited["dapui_config"] = function()
|
||||||
|
dapui.close()
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
programs.git.ignores = [ ".nvim_session" ];
|
||||||
|
xdg.configFile."nvim/coc-settings.json".text =
|
||||||
|
let
|
||||||
|
preferProjectEnv = binName: alternate: pkgs.writeShellScript "${binName}-switcher" ''
|
||||||
|
if command -v ${binName}; then
|
||||||
|
${binName} ''${@}
|
||||||
|
else
|
||||||
|
${alternate} ''${@}
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
addSDK = { name, lsp, sdk }: with pkgs; runCommandLocal name
|
||||||
|
{
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
} ''
|
||||||
|
makeWrapper ${lsp} $out \
|
||||||
|
--prefix PATH : ${lib.makeBinPath sdk}
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
builtins.toJSON {
|
||||||
|
python = {
|
||||||
|
pythonPath = preferProjectEnv "python3" (pkgs.python3 + "/bin/python3");
|
||||||
|
formatting.autopep8Path = "${pkgs.python3Packages.autopep8}/bin/autopep8";
|
||||||
|
};
|
||||||
|
pyright = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
# https://rust-analyzer.github.io/manual.html
|
||||||
|
rust-analyzer = {
|
||||||
|
cargo = {
|
||||||
|
allFeatures = true;
|
||||||
|
runBuildScripts = true;
|
||||||
|
autoreload = true;
|
||||||
|
};
|
||||||
|
completion = {
|
||||||
|
autoimport.enable = true;
|
||||||
|
privateEditable.enable = true;
|
||||||
|
fullFunctionSignatures.enable = true; # https://github.com/rust-lang/rust-analyzer/pull/15582
|
||||||
|
snippets = rec {
|
||||||
|
"return Err(..)" = {
|
||||||
|
postfix = [ "reterr" ];
|
||||||
|
body = ''return Err($${receiver});'';
|
||||||
|
description = "return expression as Err";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
"format!(..)" = {
|
||||||
|
postfix = [ "fmt" ];
|
||||||
|
body = ''format!($${receiver})'';
|
||||||
|
description = "use receiver as format string";
|
||||||
|
scope = "expr";
|
||||||
|
|
||||||
|
};
|
||||||
|
"wrap { .. }" = {
|
||||||
|
postfix = [ "brace" "wrap" ];
|
||||||
|
body = ''{$${receiver}}'';
|
||||||
|
description = "wrap this type in { .. }";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
"async move { .. }" = {
|
||||||
|
postfix = [ "asyncm" ];
|
||||||
|
body = ''async move {$${receiver}}'';
|
||||||
|
description = "wrap this type in async move { .. }";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
"try { .. }" = {
|
||||||
|
postfix = [ "try" ];
|
||||||
|
body = ''let result: Result<_,_> = try {$${receiver}};'';
|
||||||
|
description = "wrap this type in try { .. }";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
"while let Some(item) = { .. } {}" = {
|
||||||
|
postfix = [ "letwhile" ];
|
||||||
|
body = ''while let Some(item) = $${receiver} {}'';
|
||||||
|
description = "wrap this type in while let Some";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
"let $x = $x.clone()" = {
|
||||||
|
postfix = [ "cloned" ];
|
||||||
|
body = ''let $${receiver} = $${receiver}.clone();'';
|
||||||
|
description = "clone a variable into a new binding";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
"let $x = $x.into()" = {
|
||||||
|
postfix = [ "into" ];
|
||||||
|
body = ''let $${receiver} = $${receiver}.clone();'';
|
||||||
|
description = "call into() and create a new binding";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
"assert_eq!($x, .. );" = {
|
||||||
|
postfix = [ "asseq" ];
|
||||||
|
body = ''assert_eq!($${receiver}, );'';
|
||||||
|
description = "create an assertion for the expression";
|
||||||
|
scope = "expr";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
procMacro = { enable = true; attributes.enable = true; };
|
||||||
|
serverPath = addSDK {
|
||||||
|
name = "rust-env";
|
||||||
|
lsp = "${rust-analyzer}/bin/rust-analyzer";
|
||||||
|
sdk = [ rust-sdk ];
|
||||||
|
};
|
||||||
|
imports.group.enable = true;
|
||||||
|
# inlayHints = {
|
||||||
|
# closureReturnTypeHints.enable = false;
|
||||||
|
# };
|
||||||
|
highlightRelated = {
|
||||||
|
yieldPoints.enable = true;
|
||||||
|
references.enable = true;
|
||||||
|
exitPoints.enable = true;
|
||||||
|
breakPoints.enable = true;
|
||||||
|
};
|
||||||
|
checkOnSave = {
|
||||||
|
#https://github.com/rust-lang/rust-clippy/issues/9560
|
||||||
|
enable = false;
|
||||||
|
allFeatures = true;
|
||||||
|
command = "clippy";
|
||||||
|
# extraArgs = [ "--message-format=json" ];
|
||||||
|
};
|
||||||
|
diagnostics = {
|
||||||
|
enable = true;
|
||||||
|
experimental.enable = true;
|
||||||
|
};
|
||||||
|
files.excludeDirs = [ "result" "target" ];
|
||||||
|
extraEnv = {
|
||||||
|
RA_LOG = "debug";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
languageserver = {
|
||||||
|
ccls = {
|
||||||
|
command = preferProjectEnv "ccls" "${pkgs.ccls}/bin/ccls";
|
||||||
|
filetypes = [ "c" "cc" "cpp" "c++" "objc" "objcpp" ];
|
||||||
|
rootPatterns = [ ".ccls" "compile_commands.json" ".git/" ".hg/" ];
|
||||||
|
initializationOptions = {
|
||||||
|
cache = {
|
||||||
|
directory = "${config.xdg.cacheHome}/ccls";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
clang.extraOptions = [ "-std=c++20" ];
|
||||||
|
};
|
||||||
|
nix = {
|
||||||
|
command = "${pkgs.nil}/bin/nil";
|
||||||
|
rootPatterns = [ "flake.nix" ];
|
||||||
|
filetypes = [ "nix" ];
|
||||||
|
};
|
||||||
|
diagnostic-languageserver = {
|
||||||
|
filetypes = {
|
||||||
|
sh = [ "${pkgs.shellcheck}/bin/shellcheck" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
cSpell = { diagnosticLevel = "hint"; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
home.sessionVariables = rec {
|
||||||
|
EDITOR = "nvim";
|
||||||
|
VISUAL_EDITOR = EDITOR;
|
||||||
|
};
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user