This commit is contained in:
2025-08-29 23:21:21 +02:00
parent 20a49c3f58
commit e46f58fd20
14 changed files with 219 additions and 152 deletions

View File

@@ -1,4 +1,4 @@
-- Buffer group mappings -- buffer group mappings
-- --
local status_wk, wk = pcall(require, 'which-key') local status_wk, wk = pcall(require, 'which-key')

View File

@@ -1,6 +1,6 @@
-- Edition mappings -- edition mappings
--
-- --
local status_kh, kh = pcall(require, 'custom.plugins.keymaps-helper') local status_kh, kh = pcall(require, 'custom.plugins.keymaps-helper')
if not status_kh then if not status_kh then
return return
@@ -8,18 +8,5 @@ end
kh.map({ 'n', 'v', 'i' }, '<C-z>', '<CMD>undo<CR>', { silent = true, noremap = true, desc = 'Undo' }) kh.map({ 'n', 'v', 'i' }, '<C-z>', '<CMD>undo<CR>', { silent = true, noremap = true, desc = 'Undo' })
-- local status_wk, wk = pcall(require, 'which-key')
-- if not status_wk then
-- return
-- end
--
-- wk.add {
-- {
-- mode = { 'n', 'v', 'i' },
-- -- mapping runs here as which-key intercepts ctrl-z signal before term
-- { '<C-z>', '<CMD>undo<CR>', desc = 'Undo', silent = true, noremap = true, hidden = true },
-- },
-- }
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et

View File

@@ -1,4 +1,4 @@
-- Neo-tree mappings -- file explorer mappings
-- --
local status_wk, wk = pcall(require, 'which-key') local status_wk, wk = pcall(require, 'which-key')

View File

@@ -1,4 +1,4 @@
-- General mappings -- general mappings
-- --
local status_kh, kh = pcall(require, 'custom.plugins.keymaps-helper') local status_kh, kh = pcall(require, 'custom.plugins.keymaps-helper')

View File

