feat: Ajout autocmd pour les fichiers groovy et python

This commit is contained in:
Xavier Logerais 2023-11-09 20:24:20 +01:00
parent 095d08c050
commit 420f84f1a3
8 changed files with 163 additions and 23 deletions

View File

@ -4,21 +4,60 @@ vim.api.nvim_create_autocmd(
-- group = vim.api.nvim_create_augroup("groovy", { clear = true }), -- group = vim.api.nvim_create_augroup("groovy", { clear = true }),
pattern = { "groovy", "Jenkinsfile" }, pattern = { "groovy", "Jenkinsfile" },
callback = function() callback = function()
local utils = require("astronvim.utils")
utils.notify("Loading autocmd customizations for groovy files")
-- Define a new terminal dedicated to groovy
local Terminal = require('toggleterm.terminal').Terminal local Terminal = require('toggleterm.terminal').Terminal
local groovysh = Terminal:new({ local groovy = Terminal:new({
name = "groovysh", name = "groovy",
cmd = "groovysh", size = 50,
direction = "horizontal",
hidden = true, hidden = true,
close_on_exit = true, close_on_exit = true,
}) })
function _groovysh_toggle() -- Spawn in background so it will be ready to execute code
groovysh:toggle() groovy:spawn()
-- Define a function to toggle the terminal
function _groovy_terminal_toggle()
groovy:toggle(50, 'horizontal')
end end
vim.api.nvim_set_keymap("n", "<F5>", "<cmd>lua _groovysh_toggle()<CR>", { noremap = true, silent = true }) -- Define a function to run code from current buffer in the terminal
vim.api.nvim_set_keymap("i", "<F5>", "<cmd>lua _groovysh_toggle()<CR>", { noremap = true, silent = true }) function _groovy_buffer_exec()
local command = string.format(" groovy %s", vim.api.nvim_buf_get_name(0))
groovy:open(50, 'horizontal')
groovy:send(' clear', true)
groovy:send(command, true)
end
-- Define a keymap to run the current buffer in the terminal
-- <F10> corresponds to F10 on my keyboard
-- <F22> corresponds to Shift + F10 on my keyboard
-- <F34> corresponds to Ctrl + F10 on my keyboard
vim.api.nvim_set_keymap("n", "<F10>",
"<cmd>lua _groovy_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F10>",
"<cmd>lua _groovy_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F10>",
"<cmd>lua _groovy_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<F34>",
-- "<cmd>TermExec name=groovy cmd='groovy %'<cr>",
'<cmd>lua _groovy_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F34>",
-- "<cmd>TermExec name=groovy cmd='groovy %'<cr>",
'<cmd>lua _groovy_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F34>",
-- "<cmd>TermExec name=groovy cmd='groovy %'<cr>",
'<cmd>lua _groovy_buffer_exec()<cr>',
{ noremap = true, silent = true })
-- vim.api.nvim_set_keymap('n', '<F5>', ':terminal groovysh<CR>', { noremap = true, silent = true }) -- vim.api.nvim_set_keymap('n', '<F5>', ':terminal groovysh<CR>', { noremap = true, silent = true })
-- vim.opt_local.wrap = true -- vim.opt_local.wrap = true
-- vim.opt_local.spell = true -- vim.opt_local.spell = true

View File

@ -0,0 +1,67 @@
vim.api.nvim_create_autocmd(
"FileType", {
pattern = { "python" },
desc = "Customizations for python files",
callback = function()
local utils = require("astronvim.utils")
utils.notify("Loading autocmd customizations for python files")
-- Define a new terminal dedicated to python
local Terminal = require('toggleterm.terminal').Terminal
local python = Terminal:new({
name = "python",
size = 100,
direction = "vertical",
hidden = true,
close_on_exit = true,
})
-- Spawn in background so it will be ready to execute code
python:spawn()
-- Define a function to toggle the terminal
function _Python_terminal_toggle()
python:toggle(100, 'vertical')
end
-- Define a function to run code from current buffer in the terminal
function _Python_buffer_exec()
local command = string.format(" python %s", vim.api.nvim_buf_get_name(0))
python:open(100, 'vertical')
python:send(' clear', true)
python:send(command, true)
end
-- Define a keymap to run the current buffer in the terminal
-- <F10> corresponds to F10 on my keyboard
-- <F22> corresponds to Shift + F10 on my keyboard
-- <F34> corresponds to Ctrl + F10 on my keyboard
vim.api.nvim_set_keymap("n", "<F10>",
"<cmd>lua _Python_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F10>",
"<cmd>lua _Python_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F10>",
"<cmd>lua _Python_terminal_toggle()<cr>",
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<F34>",
-- "<cmd>TermExec name=python cmd='python %'<cr>",
'<cmd>lua _Python_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<F34>",
-- "<cmd>TermExec name=python cmd='python %'<cr>",
'<cmd>lua _Python_buffer_exec()<cr>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap("t", "<F34>",
-- "<cmd>TermExec name=python cmd='python %'<cr>",
'<cmd>lua _Python_buffer_exec()<cr>',
{ noremap = true, silent = true })
-- Test
-- local is_available = utils.is_available
-- if is_available "notify" then
-- notify("notify is available", "info")
end,
}
)

View File

@ -1 +1 @@
return "astrodark" return "onenord"

View File

@ -17,6 +17,7 @@ return {
require "user.autocmds.text" require "user.autocmds.text"
require "user.autocmds.terminal" require "user.autocmds.terminal"
require "user.autocmds.groovy" require "user.autocmds.groovy"
require "user.autocmds.python"
-- Set up custom filetypes -- Set up custom filetypes
-- vim.filetype.add { -- vim.filetype.add {

View File

@ -13,35 +13,47 @@ return {
-- quick save -- quick save
-- ["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command -- ["<C-s>"] = { ":w!<cr>", desc = "Save File" }, -- change description but the same command
-- My personal keybindings
["<leader>x"] = { name = "Personal" },
["<leader>xn"] = { name = "Neotree" },
["<leader>xnb"] = { "<cmd>Neotree toggle buffers left<cr>", desc = "Open Neotree Buffers" },
["<leader>xng"] = { "<cmd>Neotree toggle git_status left<cr>", desc = "Open Neotree Git status" },
["<leader>xt"] = { "<cmd>terminal tig<cr>", desc = "Open tig in a new tab" },
-- My telescope keybindings -- My telescope keybindings
["<leader>fq"] = { "<cmd>Telescope quickfix<cr>", desc = "Find quickfixes with Telescope" }, ["<leader>fq"] = { "<cmd>Telescope quickfix<cr>", desc = "Find quickfixes with Telescope" },
["<leader>fs"] = { "<cmd>Telescope spell_suggest<cr>", desc = "Find spell suggestions with Telescope" }, ["<leader>fs"] = { "<cmd>Telescope spell_suggest<cr>", desc = "Find spell suggestions with Telescope" },
["<leader>fp"] = { "<cmd>Telescope projects<cr>", desc = "Find projetcs with Telescope" },
-- My personal keybindings
["<leader>²"] = { name = "Personal" },
["<leader>²t"] = { name = "Terminals" },
["<leader>²tt"] = { "<cmd>TermSelect<cr>", desc = "Select a terminal" },
["<leader>²tg"] = { "<cmd>terminal tig<cr>", desc = "Open tig in a new tab" },
["<leader>²n"] = { name = "Neotree" },
["<leader>²nb"] = { "<cmd>Neotree toggle buffers left<cr>", desc = "Open Neotree Buffers" },
["<leader>²ng"] = { "<cmd>Neotree toggle git_status left<cr>", desc = "Open Neotree Git status" },
["<F26>"] = { '<cmd>Neotree toggle<cr>', desc = "File Explorer" }, -- F26 corresponds to <Ctrl+F2> on my keyboard
["<F27>"] = { function() require("astronvim.utils").toggle_term_cmd "lazygit" end, desc = "Lazygit" }, -- F27 corresponds to <Ctrl+F3> on my keyboard
["<F28>"] = { function() require("astronvim.utils").toggle_term_cmd "tig" end, desc = "Tig" }, -- F28 corresponds to <Ctrl+F4> on my keyboard
}, },
-- Insert mode -- Insert mode
i = {}, i = {
["<F26>"] = { '<cmd>Neotree toggle<cr>', desc = "File Explorer" }, -- F26 corresponds to <Ctrl+F2> on my keyboard
["<F27>"] = { function() require("astronvim.utils").toggle_term_cmd "lazygit" end, desc = "Lazygit" }, -- F27 corresponds to <Ctrl+F3> on my keyboard
["<F28>"] = { function() require("astronvim.utils").toggle_term_cmd "tig" end, desc = "Tig" }, -- F28 corresponds to <Ctrl+F4> on my keyboard
},
-- Terminal mode -- Terminal mode
t = { t = {
-- setting a mapping to false will disable it -- setting a mapping to false will disable it
-- ["<esc>"] = false, -- ["<esc>"] = false,
-- Switch to normal mode in terminal mode
["<Esc><Esc><Esc>"] = { "<C-\\><C-n>" },
-- Clear Ctrl+l so that we can use it to clear the terminal -- Clear Ctrl+l so that we can use it to clear the terminal
["<C-l>"] = false, ["<C-l>"] = false,
["<C-h>"] = false, ["<C-h>"] = false,
-- Clear Ctrl-J and Ctrl-K so that we can use them to navigate the terminal (for lazygit) -- Clear Ctrl-J and Ctrl-K so that we can use them to navigate the terminal (for lazygit)
["<C-j>"] = false, ["<C-j>"] = false,
["<C-k>"] = false, ["<C-k>"] = false,
-- Switch to normal mode in terminal mode ["<F27>"] = { function() require("astronvim.utils").toggle_term_cmd "lazygit" end, desc = "Lazygit" }, -- F27 corresponds to <Ctrl+F3> on my keyboard
["<Esc><Esc><Esc>"] = { "<C-\\><C-n>" } ["<F28>"] = { function() require("astronvim.utils").toggle_term_cmd "tig" end, desc = "Tig" }, -- F28 corresponds to <Ctrl+F4> on my keyboard
}, },
} }

View File

@ -2,6 +2,7 @@ return {
{ 'jacoborus/tender.vim', lazy = false }, { 'jacoborus/tender.vim', lazy = false },
{ 'altercation/vim-colors-solarized', lazy = false }, { 'altercation/vim-colors-solarized', lazy = false },
{ 'bluz71/vim-moonfly-colors', lazy = false }, { 'bluz71/vim-moonfly-colors', lazy = false },
{ 'joshdick/onedark.vim', lazy = false },
{ 'ray-x/aurora', lazy = false }, { 'ray-x/aurora', lazy = false },
{ 'rmehri01/onenord.nvim' },
{ 'joshdick/onedark.vim' },
} }

View File

@ -2,8 +2,26 @@ return {
{ {
"nvim-neo-tree/neo-tree.nvim", "nvim-neo-tree/neo-tree.nvim",
opts = { opts = {
window = {
width = 50,
mappings = {
["<space>"] = false, -- disable space until we figure out which-key disabling
[">"] = "next_source",
["<"] = "prev_source",
},
},
event_handlers = {
{
event = "file_opened",
handler = function(file_path)
-- auto close
-- vimc.cmd("Neotree close")
-- OR
require("neo-tree.command").execute({ action = "close" })
end
},
},
close_if_last_window = true, close_if_last_window = true,
window = { width = 50 }, },
}
} }
} }

View File

@ -2,10 +2,12 @@ return {
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
dependencies = { dependencies = {
"nvim-telescope/telescope-file-browser.nvim", "nvim-telescope/telescope-file-browser.nvim",
"da-moon/telescope-toggleterm.nvim",
}, },
config = function(...) config = function(...)
require "plugins.configs.telescope" (...) require "plugins.configs.telescope" (...)
local telescope = require "telescope" local telescope = require "telescope"
telescope.load_extension "file_browser" telescope.load_extension "file_browser"
telescope.load_extension "toggleterm"
end, end,
} }