local keys = require "custom_keys" local opts = require "custom_opts" -- Setup keymapping local function set_keymap() local map = vim.keymap.set local option = { noremap = true, silent = true } map("n", keys.jump_left_window, "h", option) map("n", keys.jump_down_window, "j", option) map("n", keys.jump_up_window, "k", option) map("n", keys.jump_right_window, "l", option) -- View documentation and signature details map("n", "K", vim.lsp.buf.hover, option) map({ "n", "i" }, "", vim.lsp.buf.signature_help, option) vim.cmd [[ " press esc to cancel search highlight nnoremap :nohlsearch:echo ]] -- Remove the `~` for blank lines by setting its color to be the same as background vim.cmd "hi NonText guifg=bg" -- for markdown file vim.cmd [[ " optimized up and down move when set wrap for markdown file autocmd FileType markdown noremap j gj autocmd FileType markdown noremap k gk autocmd FileType markdown setlocal wrap ]] -- Supported by bufdelete vim.cmd [[ cnoreabbrev bdelete Bdelete cnoreabbrev bdelete! Bdelete! cnoreabbrev bwipeout Bwipeout cnoreabbrev bwipeout! Bwipeout! ]] -- Supported by bufferline map("n", keys.pick_tab, ":BufferLinePick", option) -- Supported by nvim-tree map("n", keys.file_explorer, ":Neotree position=left source=filesystem action=show toggle=true", option) map("n", keys.git_status, ":Neotree position=float source=git_status action=show toggle=true", option) -- Supported by aerial map("n", keys.outline, ":AerialToggle! right", option) -- Supported by diffview map("n", keys.diff_open, ":DiffviewOpen", option) map("n", keys.diff_close, ":DiffviewClose", option) -- Supported by toggleterm -- float terminal local float_terminal_default = require("toggleterm.terminal").Terminal:new { direction = "float", on_open = function(term) -- forced to change the working dir for terminal -- This will solve the problem of not updating the directory when switching sessions. local cwd = vim.fn.getcwd() if cwd ~= term.dir then term:change_dir(cwd) end -- when float term opened, disable bottom terminal vim.api.nvim_del_keymap("t", keys.terminal_bottom) vim.cmd "startinsert!" end, on_close = function(t, job, exit_code, name) -- when float term closed, enable bottom terminal map("t", keys.terminal_bottom, ":lua _bottom_term_toggle()", option) end, } function _float_term_toggle() float_terminal_default:toggle() end -- bottom terminal local bottom_terminal_default = require("toggleterm.terminal").Terminal:new { direction = "horizontal", on_open = function(term) -- forced to change the working dir for terminal -- This will solve the problem of not updating the directory when switching sessions. local cwd = vim.fn.getcwd() if cwd ~= term.dir then term:change_dir(cwd) end -- set keymapping local opts = { buffer = 0 } vim.api.nvim_buf_set_keymap(term.bufnr, "t", "", [[wincmd h]], { noremap = true, silent = true }) vim.api.nvim_buf_set_keymap(term.bufnr, "t", "", [[wincmd j]], { noremap = true, silent = true }) vim.api.nvim_buf_set_keymap(term.bufnr, "t", "", [[wincmd k]], { noremap = true, silent = true }) vim.api.nvim_buf_set_keymap(term.bufnr, "t", "", [[wincmd l]], { noremap = true, silent = true }) vim.cmd "startinsert!" end, on_exit = function(t, job, exit_code, name) vim.cmd "quit!" end, } function _bottom_term_toggle() bottom_terminal_default:toggle() end map("n", keys.terminal_float, ":lua _float_term_toggle()", option) map("t", keys.terminal_float, ":lua _float_term_toggle()", option) map("n", keys.terminal_bottom, ":lua _bottom_term_toggle()", option) map("t", keys.terminal_bottom, ":lua _bottom_term_toggle()", option) vim.cmd [[ command! Termfloat :lua _float_term_toggle() ]] vim.cmd [[cnoreabbrev terminal Termfloat]] -- Supported by nvim-session-manager map("n", keys.switch_session, ":SessionManager load_session", option) end -- Set up transparency local function set_transparency() local transparency = opts.window_transparency -- Setup global transparency for float window. vim.api.nvim_command(string.format("autocmd FileType * set winblend=%d", transparency)) -- Setup global transparency for popup menu. vim.o.pumblend = transparency end -- Set up auto command local function set_autocmd() end set_keymap() set_transparency() set_autocmd()