feat(nvim): conf in extra file

This commit is contained in:
u2515h 2023-12-17 12:55:51 +01:00
parent d00bf0d21c
commit 36ef92f9c6
3 changed files with 230 additions and 226 deletions

View File

@ -69,231 +69,15 @@ in
oil-nvim oil-nvim
distant-nvim distant-nvim
]; ];
extraConfig = let pkgBin = pkg: "${pkgs.${pkg}}/bin/${pkg}"; in extraLuaConfig = let paths = {
'' lldb = pkgs.lldb;
let mapleader = "," rust_analyzer = rust-analyzer;
};
confDir = lib.sourceFilesBySuffices ./. [ "lua" "vim" ] ;
set hidden in with lib; ''
vim.cmd [[source ${confDir}/init.vim]]
" disable mouse ${concatStringsSep "\n" (mapAttrsToList (name: path: ''${name}_path = "${path}"'') paths)}
set mouse= dofile("${confDir}/init.lua")
" 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" ]; programs.git.ignores = [ ".nvim_session" ];
@ -333,7 +117,7 @@ in
autoimport.enable = true; autoimport.enable = true;
privateEditable.enable = true; privateEditable.enable = true;
fullFunctionSignatures.enable = true; # https://github.com/rust-lang/rust-analyzer/pull/15582 fullFunctionSignatures.enable = true; # https://github.com/rust-lang/rust-analyzer/pull/15582
snippets = rec { snippets = {
"return Err(..)" = { "return Err(..)" = {
postfix = [ "reterr" ]; postfix = [ "reterr" ];
body = ''return Err($${receiver});''; body = ''return Err($${receiver});'';

108
init.lua Normal file
View File

@ -0,0 +1,108 @@
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 = lldb_path .. "/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

112
init.vim Normal file
View File

@ -0,0 +1,112 @@
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