Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lvim.keys.normal_mode["<leader>i"] = ":Hang<cr>"
- lvim.keys.normal_mode["<leader>r"] = ":Make<cr>"
- lvim.keys.normal_mode["<leader>rr"] = ":CloseTerminal<cr>"
- lvim.keys.normal_mode["<leader>ii"] = ":CloseTerminal<cr>"
- vim.cmd("command! CloseTerminal lua close_terminal_buffer()")
- function _G.close_terminal_buffer()
- local terminal_bufnr = nil
- for _, win in ipairs(vim.api.nvim_list_wins()) do
- local bufnr = vim.api.nvim_win_get_buf(win)
- local buftype = vim.api.nvim_buf_get_option(bufnr, "buftype")
- if buftype == "terminal" then
- terminal_bufnr = bufnr
- Already_open = false
- break
- end
- end
- if terminal_bufnr then
- vim.cmd("bdelete! " .. terminal_bufnr)
- end
- end
- vim.cmd("command! Hang lua generic_make_hang()")
- function _G.generic_make_hang()
- local filename = vim.fn.expand("%");
- local filetype = vim.bo.filetype
- vim.cmd(":w")
- local commands = {
- scala = "sbt --client run",
- java = "./mvnw spring-boot:run",
- c = string.format("gcc -g %s && ./a.out", filename)
- }
- local command = commands[filetype] or "make!"
- _G.close_terminal_buffer() -- close any buffs
- vim.cmd("botright new") -- create buff
- vim.cmd("resize " .. 10) -- set buff height
- vim.fn.termopen(command) -- run cmd
- vim.cmd("visual!") -- switch to visual
- vim.cmd("wincmd p") -- switch to main window
- end
- vim.cmd("command! Make lua generic_make()")
- function _G.generic_make()
- local filename = vim.fn.expand("%");
- local filetype = vim.bo.filetype
- vim.cmd(":w")
- local commands = {
- scala = "sbt --client run",
- java = "./mvnw spring-boot:run",
- c = string.format("gcc %s && ./a.out", filename)
- }
- local command = commands[filetype] or "make!"
- local height = 10 -- Set the desired terminal window height
- vim.cmd("botright new") -- Create a new buffer at the bottom of the screen
- vim.cmd("resize " .. height) -- Set the height of the new buffer
- vim.fn.termopen(command)
- -- Set up a temporary key mapping to close the terminal buffer when any key is pressed
- vim.cmd("autocmd BufEnter <buffer> tnoremap <buffer> <silent> <nowait> <expr> <Plug>(CloseTerminal) execute('silent! bwipeout!<CR>')")
- end
Advertisement
Add Comment
Please, Sign In to add comment