@@ -1,4 +1,4 @@
-- Key mappings groups -- key mappings groups
-- --
local status_wk, wk = pcall(require, 'which-key') local status_wk, wk = pcall(require, 'which-key')
@@ -12,6 +12,7 @@ wk.add {
mode = { 'n' }, mode = { 'n' },
{ '<leader>s', group = '[s]earch' }, { '<leader>s', group = '[s]earch' },
{ '<leader>t', group = '[t]oggles' }, { '<leader>t', group = '[t]oggles' },
{ '<leader>T', group = '[T]erminal' },
}, },
{ {

View File

@@ -5,11 +5,12 @@ require 'custom.keymaps.nop'
require 'custom.keymaps.groups' require 'custom.keymaps.groups'
require 'custom.keymaps.general' require 'custom.keymaps.general'
require 'custom.keymaps.buffers' require 'custom.keymaps.buffers'
require 'custom.keymaps.files' require 'custom.keymaps.explore'
require 'custom.keymaps.edit' require 'custom.keymaps.edit'
require 'custom.keymaps.search' require 'custom.keymaps.search'
require 'custom.keymaps.toggles' require 'custom.keymaps.toggles'
require 'custom.keymaps.obsidian' require 'custom.keymaps.obsidian'
require 'custom.keymaps.terminal'
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et

View File

@@ -1,4 +1,4 @@
-- Deactivated key mappings -- deactivated key mappings
-- --
local status_wk, wk = pcall(require, 'which-key') local status_wk, wk = pcall(require, 'which-key')

View File

@@ -1,4 +1,4 @@
-- Obsidian mappings -- obsidian mappings
-- --
local status_wk, wk = pcall(require, 'which-key') local status_wk, wk = pcall(require, 'which-key')

View File

@@ -1,4 +1,4 @@
-- Search group mappings -- search group mappings
-- --
local wk = require 'which-key' local wk = require 'which-key'

View File

@@ -0,0 +1,26 @@
-- terminal mappings
--
local status_wk, wk = pcall(require, 'which-key')
if not status_wk then
return
end
local status_th, th = pcall(require, 'custom.plugins.term-helper')
if not status_th then
return
end
wk.add {
{
mode = { 'n', 'v', 'i' },
{ '<leader>Ti', th.new_terminal_ipython, desc = 'new [i]python terminal', silent = true, noremap = true },
{ '<leader>Tj', th.new_terminal_julia, desc = 'new [j]ulia terminal', silent = true, noremap = true },
{ '<leader>Ts', th.new_terminal_shell, desc = 'new terminal with [s]hell', silent = true, noremap = true },
{ '<leader>Tp', th.new_terminal_python, desc = 'new [p]ython terminal', silent = true, noremap = true },
{ '<leader>TR', th.new_terminal_r, desc = 'new [R] terminal', silent = true, noremap = true },
},
}
-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et

View File

@@ -1,15 +1,35 @@
-- Toggles group mappings -- toggles group mappings
-- --
local wk = require 'which-key' local wk = require 'which-key'
local gitsigns = require 'gitsigns' local gitsigns = require 'gitsigns'
local function toggle_light_dark_theme()
if vim.o.background == 'light' then
vim.o.background = 'dark'
else
vim.o.background = 'light'
end
end
local function toggle_conceal()
local lvl = vim.o.conceallevel
if lvl > DefaultConcealLevel then
vim.o.conceallevel = DefaultConcealLevel
else
vim.o.conceallevel = FullConcealLevel
end
end
wk.add { wk.add {
mode = { 'n' }, mode = { 'n' },
-- gitsigns -- gitsigns
{ '<leader>tb', gitsigns.toggle_current_line_blame, desc = 'toggle git show [b]lame line' }, { '<leader>tb', gitsigns.toggle_current_line_blame, desc = 'toggle git show [b]lame line' },
{ '<leader>tD', gitsigns.preview_hunk_inline, desc = 'toggle git show [D]eleted' }, { '<leader>td', gitsigns.preview_hunk_inline, desc = 'toggle git show [d]eleted' },
{ '<leader>tm', '<CMD>RenderMarkdown buf_toggle<CR>', desc = 'toggle [m]arkdown rendering for current' }, { '<leader>tm', '<CMD>RenderMarkdown buf_toggle<CR>', desc = 'toggle [m]arkdown rendering for current' },
{ '<leader>tt', toggle_light_dark_theme, desc = 'toggle light/dark [t]heme' },
{ '<leader>tc', toggle_conceal, desc = 'toggle [c]onceal' },
{ '<leader>tz', ':setlocal spell!<cr>', desc = 'toggle [z]pellcheck' },
} }
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`

View File

@@ -1,5 +1,6 @@
-- Neo-tree helper module -- Neo-tree helper module
-- --
local M = {} local M = {}
-- Function to get confirmation input (compatible with different neo-tree versions) -- Function to get confirmation input (compatible with different neo-tree versions)
@@ -30,12 +31,12 @@ function M.smart_open()
vim.cmd('Neotree toggle reveal=false position=float dir=' .. vim.fn.expand '~') vim.cmd('Neotree toggle reveal=false position=float dir=' .. vim.fn.expand '~')
-- Si c'est un fichier réel, révéler le fichier dans l'arborescence -- Si c'est un fichier réel, révéler le fichier dans l'arborescence
elseif is_real_file and bufname ~= '' then elseif is_real_file and bufname ~= '' then
-- vim.cmd('Neotree toggle position=left reveal_force_cwd=true dir=' .. vim.fn.expand '%:p:h') vim.cmd('Neotree toggle position=left reveal_force_cwd=true dir=' .. vim.fn.expand '%:p:h')
vim.cmd 'Neotree position=left reveal_force_cwd=true' -- vim.cmd 'Neotree toggle position=left reveal_force_cwd=true'
-- Sinon, ouvrir dans le répertoire de travail courant -- Sinon, ouvrir dans le répertoire de travail courant
else else
-- vim.cmd('Neotree toggle position=left reveal_force_cwd=true dir=' .. vim.fn.getcwd()) vim.cmd('Neotree toggle position=left reveal=true dir=' .. vim.fn.getcwd())
vim.cmd 'Neotree toggle position=left reveal_force_cwd=true' -- vim.cmd 'Neotree toggle position=left reveal_force_cwd=true'
end end
end end

View File

@@ -2,140 +2,171 @@
-- from: https://github.com/jmbuhr/nvim-config -- from: https://github.com/jmbuhr/nvim-config
-- --
---@module 'utils.term' -- ---@module 'utils.term'
local M = { -- local M = {
---Map of buffers to a terminals -- ---Map of buffers to a terminals
---@type table<integer, Terminal> -- ---@type table<integer, Terminal>
buf_term_map = {}, -- buf_term_map = {},
} -- }
--
-- ---A terminal has a buffer number, a type and a channel id
-- ---@class Terminal
-- ---@field bufnr integer
-- ---@field type string?
-- ---@field channel_id integer
--
-- ---Get the channel id of a terminal buffer
-- ---@param bufnr integer
-- ---@return integer|nil
-- local function get_channel_id(bufnr)
-- return vim.api.nvim_get_option_value('channel', { buf = bufnr })
-- end
--
-- ---Get the type of the terminal buffer
-- ---like ipython, R, bash, etc.
-- ---based on the buffer name
-- ---@param buf integer
-- ---@return string|nil
-- local function get_term_type(buf)
-- local name = vim.api.nvim_buf_get_name(buf)
-- local term_type = name:match 'term://.*/%d+:(.*)'
-- if not term_type then
-- return nil
-- end
-- -- drop flags like --no-confirm-exit
-- term_type = term_type:match '([^%s]+)'
-- -- drop the path to the executable
-- term_type = term_type:match '([^/]+)$'
-- return term_type
-- end
--
-- ---Find nvim terminal buffers
-- local function list_terminals()
-- local terms = {}
-- for _, buf in ipairs(vim.api.nvim_list_bufs()) do
-- if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_get_option_value('buftype', { buf = buf }) == 'terminal' then
-- local chan_id = get_channel_id(buf)
-- if not chan_id then
-- goto continue
-- end
-- ---@type Terminal
-- local term = {
-- bufnr = buf,
-- type = get_term_type(buf),
-- channel_id = chan_id,
-- }
-- table.insert(terms, term)
-- end
-- ::continue::
-- end
-- return terms
-- end
--
-- ---For ipython sending
-- local cpaste_start = '%cpaste -q\n'
-- local cpaste_end = '--\n'
-- local cpaste_pause = 10
--
-- ---Send lines to a terminal
-- ---@param lines string[]
-- ---@param term Terminal
-- ---@return nil
-- local send_lines = function(lines, term)
-- local chan_id = term.channel_id
-- local text = table.concat(lines, '\n') .. '\n'
-- if term.type == 'ipython' then
-- vim.fn.chansend(chan_id, cpaste_start)
-- vim.uv.sleep(cpaste_pause)
-- end
-- vim.fn.chansend(chan_id, text)
-- if term.type == 'ipython' then
-- vim.fn.chansend(chan_id, cpaste_end)
-- end
-- end
--
-- local s = [[
-- print("hello world!")
-- def hello():
-- print("hello")
-- hello()
-- ]]
--
-- local ls = { s }
--
-- ---Connect current buffer to a terminal
-- local connect = function()
-- local bufnr = vim.api.nvim_get_current_buf()
-- local terms = list_terminals()
-- vim.ui.select(terms, {
-- prompt = 'Select terminal',
-- format_item = function(item)
-- return item.type .. ' ' .. item.bufnr
-- end,
-- }, function(choice)
-- if choice == nil then
-- return
-- end
-- M.buf_term_map[bufnr] = choice
-- end)
-- end
--
-- M.send = function(lines)
-- local bufnr = vim.api.nvim_get_current_buf()
-- local term = M.buf_term_map[bufnr]
-- if not term then
-- connect()
-- return
-- end
-- send_lines(lines, term)
-- -- scroll to the bottom
-- local term_win = vim.fn.bufwinid(term.bufnr)
-- local n = vim.api.nvim_buf_line_count(term.bufnr)
-- vim.api.nvim_win_set_cursor(term_win, { n, 0 })
-- end
--
-- M.send_visual = function()
-- -- get the selected text
-- vim.cmd.normal { '"zy', bang = true }
-- local selection = vim.fn.getreg 'z'
-- M.send { selection }
-- end
--
-- vim.keymap.set('v', '<CR>', function()
-- M.send_visual()
-- end, { noremap = true, silent = true })
--
-- -- connect
-- vim.keymap.set('n', '<leader>ct', function()
-- connect()
-- end, { noremap = true, silent = true })
---A terminal has a buffer number, a type and a channel id local M = {}
---@class Terminal
---@field bufnr integer
---@field type string?
---@field channel_id integer
---Get the channel id of a terminal buffer local function new_terminal(lang)
---@param bufnr integer vim.cmd('vsplit term://' .. lang)
---@return integer|nil
local function get_channel_id(bufnr)
return vim.api.nvim_get_option_value('channel', { buf = bufnr })
end end
---Get the type of the terminal buffer function M.new_terminal_python()
---like ipython, R, bash, etc. new_terminal 'python'
---based on the buffer name
---@param buf integer
---@return string|nil
local function get_term_type(buf)
local name = vim.api.nvim_buf_get_name(buf)
local term_type = name:match 'term://.*/%d+:(.*)'
if not term_type then
return nil
end
-- drop flags like --no-confirm-exit
term_type = term_type:match '([^%s]+)'
-- drop the path to the executable
term_type = term_type:match '([^/]+)$'
return term_type
end end
---Find nvim terminal buffers function M.new_terminal_r()
local function list_terminals() new_terminal 'R --no-save'
local terms = {}
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_get_option_value('buftype', { buf = buf }) == 'terminal' then
local chan_id = get_channel_id(buf)
if not chan_id then
goto continue
end
---@type Terminal
local term = {
bufnr = buf,
type = get_term_type(buf),
channel_id = chan_id,
}
table.insert(terms, term)
end
::continue::
end
return terms
end end
---For ipython sending function M.new_terminal_ipython()
local cpaste_start = '%cpaste -q\n' new_terminal 'ipython --no-confirm-exit --no-autoindent'
local cpaste_end = '--\n'
local cpaste_pause = 10
---Send lines to a terminal
---@param lines string[]
---@param term Terminal
---@return nil
local send_lines = function(lines, term)
local chan_id = term.channel_id
local text = table.concat(lines, '\n') .. '\n'
if term.type == 'ipython' then
vim.fn.chansend(chan_id, cpaste_start)
vim.uv.sleep(cpaste_pause)
end
vim.fn.chansend(chan_id, text)
if term.type == 'ipython' then
vim.fn.chansend(chan_id, cpaste_end)
end
end end
local s = [[ function M.new_terminal_julia()
print("hello world!") new_terminal 'julia'
def hello():
print("hello")
hello()
]]
local ls = { s }
---Connect current buffer to a terminal
local connect = function()
local bufnr = vim.api.nvim_get_current_buf()
local terms = list_terminals()
vim.ui.select(terms, {
prompt = 'Select terminal',
format_item = function(item)
return item.type .. ' ' .. item.bufnr
end,
}, function(choice)
if choice == nil then
return
end
M.buf_term_map[bufnr] = choice
end)
end end
M.send = function(lines) function M.new_terminal_shell()
local bufnr = vim.api.nvim_get_current_buf() new_terminal '$SHELL'
local term = M.buf_term_map[bufnr]
if not term then
connect()
return
end
send_lines(lines, term)
-- scroll to the bottom
local term_win = vim.fn.bufwinid(term.bufnr)
local n = vim.api.nvim_buf_line_count(term.bufnr)
vim.api.nvim_win_set_cursor(term_win, { n, 0 })
end end
M.send_visual = function() return M
-- get the selected text
vim.cmd.normal { '"zy', bang = true }
local selection = vim.fn.getreg 'z'
M.send { selection }
end
vim.keymap.set('v', '<CR>', function() -- The line beneath this is called `modeline`. See `:help modeline`
M.send_visual() -- vim: ts=2 sts=2 sw=2 et
end, { noremap = true, silent = true })
-- connect
vim.keymap.set('n', '<leader>ct', function()
connect()
end, { noremap = true, silent = true })

View File

@@ -14,7 +14,7 @@ return {
main = 'nvim-treesitter.configs', -- Sets main module to use for opts main = 'nvim-treesitter.configs', -- Sets main module to use for opts
-- [[ Configure Treesitter ]] See `:help nvim-treesitter` -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
opts = { opts = {
ensure_installed = { 'bash', 'c', 'diff', 'html', 'latex', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'r', 'vim', 'vimdoc' }, ensure_installed = { 'bash', 'c', 'diff', 'html', 'latex', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'r', 'vim', 'vimdoc', 'yaml' },
-- Autoinstall languages that are not installed -- Autoinstall languages that are not installed
auto_install = true, auto_install = true,
highlight = { highlight = {