local map = vim.keymap.set -- Remap leader vim.g.mapleader = " " map('n', '', '') -- Buffer movements map("n", "", ":bp") map("n", "", ":bn") -- Make use of Shift+hjkl map("n", "H", "^") map("n", "L", "$") map("n", "", "}") map("n", "", "{") -- Leader remap map("n", "w", ":write") map("n", "e", ":NvimTreeFocus") -- Split movements map("n", "h", "h") map("n", "j", "j") map("n", "k", "k") map("n", "l", "l") -- Remap comments map("n", "", require("Comment.api").toggle.linewise.current) map("i", "", require("Comment.api").toggle.linewise.current) map("x", "", function() -- some evil trickery with comment plugin vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, false, true), 'nx', false) require("Comment.api").toggle.linewise(vim.fn.visualmode()) end ) -- Close buffer and nvim local close_buffer_and_nvimtree = function() local try_quit = function(command) local success, errorMsg = pcall(vim.api.nvim_command, command) if not success then print("Failed to quit: " .. errorMsg) end end local tree = require("nvim-tree.api").tree local buffer_count = #vim.fn.filter(vim.fn.range(1, vim.fn.bufnr '$'), 'buflisted(v:val)') if buffer_count == 0 then try_quit("quit") -- elseif buffer_count == 1 then -- vim.cmd("e .") -- try_quit("bd") -- vim.cmd("NvimTreeClose") else tree.toggle({ focus = false }) try_quit("bd") tree.toggle({ focus = false }) end -- if buffer_count == 1 and #vim.api.nvim_list_wins() == 1 then -- try_quit("quit") -- end end -- Leader remapping map("n", "q", function() close_buffer_and_nvimtree() end) map("n", "Q", ":%bd | quit") map("n", "", ":%bd! | quit!") map("n", "", ":%bd! | quit!") map("v", "y", '"+y') map("n", "y", '"+yy') map({ "n", "v" }, "p", '"+p') map({ "n", "v" }, "P", '"+P') -- Toggle tree map("n", "", function() require("nvim-tree.api").tree.toggle({ focus=false }) end)