neovim additions
This commit is contained in:
parent
315e988734
commit
409f13a1db
25 changed files with 242 additions and 86 deletions
|
|
@ -1,48 +1,51 @@
|
|||
-- (.config/nvim/lua/neoconf/autocmd.lua)
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
callback = function()
|
||||
vim.lsp.buf.format({ async = false })
|
||||
end,
|
||||
})
|
||||
|
||||
local function run_curr_python_file()
|
||||
-- Get file name in the current buffer
|
||||
local file_name = vim.api.nvim_buf_get_name(0)
|
||||
-- Get file name in the current buffer
|
||||
local file_name = vim.api.nvim_buf_get_name(0)
|
||||
|
||||
-- Get terminal codes for running python file
|
||||
-- ("i" to enter insert before typing rest of the command)
|
||||
local py_cmd = vim.api.nvim_replace_termcodes('ipython "' .. file_name .. '"<cr>', true, false, true)
|
||||
-- Get terminal codes for running python file
|
||||
-- ("i" to enter insert before typing rest of the command)
|
||||
local py_cmd = vim.api.nvim_replace_termcodes('ipython "' .. file_name .. '"<cr>', true, false, true)
|
||||
|
||||
-- Determine terminal window split and launch terminal
|
||||
local percent_of_win = 0.4
|
||||
local curr_win_height = vim.api.nvim_win_get_height(0) -- Current window height
|
||||
local term_height = math.floor(curr_win_height * percent_of_win) -- Terminal height
|
||||
vim.cmd(":below " .. term_height .. "split | term") -- Launch terminal (horizontal split)
|
||||
-- Determine terminal window split and launch terminal
|
||||
local percent_of_win = 0.4
|
||||
local curr_win_height = vim.api.nvim_win_get_height(0) -- Current window height
|
||||
local term_height = math.floor(curr_win_height * percent_of_win) -- Terminal height
|
||||
vim.cmd(":below " .. term_height .. "split | term") -- Launch terminal (horizontal split)
|
||||
|
||||
-- Press keys to run python command on current file
|
||||
vim.api.nvim_feedkeys(py_cmd, "t", false)
|
||||
-- Press keys to run python command on current file
|
||||
vim.api.nvim_feedkeys(py_cmd, "t", false)
|
||||
end
|
||||
|
||||
vim.keymap.set({ "n" }, "<A-r>", "", {
|
||||
desc = "Run .py file via Neovim built-in terminal",
|
||||
callback = run_curr_python_file,
|
||||
desc = "Run .py file via Neovim built-in terminal",
|
||||
callback = run_curr_python_file,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "markdown", "rmd" },
|
||||
callback = function()
|
||||
-- Force syntaxe markdown
|
||||
vim.bo.syntax = "markdown"
|
||||
-- Conceal normal pour markdown
|
||||
vim.wo.conceallevel = 2
|
||||
-- Désactive vimtex pour ces fichiers
|
||||
vim.b.vimtex_syntax_enabled = 0
|
||||
end,
|
||||
pattern = { "markdown", "rmd" },
|
||||
callback = function()
|
||||
-- Force syntaxe markdown
|
||||
vim.bo.syntax = "markdown"
|
||||
-- Conceal normal pour markdown
|
||||
vim.wo.conceallevel = 2
|
||||
-- Désactive vimtex pour ces fichiers
|
||||
vim.b.vimtex_syntax_enabled = 0
|
||||
-- spellcheck
|
||||
vim.wo.spell = true
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
pcall(vim.treesitter.start)
|
||||
local ok = pcall(vim.treesitter.start)
|
||||
if ok then
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
end
|
||||
end,
|
||||
})
|
||||
-- active spell sur .tex
|
||||
vim.api.nvim_create_autocmd("FileType", { pattern = "tex", callback = function() vim.wo.spell = true end })
|
||||
|
||||
vim.api.nvim_create_autocmd("TextYankPost", { callback = function() vim.highlight.on_yank() end })
|
||||
|
|
|
|||
|
|
@ -1,14 +1,48 @@
|
|||
-- diagnostic
|
||||
vim.diagnostic.config({
|
||||
virtual_text = {
|
||||
prefix = "●", -- Icône avant le message
|
||||
source = "if_many", -- Affiche la source LSP si plusieurs
|
||||
format = function(diag)
|
||||
return string.format("%s: %s", diag.source, diag.message)
|
||||
end,
|
||||
},
|
||||
signs = true,
|
||||
underline = true,
|
||||
update_in_insert = false, -- Évite flicker en insert
|
||||
severity_sort = true,
|
||||
virtual_text = {
|
||||
prefix = "●",
|
||||
source = "if_many",
|
||||
format = function(diag)
|
||||
return string.format("%s: %s", diag.source, diag.message)
|
||||
end,
|
||||
},
|
||||
signs = true,
|
||||
underline = true,
|
||||
update_in_insert = false,
|
||||
severity_sort = true,
|
||||
})
|
||||
|
||||
vim.keymap.set("n", "[d", function()
|
||||
vim.diagnostic.jump({ count = -1, float = true })
|
||||
end, { desc = "Previous diagnostic" })
|
||||
vim.keymap.set("n", "]d", function()
|
||||
vim.diagnostic.jump({ count = 1, float = true })
|
||||
end, { desc = "Next diagnostic" })
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
desc = "Configure LSP keymaps on attach",
|
||||
callback = function(event)
|
||||
local map = function(keys, func, desc)
|
||||
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
|
||||
end
|
||||
|
||||
map("gd", vim.lsp.buf.definition, "Goto Definition")
|
||||
map("gD", vim.lsp.buf.declaration, "Goto Declaration")
|
||||
map("gr", vim.lsp.buf.references, "Goto References")
|
||||
map("gI", vim.lsp.buf.implementation, "Goto Implementation")
|
||||
map("K", vim.lsp.buf.hover, "Hover Documentation")
|
||||
map("<leader>rn", vim.lsp.buf.rename, "Rename")
|
||||
map("<leader>ca", vim.lsp.buf.code_action, "Code Action")
|
||||
map("<leader>ds", vim.lsp.buf.document_symbol, "Document Symbols")
|
||||
|
||||
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
||||
if client and client:supports_method("textDocument/inlayHint") then
|
||||
vim.lsp.inlay_hint.enable(true, { bufnr = event.buf })
|
||||
map("<leader>th", function()
|
||||
local enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })
|
||||
vim.lsp.inlay_hint.enable(not enabled, { bufnr = event.buf })
|
||||
end, "Toggle Inlay Hints")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -25,36 +25,35 @@ vim.keymap.set("n", "<leader>fb", builtin.buffers, { desc = "Telescope buffers"
|
|||
vim.keymap.set("n", "<leader>fh", builtin.help_tags, { desc = "Telescope help tags" })
|
||||
-- oil
|
||||
vim.keymap.set("n", "<leader>n", "<cmd>Oil<CR>", { desc = "Launch oil buffer" })
|
||||
-- python
|
||||
vim.keymap.set("n", "<F5>", ":w<CR>:!python3 %<CR>", { noremap = true, silent = false })
|
||||
|
||||
vim.keymap.set("n", "-", "<cmd>Oil<CR>", { desc = "Open parent directory" })
|
||||
-- spell checker from fr to en
|
||||
vim.keymap.set("n", "<leader>sf", function()
|
||||
if vim.o.spelllang == "fr" then
|
||||
vim.o.spelllang = "en"
|
||||
else
|
||||
vim.o.spelllang = "fr"
|
||||
end
|
||||
vim.o.spell = true
|
||||
print("Spelllang: " .. vim.o.spelllang)
|
||||
if vim.o.spelllang == "fr" then
|
||||
vim.o.spelllang = "en"
|
||||
else
|
||||
vim.o.spelllang = "fr"
|
||||
end
|
||||
vim.o.spell = true
|
||||
print("Spelllang: " .. vim.o.spelllang)
|
||||
end, { desc = "Toggle spelllang FR/EN" })
|
||||
-- toggle correction
|
||||
vim.keymap.set("n", "<leader>sg", function()
|
||||
vim.wo.spell = not vim.wo.spell
|
||||
vim.notify("Spell: " .. (vim.wo.spell and "ON" or "OFF"), vim.log.levels.INFO)
|
||||
vim.wo.spell = not vim.wo.spell
|
||||
vim.notify("Spell: " .. (vim.wo.spell and "ON" or "OFF"), vim.log.levels.INFO)
|
||||
end, { desc = "Toggle spell check" })
|
||||
|
||||
vim.api.nvim_create_user_command("OctaveRun", function()
|
||||
vim.cmd("write")
|
||||
vim.cmd('!octave -qf "%:p"')
|
||||
vim.cmd("write")
|
||||
vim.cmd('!octave -qf "%:p"')
|
||||
end, {})
|
||||
vim.keymap.set("n", "<leader>ro", "<cmd>OctaveRun<CR>", { desc = "Run current Octave/Matlab file" })
|
||||
|
||||
-- set vimtex main to current file
|
||||
local function vimtex_set_main()
|
||||
vim.b.vimtex_main = vim.fn.expand("%:p")
|
||||
vim.b.vimtex = nil
|
||||
vim.fn["vimtex#init"]()
|
||||
print("VimTeX main → " .. vim.b.vimtex_main)
|
||||
vim.b.vimtex_main = vim.fn.expand("%:p")
|
||||
vim.b.vimtex = nil
|
||||
vim.fn["vimtex#init"]()
|
||||
print("VimTeX main → " .. vim.b.vimtex_main)
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>lm", vimtex_set_main, { desc = "VimTeX: set main to current file" })
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ vim.o.relativenumber = true
|
|||
vim.o.showmode = true
|
||||
-- sync clipboard
|
||||
vim.schedule(function()
|
||||
vim.o.clipboard = "unnamedplus"
|
||||
vim.o.clipboard = "unnamedplus"
|
||||
end)
|
||||
-- enable break indent
|
||||
vim.o.breakindent = true
|
||||
-- indent options
|
||||
vim.o.autoindent = true
|
||||
vim.o.smartindent = true
|
||||
-- vim.o.smartindent = true
|
||||
vim.o.expandtab = true
|
||||
-- save undo history
|
||||
vim.o.undofile = true
|
||||
|
|
@ -39,8 +39,15 @@ vim.o.scrolloff = 10
|
|||
-- confirm save/confirm
|
||||
vim.o.confirm = true
|
||||
-- spell checking
|
||||
vim.opt.spell = true
|
||||
-- vim.opt.spell = true
|
||||
vim.opt.spelllang = "fr"
|
||||
-- wrap
|
||||
vim.o.wrap = true
|
||||
vim.o.linebreak = true
|
||||
-- indent
|
||||
vim.o.shiftwidth = 4
|
||||
vim.o.tabstop = 4
|
||||
vim.o.softtabstop = 4
|
||||
-- timers
|
||||
vim.o.updatetime = 250
|
||||
vim.o.timeoutlen = 300
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue