diff options
Diffstat (limited to 'lua/core')
-rw-r--r-- | lua/core/autocmds.lua | 109 | ||||
-rw-r--r-- | lua/core/autopairs.lua | 2 | ||||
-rw-r--r-- | lua/core/bufferline.lua | 26 | ||||
-rw-r--r-- | lua/core/commands.lua | 21 | ||||
-rw-r--r-- | lua/core/compe.lua | 33 | ||||
-rw-r--r-- | lua/core/dap.lua | 23 | ||||
-rw-r--r-- | lua/core/dashboard.lua | 26 | ||||
-rw-r--r-- | lua/core/floatterm.lua | 76 | ||||
-rw-r--r-- | lua/core/formatter.lua | 60 | ||||
-rw-r--r-- | lua/core/galaxyline.lua | 14 | ||||
-rw-r--r-- | lua/core/gitsigns.lua | 4 | ||||
-rw-r--r-- | lua/core/nvimtree.lua | 119 | ||||
-rw-r--r-- | lua/core/status_colors.lua | 2 | ||||
-rw-r--r-- | lua/core/telescope.lua | 15 | ||||
-rw-r--r-- | lua/core/terminal.lua | 91 | ||||
-rw-r--r-- | lua/core/treesitter.lua | 120 | ||||
-rw-r--r-- | lua/core/which-key.lua | 65 | ||||
-rw-r--r-- | lua/core/zen.lua | 34 |
18 files changed, 400 insertions, 440 deletions
diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua new file mode 100644 index 00000000..9280da9e --- /dev/null +++ b/lua/core/autocmds.lua @@ -0,0 +1,109 @@ +local autocommands = {} + +lvim.autocommands = { + _general_settings = { + { + "TextYankPost", + "*", + "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})", + }, + { + "BufWinEnter", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { + "BufWinEnter", + "dashboard", + "setlocal cursorline signcolumn=yes cursorcolumn number", + }, + { + "BufRead", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { + "BufNewFile", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { "BufWritePost", "lv-config.lua", "lua require('utils').reload_lv_config()" }, + { + "FileType", + "qf", + "set nobuflisted", + }, + -- { "VimLeavePre", "*", "set title set titleold=" }, + }, + _filetypechanges = { + { "BufWinEnter", ".tf", "setlocal filetype=hcl" }, + { "BufRead", "*.tf", "setlocal filetype=hcl" }, + { "BufNewFile", "*.tf", "setlocal filetype=hcl" }, + { "BufWinEnter", ".zsh", "setlocal filetype=sh" }, + { "BufRead", "*.zsh", "setlocal filetype=sh" }, + { "BufNewFile", "*.zsh", "setlocal filetype=sh" }, + }, + -- _solidity = { + -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'}, + -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'} + -- }, + -- _gemini = { + -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'}, + -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'} + -- }, + _markdown = { + { "FileType", "markdown", "setlocal wrap" }, + { "FileType", "markdown", "setlocal spell" }, + }, + _tab_bindings = { + { "FileType", "*", "lua require'core.compe'.set_tab_keybindings()" }, + }, + _buffer_bindings = { + { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" }, + }, + _auto_resize = { + -- will cause split windows to be resized evenly if main window is resized + { "VimResized", "*", "wincmd =" }, + }, + _packer_compile = { + -- will cause split windows to be resized evenly if main window is resized + { "BufWritePost", "plugins.lua", "PackerCompile" }, + }, + + -- _fterm_lazygit = { + -- -- will cause esc key to exit lazy git + -- {"TermEnter", "*", "call LazyGitNativation()"} + -- }, + -- _mode_switching = { + -- -- will switch between absolute and relative line numbers depending on mode + -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'}, + -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'}, + -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'}, + -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'}, + -- }, + custom_groups = {}, +} + +function autocommands.define_augroups(definitions) -- {{{1 + -- Create autocommand groups based on the passed definitions + -- + -- The key will be the name of the group, and each definition + -- within the group should have: + -- 1. Trigger + -- 2. Pattern + -- 3. Text + -- just like how they would normally be defined from Vim itself + for group_name, definition in pairs(definitions) do + vim.cmd("augroup " .. group_name) + vim.cmd "autocmd!" + + for _, def in pairs(definition) do + local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ") + vim.cmd(command) + end + + vim.cmd "augroup END" + end +end + +return autocommands diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index b8dad5f3..f0111db6 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -1,7 +1,7 @@ -- if not package.loaded['nvim-autopairs'] then -- return -- end -local status_ok, autopairs = pcall(require, "nvim-autopairs") +local status_ok, _ = pcall(require, "nvim-autopairs") if not status_ok then return end diff --git a/lua/core/bufferline.lua b/lua/core/bufferline.lua index d4e4b4fe..c5677580 100644 --- a/lua/core/bufferline.lua +++ b/lua/core/bufferline.lua @@ -1,28 +1,2 @@ -vim.api.nvim_set_keymap("n", "<S-x>", ":BufferClose<CR>", { noremap = true, silent = true }) vim.api.nvim_set_keymap("n", "<S-l>", ":BufferNext<CR>", { noremap = true, silent = true }) vim.api.nvim_set_keymap("n", "<S-h>", ":BufferPrevious<CR>", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>", { noremap = true, silent = true }) - -O.plugin.which_key.mappings["b"] = { - name = "Buffers", - j = { "<cmd>BufferPick<cr>", "jump to buffer" }, - f = { "<cmd>Telescope buffers<cr>", "Find buffer" }, - w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" }, - e = { - "<cmd>BufferCloseAllButCurrent<cr>", - "close all but current buffer", - }, - h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" }, - l = { - "<cmd>BufferCloseBuffersRight<cr>", - "close all BufferLines to the right", - }, - D = { - "<cmd>BufferOrderByDirectory<cr>", - "sort BufferLines automatically by directory", - }, - L = { - "<cmd>BufferOrderByLanguage<cr>", - "sort BufferLines automatically by language", - }, -} diff --git a/lua/core/commands.lua b/lua/core/commands.lua new file mode 100644 index 00000000..c42b385d --- /dev/null +++ b/lua/core/commands.lua @@ -0,0 +1,21 @@ +local M = {} + +M.defaults = { + [[ + function! QuickFixToggle() + if empty(filter(getwininfo(), 'v:val.quickfix')) + copen + else + cclose + endif + endfunction + ]], +} + +M.load = function(commands) + for _, command in ipairs(commands) do + vim.cmd(command) + end +end + +return M diff --git a/lua/core/compe.lua b/lua/core/compe.lua index c8152ad1..801e2dd8 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.completion = { + lvim.builtin.compe = { enabled = true, autocomplete = true, debug = false, @@ -30,18 +30,20 @@ M.config = function() emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } }, -- for emoji press : (idk if that in compe tho) }, + -- FileTypes in this list won't trigger auto-complete when TAB is pressed. Hitting TAB will insert a tab character + exclude_filetypes = { "md", "markdown", "mdown", "mkd", "mkdn", "mdwn", "text", "txt" }, } end M.setup = function() - vim.g.vsnip_snippet_dir = O.vsnip_dir + vim.g.vsnip_snippet_dir = lvim.vsnip_dir local status_ok, compe = pcall(require, "compe") if not status_ok then return end - compe.setup(O.completion) + compe.setup(lvim.builtin.compe) local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) @@ -81,16 +83,29 @@ M.setup = function() end end - vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true }) + -- vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true }) vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", { noremap = true, silent = true, expr = true }) vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true }) vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true }) end +local is_excluded = function(file_type) + for _, type in ipairs(lvim.builtin.compe.exclude_filetypes) do + if type == file_type then + return true + end + end + return false +end + +M.set_tab_keybindings = function() + local file_type = vim.fn.expand "%:e" + if is_excluded(file_type) == false then + vim.api.nvim_buf_set_keymap(0, "i", "<Tab>", "v:lua.tab_complete()", { expr = true }) + vim.api.nvim_buf_set_keymap(0, "s", "<Tab>", "v:lua.tab_complete()", { expr = true }) + vim.api.nvim_buf_set_keymap(0, "i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) + vim.api.nvim_buf_set_keymap(0, "s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) + end +end return M diff --git a/lua/core/dap.lua b/lua/core/dap.lua index bc76e221..30e3aef9 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.dap = { + lvim.builtin.dap = { active = false, breakpoint = { text = "", @@ -17,10 +17,10 @@ M.setup = function() return end - vim.fn.sign_define("DapBreakpoint", O.plugin.dap.breakpoint) + vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" - O.user_which_key["d"] = { + lvim.builtin.which_key.mappings["d"] = { name = "Debug", t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" }, b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" }, @@ -38,4 +38,21 @@ M.setup = function() } end +-- TODO put this up there ^^^ call in ftplugin + +-- M.dap = function() +-- if lvim.plugin.dap.active then +-- local dap_install = require "dap-install" +-- dap_install.config("python_dbg", {}) +-- end +-- end +-- +-- M.dap = function() +-- -- gem install readapt ruby-debug-ide +-- if lvim.plugin.dap.active then +-- local dap_install = require "dap-install" +-- dap_install.config("ruby_vsc_dbg", {}) +-- end +-- end + return M diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index e58b6f06..8d196458 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.dashboard = { + lvim.builtin.dashboard = { active = false, search_handler = "telescope", custom_header = { @@ -43,7 +43,8 @@ M.config = function() }, d = { description = { " Settings " }, - command = ":e " .. CONFIG_PATH .. "/lv-config.lua", + -- command = ":e " .. CONFIG_PATH .. "/lv-config.lua", + command = ":e ~/.config/lvim/lv-config.lua", }, }, @@ -54,23 +55,25 @@ end M.setup = function() vim.g.dashboard_disable_at_vimenter = 0 - vim.g.dashboard_custom_header = O.plugin.dashboard.custom_header + vim.g.dashboard_custom_header = lvim.builtin.dashboard.custom_header - vim.g.dashboard_default_executive = O.plugin.dashboard.search_handler + vim.g.dashboard_default_executive = lvim.builtin.dashboard.search_handler - vim.g.dashboard_custom_section = O.plugin.dashboard.custom_section + vim.g.dashboard_custom_section = lvim.builtin.dashboard.custom_section + + lvim.builtin.which_key.mappings[";"] = { "<cmd>Dashboard<CR>", "Dashboard" } -- f = { -- description = { " Neovim Config Files" }, -- command = "Telescope find_files cwd=" .. CONFIG_PATH, -- }, -- e = {description = {' Marks '}, command = 'Telescope marks'} - vim.cmd "let g:dashboard_session_directory = $HOME..'/.config/nvim/.sessions'" - vim.cmd "let packages = len(globpath('~/.local/share/nvim/site/pack/packer/start', '*', 0, 1))" + vim.cmd 'let g:dashboard_session_directory = "~/.config/lvim/.sessions"' + vim.cmd "let packages = len(globpath('~/.local/share/lunarvim/site/pack/packer/start', '*', 0, 1))" vim.api.nvim_exec( [[ - let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' plugins'] + let g:dashboard_custom_footer = ['LunarVim loaded '..packages..' plugins '] ]], false ) @@ -78,8 +81,9 @@ M.setup = function() -- file_browser = {description = {' File Browser'}, command = 'Telescope find_files'}, -- vim.g.dashboard_session_directory = CACHE_PATH..'/session' - -- vim.g.dashboard_custom_footer = O.dashboard.footer - require("lv-utils").define_augroups { + -- vim.g.dashboard_custom_footer = lvim.dashboard.footer + + require("core.autocmds").define_augroups { _dashboard = { -- seems to be nobuflisted that makes my stuff disapear will do more testing { @@ -90,7 +94,7 @@ M.setup = function() { "FileType", "dashboard", - "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=2", + "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=" .. vim.opt.showtabline._value, }, { "FileType", "dashboard", "nnoremap <silent> <buffer> q :q<CR>" }, }, diff --git a/lua/core/floatterm.lua b/lua/core/floatterm.lua deleted file mode 100644 index 3d7e0e6e..00000000 --- a/lua/core/floatterm.lua +++ /dev/null @@ -1,76 +0,0 @@ -local M = {} -M.config = function() - O.plugin.floatterm = { - active = false, - dimensions = { - height = 0.9, - width = 0.9, - x = 0.5, - y = 0.3, - }, - border = "single", -- or 'double' - } -end - -M.setup = function() - local status_ok, fterm = pcall(require, "FTerm") - if not status_ok then - return - end - - fterm.setup(O.plugin.floatterm) - - -- Create LazyGit Terminal - local term = require "FTerm.terminal" - local lazy = term:new():setup { - cmd = "lazygit", - dimensions = O.plugin.floatterm.dimensions, - } - - local function is_installed(exe) - return vim.fn.executable(exe) == 1 - end - - -- Use this to toggle gitui in a floating terminal - function _G.__fterm_lazygit() - if is_installed "lazygit" ~= true then - print "Please install lazygit. Check documentation for more information" - return - end - lazy:toggle() - end - - -- Map esc to exit inside lazygit - -- vim.api.nvim_exec( - -- [[ - -- function LazyGitNativation() - -- echom &filetype - -- if &filetype ==# 'FTerm' - -- tnoremap <Esc> q - -- tnoremap <C-v><Esc> <Esc> - -- endif - -- endfunction - -- ]], - -- false - -- ) - - O.plugin.which_key.mappings["gg"] = "LazyGit" - vim.api.nvim_set_keymap("n", "<A-i>", "<CMD>lua require('FTerm').toggle()<CR>", { noremap = true, silent = true }) - vim.api.nvim_set_keymap("n", "<leader>gg", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true }) - - vim.api.nvim_set_keymap( - "t", - "<A-i>", - "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>", - { noremap = true, silent = true } - ) - vim.api.nvim_set_keymap("n", "<A-l>", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true }) - vim.api.nvim_set_keymap( - "t", - "<A-l>", - "<C-\\><C-n><CMD>lua _G.__fterm_lazygit()<CR>", - { noremap = true, silent = true } - ) -end - -return M diff --git a/lua/core/formatter.lua b/lua/core/formatter.lua deleted file mode 100644 index 05de74ab..00000000 --- a/lua/core/formatter.lua +++ /dev/null @@ -1,60 +0,0 @@ --- autoformat -if O.format_on_save then - require("lv-utils").define_augroups { - autoformat = { - { - "BufWritePost", - "*", - ":silent FormatWrite", - }, - }, - } -end - --- -- check if formatter has been defined for the language or not --- local function formatter_exists(lang_formatter) --- if lang_formatter == nil then --- return false --- end --- if lang_formatter.exe == nil or lang_formatter.args == nil then --- return false --- end --- return true --- end - --- returns default formatter for given language --- local function formatter_return(lang_formatter) --- return { --- exe = lang_formatter.exe, --- args = lang_formatter.args, --- stdin = not (lang_formatter.stdin ~= nil), --- } --- end - --- fill a table like this -> {rust: {exe:"sth",args:{"a","b"},stdin=true},go: {}...} --- local formatter_filetypes = {} --- for k, v in pairs(O.lang) do --- if formatter_exists(v.formatter) then --- local keys = v.filetypes --- if keys == nil then --- keys = { k } --- end --- for _, l in pairs(keys) do --- formatter_filetypes[l] = { --- function() --- return formatter_return(v.formatter) --- end, --- } --- end --- end --- end -local status_ok, formatter = pcall(require, "formatter") -if not status_ok then - return -end - -if not O.format_on_save then - vim.cmd [[if exists('#autoformat#BufWritePost') - :autocmd! autoformat - endif]] -end diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua index 281202a8..abc7c369 100644 --- a/lua/core/galaxyline.lua +++ b/lua/core/galaxyline.lua @@ -7,9 +7,9 @@ if not status_ok then end -- NOTE: if someone defines colors but doesn't have them then this will break -local palette_status_ok, colors = pcall(require, O.colorscheme .. ".palette") +local palette_status_ok, colors = pcall(require, lvim.colorscheme .. ".palette") if not palette_status_ok then - colors = O.plugin.galaxyline.colors + colors = lvim.builtin.galaxyline.colors end local condition = require "galaxyline.condition" @@ -266,7 +266,11 @@ table.insert(gls.right, { table.insert(gls.right, { Tabstop = { provider = function() - return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " + local label = "Spaces: " + if not vim.api.nvim_buf_get_option(0, "expandtab") then + label = "Tab size: " + end + return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " end, condition = condition.hide_in_width, separator = " ", @@ -311,7 +315,7 @@ table.insert(gls.short_line_left, { provider = "FileTypeName", separator = " ", separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, + highlight = { colors.alt_bg, colors.alt_bg }, }, }) @@ -319,7 +323,7 @@ table.insert(gls.short_line_left, { SFileName = { provider = "SFileName", condition = condition.buffer_not_empty, - highlight = { colors.grey, colors.alt_bg }, + highlight = { colors.alt_bg, colors.alt_bg }, }, }) diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index bc310ad6..2a5060be 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.gitsigns = { + lvim.builtin.gitsigns = { signs = { add = { hl = "GitSignsAdd", @@ -53,7 +53,7 @@ M.setup = function() if not status_ok then return end - gitsigns.setup(O.plugin.gitsigns) + gitsigns.setup(lvim.builtin.gitsigns) end return M diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index cb3eacea..dd1f4f36 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -1,86 +1,87 @@ --- --if not package.loaded['nvim-tree.view'] then --- -- return --- --end --- local M = {} -local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") -if not status_ok then - return +-- +M.config = function() + lvim.builtin.nvimtree = { + side = "left", + show_icons = { + git = 1, + folders = 1, + files = 1, + folder_arrows = 1, + tree_width = 30, + }, + ignore = { ".git", "node_modules", ".cache" }, + auto_open = 1, + auto_close = 1, + quit_on_open = 0, + follow = 1, + hide_dotfiles = 1, + git_hl = 1, + root_folder_modifier = ":t", + tab_open = 0, + allow_resize = 1, + lsp_diagnostics = 1, + auto_ignore_ft = { "startify", "dashboard" }, + icons = { + default = "", + symlink = "", + git = { + unstaged = "", + staged = "S", + unmerged = "", + renamed = "➜", + deleted = "", + untracked = "U", + ignored = "◌", + }, + folder = { + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + }, + }, + } end -- M.setup = function() + local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") + if not status_ok then + return + end local g = vim.g - vim.o.termguicolors = true - - g.nvim_tree_side = "left" - g.nvim_tree_width = 30 - g.nvim_tree_ignore = { ".git", "node_modules", ".cache" } - g.nvim_tree_auto_open = 1 - g.nvim_tree_auto_close = 1 - g.nvim_tree_quit_on_open = 0 - g.nvim_tree_follow = 1 - g.nvim_tree_indent_markers = 1 - g.nvim_tree_hide_dotfiles = 1 - g.nvim_tree_git_hl = 1 - g.nvim_tree_root_folder_modifier = ":t" - g.nvim_tree_tab_open = 0 - g.nvim_tree_allow_resize = 1 - g.nvim_tree_lsp_diagnostics = 1 - g.nvim_tree_auto_ignore_ft = { "startify", "dashboard" } - - g.nvim_tree_show_icons = { - git = 1, - folders = 1, - files = 1, - folder_arrows = 1, - } + for opt, val in pairs(lvim.builtin.nvimtree) do + g["nvim_tree_" .. opt] = val + end - vim.g.nvim_tree_icons = { - default = "", - symlink = "", - git = { - unstaged = "", - staged = "S", - unmerged = "", - renamed = "➜", - deleted = "", - untracked = "U", - ignored = "◌", - }, - folder = { - default = "", - open = "", - empty = "", - empty_open = "", - symlink = "", - }, - } local tree_cb = nvim_tree_config.nvim_tree_callback - vim.g.nvim_tree_bindings = { + g.nvim_tree_bindings = { { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, } end - -local view_status_ok, view = pcall(require, "nvim-tree.view") -if not view_status_ok then - return -end +-- +-- M.toggle_tree = function() + local view_status_ok, view = pcall(require, "nvim-tree.view") + if not view_status_ok then + return + end if view.win_open() then require("nvim-tree").close() if package.loaded["bufferline.state"] then require("bufferline.state").set_offset(0) end else - if package.loaded["bufferline.state"] then + if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then -- require'bufferline.state'.set_offset(31, 'File Explorer') require("bufferline.state").set_offset(31, "") end - require("nvim-tree").find_file(true) + require("nvim-tree").toggle() end end -- diff --git a/lua/core/status_colors.lua b/lua/core/status_colors.lua index ddb4aa98..37e9d7c9 100644 --- a/lua/core/status_colors.lua +++ b/lua/core/status_colors.lua @@ -1,4 +1,4 @@ -O.plugin.galaxyline = { +lvim.builtin.galaxyline = { active = true, colors = { alt_bg = "#2E2E2E", diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 5a067d67..65760d6c 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -5,17 +5,9 @@ M.config = function() return end - O.plugin.telescope = { + lvim.builtin.telescope = { active = false, defaults = { - find_command = { - "rg", - "--no-heading", - "--with-filename", - "--line-number", - "--column", - "--smart-case", - }, prompt_prefix = " ", selection_caret = " ", entry_prefix = " ", @@ -33,7 +25,7 @@ M.config = function() file_sorter = require("telescope.sorters").get_fzy_sorter, file_ignore_patterns = {}, generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, - path_display = { "shorten" }, + path_display = { shorten = 5 }, winblend = 0, border = {}, borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, @@ -89,8 +81,7 @@ M.setup = function() if not status_ok then return end - telescope.setup(O.plugin.telescope) - vim.api.nvim_set_keymap("n", "<Leader>f", ":Telescope find_files<CR>", { noremap = true, silent = true }) + telescope.setup(lvim.builtin.telescope) end return M diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua new file mode 100644 index 00000000..015341df --- /dev/null +++ b/lua/core/terminal.lua @@ -0,0 +1,91 @@ +local M = {} +M.config = function() + lvim.builtin["terminal"] = { + -- size can be a number or function which is passed the current terminal + size = 5, + -- open_mapping = [[<c-\>]], + open_mapping = [[<c-t>]], + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_filetypes = {}, + shade_terminals = true, + shading_factor = 2, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + start_in_insert = true, + insert_mappings = true, -- whether or not the open mapping applies in insert mode + persist_size = true, + -- direction = 'vertical' | 'horizontal' | 'window' | 'float', + direction = "float", + close_on_exit = true, -- close the terminal window when the process exits + shell = vim.o.shell, -- change the default shell + -- This field is only relevant if direction is set to 'float' + float_opts = { + -- The border key is *almost* the same as 'nvim_win_open' + -- see :h nvim_win_open for details on borders however + -- the 'curved' border is a custom border type + -- not natively supported but implemented in this plugin. + -- border = 'single' | 'double' | 'shadow' | 'curved' | ... other options supported by win open + border = "curved", + -- width = <value>, + -- height = <value>, + winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + }, + }, + -- Add executables on the lv-config file + -- { exec, keymap, name} + -- lvim.builtin.terminal.execs = {{}} to overwrite + -- lvim.builtin.terminal.execs[#lvim.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"} + execs = { { "lazygit", "gg", "LazyGit" } }, + } +end + +M.setup = function() + local status_ok, terminal = pcall(require, "toggleterm") + if not status_ok then + print(terminal) + return + end + for _, exec in pairs(lvim.builtin.terminal.execs) do + require("core.terminal").add_exec(exec[1], exec[2], exec[3]) + end + terminal.setup(lvim.builtin.terminal) +end + +local function is_installed(exe) + return vim.fn.executable(exe) == 1 +end + +M.add_exec = function(exec, keymap, name) + vim.api.nvim_set_keymap( + "n", + "<leader>" .. keymap, + "<cmd>lua require('core.terminal')._exec_toggle('" .. exec .. "')<CR>", + { noremap = true, silent = true } + ) + lvim.builtin.which_key.mappings[keymap] = name +end + +M._split = function(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t = {} + for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do + table.insert(t, str) + end + return t +end + +M._exec_toggle = function(exec) + local binary = M._split(exec)[1] + if is_installed(binary) ~= true then + print("Please install executable " .. binary .. ". Check documentation for more information") + return + end + local Terminal = require("toggleterm.terminal").Terminal + local exec_term = Terminal:new { cmd = exec, hidden = true } + exec_term:toggle() +end + +return M diff --git a/lua/core/treesitter.lua b/lua/core/treesitter.lua index 2b7a2d54..cfc58bb7 100644 --- a/lua/core/treesitter.lua +++ b/lua/core/treesitter.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.treesitter = { + lvim.builtin.treesitter = { ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages ignore_install = {}, matchup = { @@ -18,7 +18,7 @@ M.config = function() }, -- indent = {enable = true, disable = {"python", "html", "javascript"}}, -- TODO seems to be broken - indent = { enable = { "javascriptreact" } }, + indent = { enable = true, disable = { "yaml" } }, autotag = { enable = false }, textobjects = { swap = { @@ -59,129 +59,15 @@ M.config = function() max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int }, } - - -- -- TODO refactor treesitter - -- -- @usage pass a table with your desired languages - -- treesitter = { - -- ensure_installed = "all", - -- ignore_install = { "haskell" }, - -- highlight = { enabled = true }, - -- -- The below are for treesitter-textobjects plugin - -- textobj_prefixes = { - -- goto_next = "]", -- Go to next - -- goto_previous = "[", -- Go to previous - -- inner = "i", -- Select inside - -- outer = "a", -- Selct around - -- swap = "<leader>a", -- Swap with next - -- }, - -- textobj_suffixes = { - -- -- Start and End respectively for the goto keys - -- -- for other keys it only uses the first - -- ["function"] = { "f", "F" }, - -- ["class"] = { "m", "M" }, - -- ["parameter"] = { "a", "A" }, - -- ["block"] = { "k", "K" }, - -- ["conditional"] = { "i", "I" }, - -- ["call"] = { "c", "C" }, - -- ["loop"] = { "l", "L" }, - -- ["statement"] = { "s", "S" }, - -- ["comment"] = { "/", "?" }, - -- }, - -- -- The below is for treesitter hint textobjects plugin - -- hint_labels = { "h", "j", "f", "d", "n", "v", "s", "l", "a" }, - -- }, end M.setup = function() - -- TODO: refacor this whole file and treesitter in general - -- if not package.loaded['nvim-treesitter'] then return end - -- - -- Custom parsers - -- local parser_config = require("nvim-treesitter.parsers").get_parser_configs() - -- parser_config.make = { - -- install_info = { - -- url = "https://github.com/alemuller/tree-sitter-make", -- local path or git repo - -- files = {"src/parser.c"}, - -- requires_generate_from_grammar = true - -- } - -- } - -- parser_config.just = { - -- install_info = { - -- url = "~/dev/tree-sitter-just", -- local path or git repo - -- files = {"src/parser.c"} - -- } - -- -- filetype = "just", -- if filetype does not agrees with parser name - -- -- used_by = {"bar", "baz"} -- additional filetypes that use this parser - -- } - -- Custom text objects - -- local textobj_prefixes = O.treesitter.textobj_prefixes - -- local textobj_suffixes = O.treesitter.textobj_suffixes - -- local textobj_sel_keymaps = {} - -- local textobj_swap_keymaps = {} - -- local textobj_move_keymaps = { - -- enable = O.plugin.ts_textobjects, - -- set_jumps = true, -- whether to set jumps in the jumplist - -- goto_next_start = {}, - -- goto_next_end = {}, - -- goto_previous_start = {}, - -- goto_previous_end = {}, - -- } - -- for obj, suffix in pairs(textobj_suffixes) do - -- if textobj_prefixes["goto_next"] ~= nil then - -- textobj_move_keymaps["goto_next_start"][textobj_prefixes["goto_next"] .. suffix[1]] = "@" .. obj .. ".outer" - -- textobj_move_keymaps["goto_next_end"][textobj_prefixes["goto_next"] .. suffix[2]] = "@" .. obj .. ".outer" - -- end - -- if textobj_prefixes["goto_previous"] ~= nil then - -- textobj_move_keymaps["goto_previous_start"][textobj_prefixes["goto_previous"] .. suffix[2]] = "@" .. obj .. ".outer" - -- textobj_move_keymaps["goto_previous_end"][textobj_prefixes["goto_previous"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- - -- if textobj_prefixes["inner"] ~= nil then - -- textobj_sel_keymaps[textobj_prefixes["inner"] .. suffix[1]] = "@" .. obj .. ".inner" - -- end - -- if textobj_prefixes["outer"] ~= nil then - -- textobj_sel_keymaps[textobj_prefixes["outer"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- - -- if textobj_prefixes["swap"] ~= nil then - -- textobj_swap_keymaps[textobj_prefixes["swap"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- end - -- vim.g.ts_hint_textobject_keys = O.treesitter.hint_labels -- Requires https://github.com/mfussenegger/nvim-ts-hint-textobject/pull/2 - -- - -- -- Add which key menu entries - -- local status, wk = pcall(require, "which-key") - -- if status then - -- local normal = { - -- mode = "n", -- Normal mode - -- } - -- local operators = { - -- mode = "o", -- Operator mode - -- } - -- wk.register(textobj_sel_keymaps, operators) - -- wk.register({ - -- ["m"] = "Hint Objects", - -- ["."] = "Textsubject", - -- [";"] = "Textsubject-big", - -- }, operators) - -- wk.register(textobj_swap_keymaps, normal) - -- wk.register({ - -- [textobj_prefixes["swap"]] = "Swap", - -- -- [textobj_prefixes["goto_next"]] = "Jump [", - -- -- [textobj_prefixes["goto_previous"]] = "Jump ]" - -- }, normal) - -- wk.register(textobj_move_keymaps["goto_next_start"], normal) - -- wk.register(textobj_move_keymaps["goto_next_end"], normal) - -- wk.register(textobj_move_keymaps["goto_previous_start"], normal) - -- wk.register(textobj_move_keymaps["goto_previous_end"], normal) - -- end - local status_ok, treesitter_configs = pcall(require, "nvim-treesitter.configs") if not status_ok then return end - treesitter_configs.setup(O.treesitter) + treesitter_configs.setup(lvim.builtin.treesitter) end return M diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index c3255705..9d4e7744 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.which_key = { + lvim.builtin.which_key = { active = false, setup = { plugins = { @@ -64,16 +64,38 @@ M.config = function() ["w"] = { "<cmd>w!<CR>", "Save" }, ["q"] = { "<cmd>q!<CR>", "Quit" }, ["/"] = { "<cmd>CommentToggle<CR>", "Comment" }, - ["c"] = { "<cmd>BufferClose<CR>", "Close Buffer" }, + ["c"] = { "<cmd>BufferClose!<CR>", "Close Buffer" }, ["e"] = { "<cmd>lua require'core.nvimtree'.toggle_tree()<CR>", "Explorer" }, ["f"] = { "<cmd>Telescope find_files<CR>", "Find File" }, ["h"] = { '<cmd>let @/=""<CR>', "No Highlight" }, - [";"] = { "<cmd>Dashboard<CR>", "Dashboard" }, + b = { + name = "Buffers", + j = { "<cmd>BufferPick<cr>", "jump to buffer" }, + f = { "<cmd>Telescope buffers<cr>", "Find buffer" }, + w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" }, + e = { + "<cmd>BufferCloseAllButCurrent<cr>", + "close all but current buffer", + }, + h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" }, + l = { + "<cmd>BufferCloseBuffersRight<cr>", + "close all BufferLines to the right", + }, + D = { + "<cmd>BufferOrderByDirectory<cr>", + "sort BufferLines automatically by directory", + }, + L = { + "<cmd>BufferOrderByLanguage<cr>", + "sort BufferLines automatically by language", + }, + }, p = { name = "Packer", c = { "<cmd>PackerCompile<cr>", "Compile" }, i = { "<cmd>PackerInstall<cr>", "Install" }, - r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" }, + r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload" }, s = { "<cmd>PackerSync<cr>", "Sync" }, u = { "<cmd>PackerUpdate<cr>", "Update" }, }, @@ -118,19 +140,21 @@ M.config = function() "<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics", }, - f = { "<cmd>silent FormatWrite<cr>", "Format" }, + -- f = { "<cmd>silent FormatWrite<cr>", "Format" }, + f = { "<cmd>lua vim.lsp.buf.formatting()<cr>", "Format" }, i = { "<cmd>LspInfo<cr>", "Info" }, j = { - "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>", + "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<cr>", "Next Diagnostic", }, k = { - "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>", + "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<cr>", "Prev Diagnostic", }, + l = { "<cmd>silent lua require('lint').try_lint()<cr>", "Lint" }, q = { "<cmd>Telescope quickfix<cr>", "Quickfix" }, r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" }, - s = { "<cmd> Telescope lsp_document_symbols<cr>", "Document Symbols" }, + s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" }, S = { "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>", "Workspace Symbols", @@ -149,6 +173,10 @@ M.config = function() t = { "<cmd>Telescope live_grep<cr>", "Text" }, k = { "<cmd>Telescope keymaps<cr>", "Keymaps" }, C = { "<cmd>Telescope commands<cr>", "Commands" }, + p = { + "<cmd>lua require('telescope.builtin.internal').colorscheme({enable_preview = true})<cr>", + "Colorscheme with Preview", + }, }, T = { name = "Treesitter", @@ -167,29 +195,18 @@ M.setup = function() return end - which_key.setup(O.plugin.which_key.setup) - - local opts = O.plugin.which_key.opts - local vopts = O.plugin.which_key.vopts + which_key.setup(lvim.builtin.which_key.setup) - local mappings = O.plugin.which_key.mappings - local vmappings = O.plugin.which_key.vmappings + local opts = lvim.builtin.which_key.opts + local vopts = lvim.builtin.which_key.vopts - -- if O.plugin.ts_playground.active then - -- vim.api.nvim_set_keymap("n", "<leader>Th", ":TSHighlightCapturesUnderCursor<CR>", { noremap = true, silent = true }) - -- mappings[""] = "Highlight Capture" - -- end - - if O.plugin.zen.active then - vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true }) - mappings["z"] = "Zen" - end + local mappings = lvim.builtin.which_key.mappings + local vmappings = lvim.builtin.which_key.vmappings local wk = require "which-key" wk.register(mappings, opts) wk.register(vmappings, vopts) - wk.register(O.user_which_key, opts) end return M diff --git a/lua/core/zen.lua b/lua/core/zen.lua deleted file mode 100644 index 99a5d769..00000000 --- a/lua/core/zen.lua +++ /dev/null @@ -1,34 +0,0 @@ -local M = {} -M.config = function() - O.plugin["zen"] = { - window = { - backdrop = 1, - height = 0.85, -- height of the Zen window - options = { - signcolumn = "no", -- disable signcolumn - number = false, -- disable number column - relativenumber = false, -- disable relative numbers - -- cursorline = false, -- disable cursorline - -- cursorcolumn = false, -- disable cursor column - -- foldcolumn = "0", -- disable fold column - -- list = false, -- disable whitespace characters - }, - }, - plugins = { - gitsigns = { enabled = false }, -- disables git signs - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below - }, - } -end - -M.setup = function() - local status_ok, zen_mode = pcall(require, "zen-mode") - if not status_ok then - return - end - zen_mode.setup(O.plugin.zen) -end - -return M |