add: add key map live server, close buffer

This commit is contained in:
asep komarudin 2024-02-14 22:40:05 +07:00
parent 02ec73abf4
commit 17c1335cd6
2 changed files with 29 additions and 1 deletions

View file

@ -10,6 +10,12 @@ function _LIVE_SERVER()
live_server:toggle() live_server:toggle()
end end
function _close_buffer()
local buf = vim.api.nvim_get_current_buf()
-- delete current buffer
require("bufdelete").bufdelete(buf, true)
end
local term_opts = { silent = true } local term_opts = { silent = true }
-- Shorten function name -- Shorten function name
@ -46,6 +52,7 @@ keymap("n", "<C-Z>", "<cmd>undo<CR>", opts)
keymap("x", "<C-Z>", "<esc><cmd>undo<CR>", opts) keymap("x", "<C-Z>", "<esc><cmd>undo<CR>", opts)
keymap("v", "<C-Z>", "<esc><cmd>undo<CR>", opts) keymap("v", "<C-Z>", "<esc><cmd>undo<CR>", opts)
keymap("i", "<C-Z>", "<esc><cmd>undo<CR>", opts) keymap("i", "<C-Z>", "<esc><cmd>undo<CR>", opts)
-- create comment CTRL + / all mode
keymap("n", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts) keymap("n", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts)
keymap("v", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts) keymap("v", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts)
keymap("i", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts) keymap("i", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", opts)
@ -54,6 +61,9 @@ keymap("n", "<C-_>", "<esc><cmd>lua require('Comment.api').toggle.linewise.curre
-- keymap("n", "<C-l>", "<esc><cmd>lua _LIVE_SERVER()<cr>", opts) -- keymap("n", "<C-l>", "<esc><cmd>lua _LIVE_SERVER()<cr>", opts)
-- keymap("i", "<C-l>", "<esc><cmd>lua _LIVE_SERVER()<cr>", opts) -- keymap("i", "<C-l>", "<esc><cmd>lua _LIVE_SERVER()<cr>", opts)
-- ALT + l to open terminal and run live-server
keymap("n", "<A-l>", "<cmd>terminal<cr>$i<Right>live-server<cr>", opts)
-- Resize with arrows -- Resize with arrows
-- cona -- cona
-- keymap("n", "<C-Down>", ":resize +2<CR>", opts) -- keymap("n", "<C-Down>", ":resize +2<CR>", opts)
@ -114,6 +124,9 @@ keymap("x", "<S-Down>", ":'<,'>t'><cr>", opts)
-- keymap("i", "<C-r>", "<cmd>RunFile<CR>", opts) -- keymap("i", "<C-r>", "<cmd>RunFile<CR>", opts)
-- keymap("n", "<C-r>", "<cmd>RunFile<CR>", opts) -- keymap("n", "<C-r>", "<cmd>RunFile<CR>", opts)
-- close current buffer
keymap("n", "<S-t>", "<cmd>lua _close_buffer()<cr>", opts)
-- Visual Block -- -- Visual Block --
-- Move text up and down -- Move text up and down
keymap("x", "J", ":move '>+1<CR>gv-gv", opts) keymap("x", "J", ":move '>+1<CR>gv-gv", opts)

View file

@ -53,6 +53,12 @@ function _NEWTAB_TOGGLE()
pwsh:toggle() pwsh:toggle()
end end
function _open_explorer()
local Terminal = require("toggleterm.terminal").Terminal
local pwsh = Terminal:new({ cmd = "explorer .", hidden = true, direction = "tab" })
pwsh:toggle()
end
function _LIVE_SERVER() function _LIVE_SERVER()
local Terminal = require("toggleterm.terminal").Terminal local Terminal = require("toggleterm.terminal").Terminal
local live_server = Terminal:new({ local live_server = Terminal:new({
@ -156,6 +162,12 @@ end
local debug_key = {} local debug_key = {}
-- local is_dap = pcall(require, "dap") -- local is_dap = pcall(require, "dap")
function _close_buffer()
local buf = vim.api.nvim_get_current_buf()
-- delete current buffer
require("bufdelete").bufdelete(buf, true)
end
if vim.fn.has("win32") == 0 then if vim.fn.has("win32") == 0 then
debug_key = { debug_key = {
name = "  Debug", name = "  Debug",
@ -189,7 +201,10 @@ local mappings = {
["e"] = { "<cmd>NvimTreeToggle<cr>", "󰙅 Explorer" }, ["e"] = { "<cmd>NvimTreeToggle<cr>", "󰙅 Explorer" },
["w"] = { "<cmd>w!<CR>", "󰆓 Save" }, ["w"] = { "<cmd>w!<CR>", "󰆓 Save" },
["q"] = { "<cmd>q!<CR>", "󰿅 Quit" }, ["q"] = { "<cmd>q!<CR>", "󰿅 Quit" },
["c"] = { "<cmd>Bdelete!<CR>", " 󰅗 Close Buffer" }, -- ["c"] = { "<cmd>Bdelete!<CR>", "󰅗 Close Buffer" },
["k"] = { "<cmd>lua _close_buffer()<CR>", "󰅗 Close Buffer" },
-- open exloler and close toggleterm
["o"] = { "<cmd>lua _open_explorer()<cr><cmd>lua require('toggleterm').toggle()<cr>", "󱏒 Open Explorer" },
["h"] = { "<cmd>nohlsearch<CR>", "󱪿 No Highlight" }, ["h"] = { "<cmd>nohlsearch<CR>", "󱪿 No Highlight" },
["f"] = { ["f"] = {
"<cmd>Telescope find_files <CR>", "<cmd>Telescope find_files <CR>",