diff --git a/lua/chadrc.lua b/lua/chadrc.lua index e006e11..53d5c22 100644 --- a/lua/chadrc.lua +++ b/lua/chadrc.lua @@ -1,6 +1,10 @@ local M = { ui = { - theme = "onedark" + theme = "onedark", + hidden_statusline = { -- these are filetypes, not pattern matched + "NvimTree", + "toggleterm" + } }, options = { permanent_undo = true, @@ -86,13 +90,15 @@ local M = { diffget_3 = "gl", git_blame = "gb" }, + toggleterm = { + toggle_window = "w", + toggle_right = "v", + toggle_bot = "h", + }, misc = { - openTerm_right = "", - openTerm_bottom = "", - openTerm_currentBuf = "t", + esc_Termmode = "jk", copywhole_file = "", - toggle_linenr = "n", - esc_Termmode = "jk" + toggle_linenr = "n" } } } diff --git a/lua/mappings.lua b/lua/mappings.lua index 5cf0634..81b58db 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -35,10 +35,6 @@ map("", "k", 'v:count ? "k" : "gk"', {expr = true}) map("", "", 'v:count ? "j" : "gj"', {expr = true}) map("", "", 'v:count ? "k" : "gk"', {expr = true}) --- OPEN TERMINALS -- -map("n", miscMap.openTerm_right, ":vnew +terminal | setlocal nobuflisted ", opt) -- term over right -map("n", miscMap.openTerm_bottom, ":10new +terminal | setlocal nobuflisted ", opt) -- term bottom -map("n", miscMap.openTerm_currentBuf, ":terminal ", opt) -- term buffer -- copy whole file content map("n", miscMap.copywhole_file, ":%y+", opt) @@ -46,6 +42,25 @@ map("n", miscMap.copywhole_file, ":%y+", opt) -- toggle numbers map("n", miscMap.toggle_linenr, ":set nu!", opt) +-- open a new buffer as a Terminal +-- get out of terminal with jk +map("t", miscMap.esc_Termmode, "", opt) + + +M.toggleterm = function() + local m = user_map.toggleterm + + -- Open terminals + map("n", m.toggle_window, ":execute v:count . 'ToggleTerm direction=window' ", opt) + map("n", m.toggle_right, ":execute v:count . 'ToggleTerm direction=vertical' ", opt) + map("n", m.toggle_bot, ":execute v:count . 'ToggleTerm direction=horizontal' ", opt) + + -- 'Un' toggle a term from within terminal edit mode + map("t", m.toggle_window, " :ToggleTerm ", opt) + map("t", m.toggle_right, " :ToggleTerm ", opt) + map("t", m.toggle_bot, " :ToggleTerm ", opt) +end + M.truezen = function() local m = user_map.truezen @@ -113,9 +128,6 @@ end -- use ESC to turn off search highlighting map("n", "", ":noh", opt) --- get out of terminal with jk -map("t", miscMap.esc_Termmode, "", opt) - -- Packer commands till because we are not loading it at startup cmd("silent! command PackerCompile lua require 'pluginList' require('packer').compile()") cmd("silent! command PackerInstall lua require 'pluginList' require('packer').install()") diff --git a/lua/options.lua b/lua/options.lua index 48d7339..9b88ed2 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -66,9 +66,9 @@ for _, plugin in pairs(disabled_built_ins) do g["loaded_" .. plugin] = 1 end --- Don't show status line on vim terminals -vim.cmd [[ au TermOpen term://* setlocal nonumber laststatus=0 ]] -vim.cmd [[ au TermClose term://* setlocal number laststatus=2 ]] +-- Don't show status line on certain windows +vim.cmd [[ au TermOpen term://* setlocal nonumber norelativenumber ]] +vim.cmd [[let hidden_statusline = luaeval('require("chadrc").ui.hidden_statusline') | autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter,TermEnter * nested if index(hidden_statusline, &ft) >= 0 | set laststatus=0 | else | set laststatus=2 | endif]] -- Open a file from its last left off position -- vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] diff --git a/lua/pluginList.lua b/lua/pluginList.lua index 773cf8d..458fb0e 100644 --- a/lua/pluginList.lua +++ b/lua/pluginList.lua @@ -199,6 +199,16 @@ return packer.startup( } -- misc plugins + use { + "akinsho/nvim-toggleterm.lua", + event = "BufWinEnter", + config = function() + require "plugins.toggleterm" + end, + setup = function() + require "mappings".toggleterm() + end + } use { "windwp/nvim-autopairs", after = "nvim-compe", diff --git a/lua/plugins/nvimtree.lua b/lua/plugins/nvimtree.lua index 5713bd1..4444755 100644 --- a/lua/plugins/nvimtree.lua +++ b/lua/plugins/nvimtree.lua @@ -93,6 +93,3 @@ g.nvim_tree_bindings = { {key = "q", cb = tree_cb("close")}, {key = "g?", cb = tree_cb("toggle_help")} } - --- hide statusline when nvim tree is opened -vim.cmd [[au BufEnter,BufWinEnter,WinEnter,CmdwinEnter * if bufname('%') == "NvimTree" | set laststatus=0 | else | set laststatus=2 | endif]] diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..174e544 --- /dev/null +++ b/lua/plugins/toggleterm.lua @@ -0,0 +1,33 @@ +local present, toggleterm = pcall(require, "toggleterm") +if not present then + return +end + +toggleterm.setup { + -- size can be a number or function which is passed the current terminal + size = function(term) + if term.direction == "horizontal" then + return 15 + elseif term.direction == "vertical" then + return vim.o.columns * 0.4 + end + end, + -- open_mapping = [[]], -- mapping set in mappings.lua + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_terminals = false, + start_in_insert = true, + -- insert_mappings = true, -- see 'open_mapping', not set on purpose + -- whether or not the open mapping applies in insert mode + persist_size = true, + direction = 'vertical', + close_on_exit = true, -- close the terminal window when the process exits + -- This field is only relevant if direction is set to 'float' + float_opts = { + border = 'single', + winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + } + } +}