diff --git a/lua/custom/keymaps/buffers.lua b/lua/custom/keymaps/buffers.lua index ea9d72f..e13bafc 100644 --- a/lua/custom/keymaps/buffers.lua +++ b/lua/custom/keymaps/buffers.lua @@ -1,4 +1,4 @@ --- Buffer group mappings +-- buffer group mappings -- local status_wk, wk = pcall(require, 'which-key') diff --git a/lua/custom/keymaps/edit.lua b/lua/custom/keymaps/edit.lua index 59e1ca5..e7d1a34 100644 --- a/lua/custom/keymaps/edit.lua +++ b/lua/custom/keymaps/edit.lua @@ -1,6 +1,6 @@ --- Edition mappings --- +-- edition mappings -- + local status_kh, kh = pcall(require, 'custom.plugins.keymaps-helper') if not status_kh then return @@ -8,18 +8,5 @@ end kh.map({ 'n', 'v', 'i' }, '', 'undo', { 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 --- { '', 'undo', desc = 'Undo', silent = true, noremap = true, hidden = true }, --- }, --- } - -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/custom/keymaps/files.lua b/lua/custom/keymaps/explore.lua similarity index 96% rename from lua/custom/keymaps/files.lua rename to lua/custom/keymaps/explore.lua index d1b03de..194be98 100644 --- a/lua/custom/keymaps/files.lua +++ b/lua/custom/keymaps/explore.lua @@ -1,4 +1,4 @@ --- Neo-tree mappings +-- file explorer mappings -- local status_wk, wk = pcall(require, 'which-key') diff --git a/lua/custom/keymaps/general.lua b/lua/custom/keymaps/general.lua index 18d0211..f131c28 100644 --- a/lua/custom/keymaps/general.lua +++ b/lua/custom/keymaps/general.lua @@ -1,4 +1,4 @@ --- General mappings +-- general mappings -- local status_kh, kh = pcall(require, 'custom.plugins.keymaps-helper') diff --git a/lua/custom/keymaps/groups.lua b/lua/custom/keymaps/groups.lua index e86633c..b12a65d 100644 --- a/lua/custom/keymaps/groups.lua +++ b/lua/custom/keymaps/groups.lua @@ -1,4 +1,4 @@ --- Key mappings groups +-- key mappings groups -- local status_wk, wk = pcall(require, 'which-key') @@ -12,6 +12,7 @@ wk.add { mode = { 'n' }, { 's', group = '[s]earch' }, { 't', group = '[t]oggles' }, + { 'T', group = '[T]erminal' }, }, { diff --git a/lua/custom/keymaps/init.lua b/lua/custom/keymaps/init.lua index 0cd8a27..6d69266 100644 --- a/lua/custom/keymaps/init.lua +++ b/lua/custom/keymaps/init.lua @@ -5,11 +5,12 @@ require 'custom.keymaps.nop' require 'custom.keymaps.groups' require 'custom.keymaps.general' require 'custom.keymaps.buffers' -require 'custom.keymaps.files' +require 'custom.keymaps.explore' require 'custom.keymaps.edit' require 'custom.keymaps.search' require 'custom.keymaps.toggles' require 'custom.keymaps.obsidian' +require 'custom.keymaps.terminal' -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/custom/keymaps/nop.lua b/lua/custom/keymaps/nop.lua index 11c292f..d56f357 100644 --- a/lua/custom/keymaps/nop.lua +++ b/lua/custom/keymaps/nop.lua @@ -1,4 +1,4 @@ --- Deactivated key mappings +-- deactivated key mappings -- local status_wk, wk = pcall(require, 'which-key') diff --git a/lua/custom/keymaps/obsidian.lua b/lua/custom/keymaps/obsidian.lua index 481aada..d3469d1 100644 --- a/lua/custom/keymaps/obsidian.lua +++ b/lua/custom/keymaps/obsidian.lua @@ -1,4 +1,4 @@ --- Obsidian mappings +-- obsidian mappings -- local status_wk, wk = pcall(require, 'which-key') diff --git a/lua/custom/keymaps/search.lua b/lua/custom/keymaps/search.lua index dd18013..7c30dbf 100644 --- a/lua/custom/keymaps/search.lua +++ b/lua/custom/keymaps/search.lua @@ -1,4 +1,4 @@ --- Search group mappings +-- search group mappings -- local wk = require 'which-key' diff --git a/lua/custom/keymaps/terminal.lua b/lua/custom/keymaps/terminal.lua new file mode 100644 index 0000000..d5001d4 --- /dev/null +++ b/lua/custom/keymaps/terminal.lua @@ -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' }, + { 'Ti', th.new_terminal_ipython, desc = 'new [i]python terminal', silent = true, noremap = true }, + { 'Tj', th.new_terminal_julia, desc = 'new [j]ulia terminal', silent = true, noremap = true }, + { 'Ts', th.new_terminal_shell, desc = 'new terminal with [s]hell', silent = true, noremap = true }, + { 'Tp', th.new_terminal_python, desc = 'new [p]ython terminal', silent = true, noremap = true }, + { '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 diff --git a/lua/custom/keymaps/toggles.lua b/lua/custom/keymaps/toggles.lua index a57782d..c3e19b7 100644 --- a/lua/custom/keymaps/toggles.lua +++ b/lua/custom/keymaps/toggles.lua @@ -1,15 +1,35 @@ --- Toggles group mappings +-- toggles group mappings -- local wk = require 'which-key' 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 { mode = { 'n' }, -- gitsigns { 'tb', gitsigns.toggle_current_line_blame, desc = 'toggle git show [b]lame line' }, - { 'tD', gitsigns.preview_hunk_inline, desc = 'toggle git show [D]eleted' }, + { 'td', gitsigns.preview_hunk_inline, desc = 'toggle git show [d]eleted' }, { 'tm', 'RenderMarkdown buf_toggle', desc = 'toggle [m]arkdown rendering for current' }, + { 'tt', toggle_light_dark_theme, desc = 'toggle light/dark [t]heme' }, + { 'tc', toggle_conceal, desc = 'toggle [c]onceal' }, + { 'tz', ':setlocal spell!', desc = 'toggle [z]pellcheck' }, } -- The line beneath this is called `modeline`. See `:help modeline` diff --git a/lua/custom/plugins/neotree-helper.lua b/lua/custom/plugins/neotree-helper.lua index e8c4056..a3b2aca 100644 --- a/lua/custom/plugins/neotree-helper.lua +++ b/lua/custom/plugins/neotree-helper.lua @@ -1,5 +1,6 @@ -- Neo-tree helper module -- + local M = {} -- 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 '~') -- Si c'est un fichier réel, révéler le fichier dans l'arborescence 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 position=left reveal_force_cwd=true' + 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' -- Sinon, ouvrir dans le répertoire de travail courant else - -- vim.cmd('Neotree toggle position=left reveal_force_cwd=true dir=' .. vim.fn.getcwd()) - vim.cmd 'Neotree toggle position=left reveal_force_cwd=true' + vim.cmd('Neotree toggle position=left reveal=true dir=' .. vim.fn.getcwd()) + -- vim.cmd 'Neotree toggle position=left reveal_force_cwd=true' end end diff --git a/lua/custom/plugins/term-helper.lua b/lua/custom/plugins/term-helper.lua index c09ace6..cf87b4d 100644 --- a/lua/custom/plugins/term-helper.lua +++ b/lua/custom/plugins/term-helper.lua @@ -2,140 +2,171 @@ -- from: https://github.com/jmbuhr/nvim-config -- ----@module 'utils.term' -local M = { - ---Map of buffers to a terminals - ---@type table - buf_term_map = {}, -} +-- ---@module 'utils.term' +-- local M = { +-- ---Map of buffers to a terminals +-- ---@type table +-- 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', '', function() +-- M.send_visual() +-- end, { noremap = true, silent = true }) +-- +-- -- connect +-- vim.keymap.set('n', 'ct', function() +-- connect() +-- end, { noremap = true, silent = true }) ----A terminal has a buffer number, a type and a channel id ----@class Terminal ----@field bufnr integer ----@field type string? ----@field channel_id integer +local M = {} ----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 }) +local function new_terminal(lang) + vim.cmd('vsplit term://' .. lang) 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 +function M.new_terminal_python() + new_terminal 'python' 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 +function M.new_terminal_r() + new_terminal 'R --no-save' 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 +function M.new_terminal_ipython() + new_terminal 'ipython --no-confirm-exit --no-autoindent' 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) +function M.new_terminal_julia() + new_terminal 'julia' 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 }) +function M.new_terminal_shell() + new_terminal '$SHELL' 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 +return M -vim.keymap.set('v', '', function() - M.send_visual() -end, { noremap = true, silent = true }) - --- connect -vim.keymap.set('n', 'ct', function() - connect() -end, { noremap = true, silent = true }) +-- The line beneath this is called `modeline`. See `:help modeline` +-- vim: ts=2 sts=2 sw=2 et diff --git a/lua/kickstart/plugins/treesitter.lua b/lua/kickstart/plugins/treesitter.lua index d50d4fa..26b4b5e 100644 --- a/lua/kickstart/plugins/treesitter.lua +++ b/lua/kickstart/plugins/treesitter.lua @@ -14,7 +14,7 @@ return { main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` 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 auto_install = true, highlight = {