-- local bufnr = vim.api.nvim_get_current_buf() -- Packer {{{ -- Install packer local ensure_packer = function() local fn = vim.fn local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) vim.cmd [[packadd packer.nvim]] return true end return false end local packer_bootstrap = ensure_packer() require('packer').startup(function(use) -- Packer can manage itself use 'wbthomason/packer.nvim' -- UI use { "catppuccin/nvim", as = "catppuccin" } -- Theme use { 'akinsho/bufferline.nvim', requires = 'kyazdani42/nvim-web-devicons', config = function() require("bufferline").setup{} end } -- Top line use { 'nvim-lualine/lualine.nvim', requires = {'kyazdani42/nvim-web-devicons', opt = true}, } -- Bottom line use { 'folke/noice.nvim', requires = { 'MunifTanjim/nui.nvim', -- 'rcarriga/nvim-notify' -- laisser fidget s'en occuper } } -- replaces the UI for messages, cmdline and the popupmenu. use 'yggdroot/indentline' -- Display vertical lines at each indentation -- use 'junegunn/goyo.vim' -- Distraction-free writing in Vim -- use 'xiyaowong/nvim-transparent' -- Treesitter use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate', } use 'nvim-treesitter/nvim-treesitter-refactor' -- refactoring / renaming use 'romgrk/nvim-treesitter-context' -- maintient les entêtes des fonctions pour avoir le contexte d'où on se trouve -- LSP use {'neovim/nvim-lspconfig'} -- use {'williamboman/mason.nvim', tag = "stable" } use {'williamboman/mason.nvim'} use {'williamboman/mason-lspconfig.nvim'} use {'j-hui/fidget.nvim', tag = "v1.4.*", config = function() require('fidget').setup() end } -- Visualisation du status du LSP use 'onsails/lspkind.nvim' -- This tiny plugin adds vscode-like pictograms to neovim built-in lsp -- Autocompletion use { "hrsh7th/nvim-cmp", requires = { "hrsh7th/cmp-buffer", "hrsh7th/cmp-nvim-lsp", 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', 'saadparwaiz1/cmp_luasnip' } } -- Snippets use {"L3MON4D3/LuaSnip", tag = "v2.*", run = "make install_jsregexp"} use "rafamadriz/friendly-snippets" -- Debugger use { 'rcarriga/nvim-dap-ui',-- Debug Adapter UI requires = { {'mfussenegger/nvim-dap', 'nvim-neotest/nvim-nio', 'theHamsta/nvim-dap-virtual-text'},-- Debug Adapter Protocol } } -- use 'puremourning/vimspector' -- Search and move use 'justinmk/vim-sneak' use {'ThePrimeagen/harpoon', config = function() require("harpoon").setup({}) end } use { 'nvim-telescope/telescope.nvim', requires = { {'nvim-lua/plenary.nvim'},-- LUA framework {'nvim-treesitter/nvim-treesitter'}, }, } use 'romainl/vim-cool' -- Toggle search highlighting -- Highlight use 'cespare/vim-toml' use 'mboughaba/i3config.vim' -- i3config highlight use 'f3fora/cmp-spell' -- add spell support into cmp -- use 'pearofducks/ansible-vim' -- Ansible highlight -- Database -- use {'tpope/vim-dadbod', -- requires = { -- 'kristijanhusak/vim-dadbod-ui', -- 'kristijanhusak/vim-dadbod-completion' -- } -- } -- development use {"mrcjkb/rustaceanvim", tag = "4.*" } -- use "lvimuser/lsp-inlayhints.nvim" -- will be added in version 10 of neovim use {'folke/neodev.nvim', -- Additional lua configuration, makes nvim stuff amazing config = function() require('neodev').setup() end } use { "folke/trouble.nvim", requires = "kyazdani42/nvim-web-devicons", } -- A pretty list for showing diagnostics, references, telescope results, quickfix and location lists to help you solve all the trouble your code is causing. -- confort use 'farmergreg/vim-lastplace' -- plugin that intelligently reopens files at your last edit position. use { 'folke/which-key.nvim', config = function() require("which-key").setup {} end } use 'tpope/vim-commentary' use 'junegunn/vim-easy-align' use 'tpope/vim-surround' use { "windwp/nvim-autopairs", } -- Others use { 'norcalli/nvim-colorizer.lua' } -- Fast color highlighter -- Automatically set up your configuration after cloning packer.nvim -- Put this at the end after all plugins if packer_bootstrap then require('packer').sync() end end) -- -- Automatically source and re-compile packer whenever you save this init.lua -- local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true }) -- vim.api.nvim_create_autocmd('BufWritePost', { -- command = 'source | silent! LspStop | silent! LspStart | PackerCompile', -- group = packer_group, -- pattern = vim.fn.expand '$MYVIMRC', -- }) -- }}} -- local execute = vim.api.nvim_command vim.g.mapleader = ' ' -- Opt {{{ vim.opt.belloff = 'all' -- never ring the bell for any reason vim.opt.completeopt = 'menuone' -- show menu even if there is only one candidate (for nvim-compe) vim.opt.completeopt = vim.opt.completeopt + 'noselect' -- don't automatically select canditate (for nvim-compe) vim.opt.expandtab = true -- always use spaces instead of tabs vim.opt.foldenable = true -- enable folding, za for toggling vim.opt.foldmethod = "marker" -- choose marker method other : manual indent expr syntax diff marker vim.opt.foldlevel = 99 vim.opt.inccommand = 'split' -- live preview of :s results vim.opt.listchars = { tab='▷⋯', eol='↲', nbsp='␣', space='•', trail='•', extends='»', precedes='«' } vim.opt.modelines = 5 -- scan this many lines looking for modeline vim.opt.relativenumber = true -- show relative numbers in gutter vim.opt.scrolloff = 999 -- Make sure that cursor is always vertically centered on j/k moves vim.opt.shada = "'20,<1000,s100,:0,/20,%,n~/.cache/shada" -- ' - Specify the maximum number of marked files remembered. It also saves the jump list and the change list we saw in a previous article. -- < - Specify the maximum of lines saved for each register. All the lines are saved if this is not included. If you don’t want to save your registers, use the value <0. -- / and : - Number of search patterns and entries from the command-line history saved. The option history is used if it’s not specified. -- % - Save and restore the buffer list. You can specify the maximum number of buffer stored with a number. -- s - Specify the maximum size of an item’s content in KiB (kilobyte). -- For the viminfo file, it only applies to register. -- For the shada file, it applies to all items except for the buffer list and header. vim.opt.shiftwidth = 2 -- spaces per tab vim.opt.shiftround = true -- Round indent to multiple of 'shiftwidth' for > and < commands vim.opt.smartindent = true -- don't create swap files vim.opt.swapfile = false -- don't create swap files vim.opt.tabstop = 2 -- spaces per tab vim.opt.undodir = vim.fn.expand('~').."/.cache/nvim/undodir/" -- keep undo files out of the way vim.opt.undofile = true -- actually use undo files -- vim.opt.updatetime = 350 -- Reduce time for highlighting other references vim.opt.redrawtime = 10000 -- Allow more time for loading syntax on large files vim.opt.clipboard = "unnamedplus" -- Put those yanks in my os clipboards vim.opt.ignorecase = true -- Ignore la casse lors d'une recherche vim.opt.smartcase = true -- Sauf si une recherche contient une majuscule vim.opt.hidden = true -- Changing buffer without saving -- Obligatoire pour cmp-spell vim.opt.spell = true -- à ne pas activer de base pour éviter les parasites avec les fichiers de code vim.opt.spelllang = { 'fr', 'en_us' } vim.opt.spellsuggest = { 'best',9 } vim.opt.mouse = '' vim.g.CoolTotalMatches = 1 -- vim-cool : Show numbers of matches -- vim.opt.shortmess+=c -- }}} -- Scheme + UI + Highlight {{{ vim.opt.termguicolors = true -- Truecolor vim.g.catppuccin_flavour = "mocha" -- latte, frappe, macchiato, mocha vim.cmd[[colorscheme catppuccin]] vim.g.loaded_perl_provider = 0 vim.g.loaded_ruby_provider = 0 vim.lsp.inlay_hint.enable(true) require("lualine").setup({ options = { theme = 'catppuccin' } }) vim.cmd(([[ au BufRead,BufNewFile *.playbook set filetype=yaml.ansible ]])) --- }}} -- General keybinds {{{ local map = vim.api.nvim_set_keymap map('n', ',', 'A,', {noremap = true}) -- Easy insertion of a trailing ; or , from insert mode map('n', ';', 'A;', {noremap = true}) -- Easy insertion of a trailing ; or , from insert mode map('n', 'w', ':w!', {noremap = true}) map('i', 'mw', '`^:w', {noremap = true}) -- map('i', 'mwq', ':wq!', {noremap = true}) map('i', 'kj', '`^', {noremap = true}) map('n', 'Q', '', {noremap = true}) map('v', 'p', ':"_dP', {noremap = true}) local opts = { noremap=true, silent=true } map('n', '', 'lua vim.lsp.buf.code_action()', opts) map('n', 'R', 'lua vim.lsp.buf.rename()', opts) map('n', 'db', ':DB mysql://root:ntz-mdb2uch2nvc7DVW@web2.enim.univ-lorraine.fr/concours', {noremap = true}) map('n', 'y', '"+y', {noremap = true}) map('n', 'pwd', ':lua vim.fn.setreg("+",vim.fn.system("pwd"):gsub("$","").."/"..vim.fn.getreg("%"))', {noremap = true}) map('n', ']', "mao`a", {noremap = true}) -- ma: set cursor mark, `a jump to position (line and column) map('n', '[', "maO`a", {noremap = true}) map('n', '', 'zz', {noremap = true}) map('n', '', 'zz', {noremap = true}) -- map('n', 'n', 'nzzzc', {noremap = true}) -- map('n', 'N', 'Nzzzc', {noremap = true}) -- }}} -- Plugin keybind {{{ map('n', 'ga', '(EasyAlign)', {noremap = true}) -- Easy insertion of a trailing ; or , from insert mode map('i', '', "lua require'luasnip'.jump(1)", {noremap = true}) map('i', '', "lua require'luasnip'.jump(-1)", {noremap = true}) map('n', 'hm', ':lua require("harpoon.ui").toggle_quick_menu()', {noremap = true}) map('n', 'ha', ':lua require("harpoon.mark").add_file()', {noremap = true}) map('n', '', ':lua require("harpoon.ui").nav_next()', {noremap = true}) map('i', '', 'copilot#Accept("")', {noremap = true, silent = true, expr = true}) -- vim.g.copilot_no_tab_map = true -- vim.g.copilot_assume_mapped = true -- https://www.reddit.com/r/neovim/comments/sk70rk/using_github_copilot_in_neovim_tab_map_has_been/ map('n', 'ra', "lua vim.cmd.RustLsp('codeAction')",{ silent = true}) -- }}} -- Lsp {{{ require('mason').setup() -- https://github.com/williamboman/mason.nvim -- https://github.com/williamboman/mason-lspconfig.nvim require('mason-lspconfig').setup({ ensure_installed = { 'html', 'cssls', 'lua_ls', 'marksman', 'sqlls', 'jinja_lsp' }, -- 'rust_analyzer', -- non compatible avec rustaceanvim : https://github.com/mrcjkb/rustaceanvim/blob/master/doc/mason.txt }) require('lspconfig').marksman.setup({}) require('lspconfig').html.setup({ filetypes = { "html", "htmldjango" } }) require('lspconfig').lua_ls.setup({ settings = { -- for suppressing warning: undefined global `vim`? Lua = { diagnostics = { -- Get the language server to recognize the `vim` global globals = {'vim'}, }, }, }, }) local cmp = require('cmp') -- require('lsp-zero').cmp_action() local cmp_select = {behavior = cmp.SelectBehavior.Select} local luasnip = require("luasnip") cmp.setup({ sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'marksman' }, { name = 'buffer' }, { name = 'path' } }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ -- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.locally_jumpable(1) then luasnip.jump(1) else fallback() end end, { "i", "s" }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.locally_jumpable(-1) then luasnip.jump(-1) else fallback() end end, { "i", "s" }), [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), [''] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true, }) }), snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, }) -- `/` cmdline setup. cmp.setup.cmdline('/', { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } } }) }) -- lsp.setup() -- }}} -- vim.cmd(([[ let g:sneak#s_next = 1 ]])) -- Telescope {{{ -- https://github.com/nvim-telescope/telescope.nvim map('n', '', 'Telescope find_files', {noremap = true}) -- Telescope map('n', '', 'Telescope buffers', {noremap = true}) -- Telescope map('n', '', 'Telescope live_grep', {noremap = true}) -- Telescope -- }}} require'nvim-treesitter.configs'.setup { ensure_installed = { "html", "bash", "dockerfile", "rust" , "css" , "markdown", "markdown_inline", "sql", "hyprlang", "nix", "vimdoc", "lua", "regex"}, highlight = { enable = true, additional_vim_regex_highlighting = { "markdown" }, }, indent = { enable = true, }, autotag = { enable = true, }, refactor = { smart_rename = { enable = true, keymaps = { smart_rename = "grr", }, }, }, } require("trouble").setup({ auto_open = true, -- automatically open the list when you have diagnostics auto_close = true, -- automatically close the list when you have no diagnostics }) -- Source : https://alpha2phi.medium.com/neovim-for-beginners-fuzzy-file-search-part-2-2aab95fe8cfe -- Custom actions local transform_mod = require("telescope.actions.mt").transform_mod local nvb_actions = transform_mod { file_path = function(prompt_bufnr) -- Get selected entry and the file full path local content = require("telescope.actions.state").get_selected_entry() -- local full_path = content.cwd .. require("plenary.path").path.sep .. content.value local relative_path = "." .. require("plenary.path").path.sep .. content.value vim.schedule(function() -- local x = vim.api.nvim_win_get_cursor(vim.api.nvim_get_current_win())[1] - 1 -- local y = vim.api.nvim_win_get_cursor(vim.api.nvim_get_current_win())[2] local x,y = table.unpack(vim.api.nvim_win_get_cursor(0)) vim.api.nvim_buf_set_text(0,x-1,y,x-1,y, {"[](" .. relative_path .. ")"}) end) -- Close the popup require("telescope.actions").close(prompt_bufnr) end, } require('telescope').setup{ defaults = { -- https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/mappings.lua mappings = { i = { [""] = require('telescope.actions').move_selection_next, [""] = require('telescope.actions').move_selection_previous, [""] = require('telescope.actions').close, }, }, }, pickers = { find_files = { -- theme = "ivy", -- `hidden = true` will still show the inside of `.git/` as it's not `.gitignore`d. find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" }, mappings = { n = { ["y"] = nvb_actions.file_path, }, i = { [""] = nvb_actions.file_path, }, }, }, } } require('telescope').load_extension("noice") -- Luasnip {{{ -- load friendly snippet require('luasnip.loaders.from_vscode').lazy_load() local snippet = luasnip.snippet local text = luasnip.text_node local insert = luasnip.insert_node local func = luasnip.function_node require'luasnip'.filetype_extend("htmldjango", {"html"}) luasnip.setup({}) -- Functions {{{ local date = function() return {os.date('%Y-%m-%d')} end local filename = function() return debug.getinfo(1, 'S').source end -- }}} -- Zola {{{ luasnip.add_snippets("markdown", { snippet("zh", { text("+++"), text("title = \""), func (filename, {}), text("\""), text("slug = \""), func (filename, {}), text("\""), text("date = "), func(date, {}), text("updated = "), func(date, {}), text("[taxonomies]"), text("tags = []"), text("+++") }), snippet("zi", { text("{{ image_fit(path=\"@/images/"), insert(1,"image_filename"), text("\") }}") }), snippet("z2i", { text("{{ image_fit(path1=\"@/images/"), insert(1,"image_filename"), text("\", path2=\"@/images/"), insert(2,"image_filename"), text("\") }}"), }), snippet("zyt", { text("{{ yt(id=\""), insert(1,"youtube_filename"), text("\") }}") }), snippet("histoire", { text( { "## Focalisation", "- 1ère personne/3ème personne", "- externe/interne/omniscient", "## Narrateur", "- objectif/subjectif", "- relate honnêtement/partis pris dissimulé", "## Quelle temporalité", "- aujourd'hui/historique/futuriste", "- ailleurs/voyage temporel/fragmentaire", }), }), snippet("character", { text( { "- 3 traits psy : ", "- 3 traits physiques : ", "- 1 ou 2 motivation : ", "- habilité spéciale", }), }), }) -- }}} -- }}} require("noice").setup({ lsp = { -- override markdown rendering so that **cmp** and other plugins use **Treesitter** override = { ["vim.lsp.util.convert_input_to_markdown_lines"] = true, ["vim.lsp.util.stylize_markdown"] = true, ["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp }, }, -- you can enable a preset for easier configuration presets = { bottom_search = false, -- use a classic bottom cmdline for search command_palette = true, -- position the cmdline and popupmenu together long_message_to_split = true, -- long messages will be sent to a split inc_rename = false, -- enables an input dialog for inc-rename.nvim lsp_doc_border = false, -- add a border to hover docs and signature help }, }) vim.o.autoread = true vim.g.indentLine_conceallevel = 0 -- pose trop de problème avec le markdown et le json vim.filetype.add({ pattern = { [".*/hypr/.*%.conf"] = "hyprlang" }, }) require'colorizer'.setup() require("nvim-autopairs").setup {} -- ne semble pas pouvoir être intégré dans le use local dap, dapui = require("dap"), require("dapui") dapui.setup() require("nvim-dap-virtual-text").setup() dap.adapters.rustlldb = { type = "executable", -- command = "/usr/bin/lldb-vscode", -- adjust as needed command = vim.fn.expand('~').."/.cargo/bin/rust-lldb", -- adjust as needed name = "rustlldb", } dap.listeners.before.attach.dapui_config = function() dapui.open() vim.opt.mouse = 'n' end dap.listeners.before.launch.dapui_config = function() dapui.open() vim.opt.mouse = 'n' end dap.listeners.before.event_terminated.dapui_config = function() dapui.close() vim.opt.mouse = '' end dap.listeners.before.event_exited.dapui_config = function() dapui.close() vim.opt.mouse = '' end vim.keymap.set('n', '', require 'dap'.continue) vim.keymap.set('n', '', require 'dap'.step_over) vim.keymap.set('n', '', require 'dap'.step_into) vim.keymap.set('n', '', require 'dap'.step_out) vim.keymap.set('n', 'b', require 'dap'.toggle_breakpoint) vim.keymap.set('n', 'e', require 'dapui'.eval) vim.fn.sign_define('DapBreakpoint',{ text ='🟥', texthl ='', linehl ='', numhl =''}) vim.fn.sign_define('DapStopped',{ text ='▶️', texthl ='', linehl ='', numhl =''})