|
| 1 | +local opts = { |
| 2 | + -- size can be a number or function which is passed the current terminal |
| 3 | + size = function(term) |
| 4 | + if term.direction == "horizontal" then |
| 5 | + return 15 |
| 6 | + elseif term.direction == "vertical" then |
| 7 | + return vim.o.columns * 0.4 |
| 8 | + end |
| 9 | + end, |
| 10 | + open_mapping = [[<c-\><c-\>]], |
| 11 | + -- on_open = fun(t: Terminal), -- function to run when the terminal opens |
| 12 | + hide_numbers = true, -- hide the number column in toggleterm buffers |
| 13 | + shade_filetypes = {}, |
| 14 | + shade_terminals = true, |
| 15 | + -- shading_factor = '<number>', -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light |
| 16 | + -- start_in_insert = true, |
| 17 | + start_in_insert = false, |
| 18 | + insert_mappings = true, -- whether or not the open mapping applies in insert mode |
| 19 | + persist_size = true, |
| 20 | + -- direction = 'vertical' | 'horizontal' | 'window' | 'float', |
| 21 | + -- direction = 'float', |
| 22 | + direction = "horizontal", |
| 23 | + close_on_exit = true, -- close the terminal window when the process exits |
| 24 | + shell = vim.o.shell, -- change the default shell |
| 25 | + -- This field is only relevant if direction is set to 'float' |
| 26 | + float_opts = { |
| 27 | + -- The border key is *almost* the same as 'nvim_open_win' |
| 28 | + -- see :h nvim_open_win for details on borders however |
| 29 | + -- the 'curved' border is a custom border type |
| 30 | + -- not natively supported but implemented in this plugin. |
| 31 | + -- border = 'single' | 'double' | 'shadow' | 'curved' | ... other options supported by win open |
| 32 | + -- width = <value>, |
| 33 | + -- height = <value>, |
| 34 | + -- winblend = 3, |
| 35 | + highlights = { |
| 36 | + border = "Normal", |
| 37 | + background = "Normal", |
| 38 | + }, |
| 39 | + }, |
| 40 | +} |
| 41 | + |
| 42 | +return { |
| 43 | + { |
| 44 | + "akinsho/toggleterm.nvim", |
| 45 | + config = function() |
| 46 | + require("toggleterm").setup(opts) |
| 47 | + -- config will override automatically setup(opts). |
| 48 | + for _, mode in pairs({ "i", "v", "n", "t" }) do |
| 49 | + for i = 1, 4 do |
| 50 | + -- vim.api.nvim_set_keymap(mode, "<c-"..tostring(i)..">", "<cmd>ToggleTerm "..tostring(i).."<cr>", {expr = true, noremap = true}) |
| 51 | + vim.api.nvim_set_keymap( |
| 52 | + mode, |
| 53 | + "<F" .. tostring(i) .. ">", |
| 54 | + "<cmd>ToggleTerm " .. tostring(i) .. "<cr>", |
| 55 | + { expr = false, noremap = true } |
| 56 | + ) |
| 57 | + -- expr = false 非常重要; 不然就会触发 vim mapping 的 <expr> 机制, 导致先用vim命令执行一遍, 再把结果作为map的目标 |
| 58 | + end |
| 59 | + end |
| 60 | + vim.api.nvim_set_keymap("t", "<c-w>w", "<c-\\><c-n><c-w><c-w>", { expr = false, noremap = true }) |
| 61 | + end, |
| 62 | + }, |
| 63 | +} |
0 commit comments