From 0ca41390072db59644fe220a7e8b469e08aaeccb Mon Sep 17 00:00:00 2001 From: suly520 Date: Tue, 9 Apr 2024 21:07:14 +0200 Subject: [PATCH] Added some minor keymapings; Added terminal support --- init.lua | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index db55a9e8..ac8f1033 100644 --- a/init.lua +++ b/init.lua @@ -167,6 +167,65 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagn vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) +-- flsu +-- +-- general +-- +vim.wo.relativenumber = true + +vim.api.nvim_set_keymap('n', 'i', '', { noremap = true, silent = true, desc = 'find tag under cursor' }) +-- vim.keymap.set('n', 't', function() +-- +-- clipboard +-- +vim.g.clipboard = { + name = 'xclip', + copy = { + ['+'] = 'xclip -selection clipboard', + ['*'] = 'xclip -selection clipboard', + }, + paste = { + ['+'] = 'xclip -selection clipboard -o', + ['*'] = 'xclip -selection clipboard -o', + }, + cache_enabled = 1, +} +-- +-- term +-- +local termBfr = { bufnr = nil } + +local function openOrToggleTerminal(new_term) + new_term = new_term or false + local bufnr = vim.api.nvim_get_current_buf() + + -- If the current buffer is a terminal, hide (minimize) it + if vim.bo[bufnr].buftype == 'terminal' then + vim.cmd 'hide' + return + end + + if termBfr.bufnr and vim.api.nvim_buf_is_loaded(termBfr.bufnr) and not new_term then + vim.cmd 'botright split' + vim.cmd('buffer ' .. termBfr.bufnr) + vim.cmd 'startinsert' + return + end + + -- If no terminal is found, open a new one + vim.cmd 'botright split | terminal' + vim.cmd 'startinsert' + termBfr.bufnr = vim.api.nvim_get_current_buf() +end + +-- Map t to toggle the terminal +vim.keymap.set('n', 't', openOrToggleTerminal, { desc = 'Toggle Terminal' }) + +-- Map nt to open a new terminal or toggle the visibility of an existing one +vim.keymap.set('n', 'nt', function() + vim.cmd 'cd %:p:h' -- Change to the directory of the current file + openOrToggleTerminal(true) -- Open or toggle the terminal +end, { desc = 'Open New Terminal' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which -- is not what someone will guess without a bit more experience. @@ -190,6 +249,10 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the right win vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +-- my custom keys flsu + +-- vim.keymap.set('n', 't', , { desc = 'sme' }) + -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` @@ -708,7 +771,7 @@ require('lazy').setup({ -- is similar, except moving you backwards. [''] = cmp.mapping(function() if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() + luasnip.expand_or_jump(1) end end, { 'i', 's' }), [''] = cmp.mapping(function() @@ -837,6 +900,15 @@ require('lazy').setup({ -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` -- { import = 'custom.plugins' }, + -- + -- amongst your other plugins + { + 'akinsho/toggleterm.nvim', + version = '*', + config = true, + }, + -- or + -- 'akinsho/toggleterm.nvim', version = "*", opts = {--[[ things you want to change go here]]}} }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the @@ -859,5 +931,18 @@ require('lazy').setup({ }, }) +function _G.set_terminal_keymaps() + local opts = { buffer = 0 } + vim.keymap.set('t', '', [[]], opts) + vim.keymap.set('t', 'jk', [[]], opts) + vim.keymap.set('t', '', [[wincmd h]], opts) + vim.keymap.set('t', '', [[wincmd j]], opts) + vim.keymap.set('t', '', [[wincmd k]], opts) + vim.keymap.set('t', '', [[wincmd l]], opts) + vim.keymap.set('t', '', [[]], opts) +end + +vim.cmd 'autocmd! TermOpen term://* lua set_terminal_keymaps()' + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et