diff options
| author | christianchiarulli <[email protected]> | 2021-07-12 21:11:43 -0400 | 
|---|---|---|
| committer | christianchiarulli <[email protected]> | 2021-07-12 21:11:43 -0400 | 
| commit | 2423fcdc904ec1413edaaac1fd8b9c0971f4a869 (patch) | |
| tree | 388a51b436b364009dc83e301270657f40d8212a /lua/core | |
| parent | 476f7bb22f1d6d696ad9c2e2cc6e574167aef841 (diff) | |
refactor single file
Diffstat (limited to 'lua/core')
| -rw-r--r-- | lua/core/autopairs.lua | 51 | ||||
| -rw-r--r-- | lua/core/bufferline.lua | 28 | ||||
| -rw-r--r-- | lua/core/compe.lua | 96 | ||||
| -rw-r--r-- | lua/core/dap.lua | 41 | ||||
| -rw-r--r-- | lua/core/dashboard.lua | 100 | ||||
| -rw-r--r-- | lua/core/floatterm.lua | 76 | ||||
| -rw-r--r-- | lua/core/formatter.lua | 61 | ||||
| -rw-r--r-- | lua/core/galaxyline.lua | 353 | ||||
| -rw-r--r-- | lua/core/nvimtree.lua | 87 | ||||
| -rw-r--r-- | lua/core/telescope.lua | 94 | ||||
| -rw-r--r-- | lua/core/treesitter.lua | 187 | ||||
| -rw-r--r-- | lua/core/which-key.lua | 197 | ||||
| -rw-r--r-- | lua/core/zen.lua | 34 | 
13 files changed, 1405 insertions, 0 deletions
| diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua new file mode 100644 index 00000000..b8dad5f3 --- /dev/null +++ b/lua/core/autopairs.lua @@ -0,0 +1,51 @@ +-- if not package.loaded['nvim-autopairs'] then +--   return +-- end +local status_ok, autopairs = pcall(require, "nvim-autopairs") +if not status_ok then +  return +end +local npairs = require "nvim-autopairs" +local Rule = require "nvim-autopairs.rule" + +-- skip it, if you use another global object +_G.MUtils = {} + +vim.g.completion_confirm_key = "" +MUtils.completion_confirm = function() +  if vim.fn.pumvisible() ~= 0 then +    if vim.fn.complete_info()["selected"] ~= -1 then +      return vim.fn["compe#confirm"](npairs.esc "<cr>") +    else +      return npairs.esc "<cr>" +    end +  else +    return npairs.autopairs_cr() +  end +end + +if package.loaded["compe"] then +  require("nvim-autopairs.completion.compe").setup { +    map_cr = true, --  map <CR> on insert mode +    map_complete = true, -- it will auto insert `(` after select function or method item +  } +end + +npairs.setup { +  check_ts = true, +  ts_config = { +    lua = { "string" }, -- it will not add pair on that treesitter node +    javascript = { "template_string" }, +    java = false, -- don't check treesitter on java +  }, +} + +require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + +local ts_conds = require "nvim-autopairs.ts-conds" + +-- press % => %% is only inside comment or string +npairs.add_rules { +  Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), +  Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), +} diff --git a/lua/core/bufferline.lua b/lua/core/bufferline.lua new file mode 100644 index 00000000..d4e4b4fe --- /dev/null +++ b/lua/core/bufferline.lua @@ -0,0 +1,28 @@ +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/compe.lua b/lua/core/compe.lua new file mode 100644 index 00000000..ca8d6394 --- /dev/null +++ b/lua/core/compe.lua @@ -0,0 +1,96 @@ +local M = {} +M.config = function() +  O.completion = { +    enabled = true, +    autocomplete = true, +    debug = false, +    min_length = 1, +    preselect = "enable", +    throttle_time = 80, +    source_timeout = 200, +    incomplete_delay = 400, +    max_abbr_width = 100, +    max_kind_width = 100, +    max_menu_width = 100, +    documentation = true, + +    source = { +      path = { kind = "   (Path)" }, +      buffer = { kind = "   (Buffer)" }, +      calc = { kind = "   (Calc)" }, +      vsnip = { kind = "   (Snippet)" }, +      nvim_lsp = { kind = "   (LSP)" }, +      nvim_lua = false, +      spell = { kind = "   (Spell)" }, +      tags = false, +      vim_dadbod_completion = false, +      snippets_nvim = false, +      ultisnips = false, +      treesitter = false, +      emoji = { kind = " ﲃ  (Emoji)", filetypes = { "markdown", "text" } }, +      -- for emoji press : (idk if that in compe tho) +    }, +  } +end + +M.setup = function() +  vim.g.vsnip_snippet_dir = O.vnsip_dir + +  local status_ok, compe = pcall(require, "compe") +  if not status_ok then +    return +  end + +  compe.setup(O.completion) + +  local t = function(str) +    return vim.api.nvim_replace_termcodes(str, true, true, true) +  end + +  local check_back_space = function() +    local col = vim.fn.col "." - 1 +    if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then +      return true +    else +      return false +    end +  end + +  -- Use (s-)tab to: +  --- move to prev/next item in completion menuone +  --- jump to prev/next snippet's placeholder +  _G.tab_complete = function() +    if vim.fn.pumvisible() == 1 then +      return t "<C-n>" +    elseif vim.fn.call("vsnip#available", { 1 }) == 1 then +      return t "<Plug>(vsnip-expand-or-jump)" +    elseif check_back_space() then +      return t "<Tab>" +    else +      return vim.fn["compe#complete"]() +    end +  end + +  _G.s_tab_complete = function() +    if vim.fn.pumvisible() == 1 then +      return t "<C-p>" +    elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then +      return t "<Plug>(vsnip-jump-prev)" +    else +      return t "<S-Tab>" +    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", "<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 + +return M diff --git a/lua/core/dap.lua b/lua/core/dap.lua new file mode 100644 index 00000000..bc76e221 --- /dev/null +++ b/lua/core/dap.lua @@ -0,0 +1,41 @@ +local M = {} +M.config = function() +  O.plugin.dap = { +    active = false, +    breakpoint = { +      text = "", +      texthl = "LspDiagnosticsSignError", +      linehl = "", +      numhl = "", +    }, +  } +end + +M.setup = function() +  local status_ok, dap = pcall(require, "dap") +  if not status_ok then +    return +  end + +  vim.fn.sign_define("DapBreakpoint", O.plugin.dap.breakpoint) +  dap.defaults.fallback.terminal_win_cmd = "50vsplit new" + +  O.user_which_key["d"] = { +    name = "Debug", +    t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" }, +    b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" }, +    c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" }, +    C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" }, +    d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" }, +    g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" }, +    i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" }, +    o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" }, +    u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" }, +    p = { "<cmd>lua require'dap'.pause.toggle()<cr>", "Pause" }, +    r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" }, +    s = { "<cmd>lua require'dap'.continue()<cr>", "Start" }, +    q = { "<cmd>lua require'dap'.stop()<cr>", "Quit" }, +  } +end + +return M diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua new file mode 100644 index 00000000..e58b6f06 --- /dev/null +++ b/lua/core/dashboard.lua @@ -0,0 +1,100 @@ +local M = {} +M.config = function() +  O.plugin.dashboard = { +    active = false, +    search_handler = "telescope", +    custom_header = { +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣾⠿⠿⠟⠛⠛⠛⠛⠿⠿⣿⣷⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "  ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⡿⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠿⣷⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⡿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠒⠂⠉⠉⠉⠉⢩⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠸⡀⠀⠀⠀⠀⠀⢰⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠠⡀⠀⠀⢀⣾⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⢀⣸⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡧⢄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡇⠀⠈⠁⠒⠤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣇⠀⠀⠀⠀⠀⠀⠉⠢⠤⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡟⠈⠑⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠑⠒⠤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⡇⠀⠀⢀⣣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠀⠀⠒⠢⠤⠄⣀⣀⠀⠀⠀⢠⣿⡟⠀⠀⠀⣺⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +      "⠀⣿⠇⠀⠀⠀⠀⠀⣤⡄⠀⠀⢠⣤⡄⠀⢨⣭⣠⣤⣤⣤⡀⠀⠀⢀⣤⣤⣤⣤⡄⠀⠀⠀⣤⣄⣤⣤⣤⠀⠀⣿⣯⠉⠉⣿⡟⠀⠈⢩⣭⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤", +      "⢠⣿⠀⠀⠀⠀⠀⠀⣿⠃⠀⠀⣸⣿⠁⠀⣿⣿⠉⠀⠈⣿⡇⠀⠀⠛⠋⠀⠀⢹⣿⠀⠀⠀⣿⠏⠀⠸⠿⠃⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿", +      "⣸⡇⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⣿⡟⠀⢠⣿⡇⠀⠀⢰⣿⡇⠀⣰⣾⠟⠛⠛⣻⡇⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏", +      "⣿⣧⣤⣤⣤⡄⠀⠘⣿⣤⣤⡤⣿⠇⠀⢸⣿⠁⠀⠀⣼⣿⠀⠀⢿⣿⣤⣤⠔⣿⠃⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃", +      "⠉⠉⠉⠉⠉⠁⠀⠀⠈⠉⠉⠀⠉⠀⠀⠈⠉⠀⠀⠀⠉⠉⠀⠀⠀⠉⠉⠁⠈⠉⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀", +    }, + +    custom_section = { +      a = { +        description = { "  Find File          " }, +        command = "Telescope find_files", +      }, +      b = { +        description = { "  Recently Used Files" }, +        command = "Telescope oldfiles", +      }, +      -- c = { +      --   description = { "  Load Last Session  " }, +      --   command = "SessionLoad", +      -- }, +      c = { +        description = { "  Find Word          " }, +        command = "Telescope live_grep", +      }, +      d = { +        description = { "  Settings           " }, +        command = ":e " .. CONFIG_PATH .. "/lv-config.lua", +      }, +    }, + +    footer = { "chrisatmachine.com" }, +  } +end + +M.setup = function() +  vim.g.dashboard_disable_at_vimenter = 0 + +  vim.g.dashboard_custom_header = O.plugin.dashboard.custom_header + +  vim.g.dashboard_default_executive = O.plugin.dashboard.search_handler + +  vim.g.dashboard_custom_section = O.plugin.dashboard.custom_section + +  -- 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.api.nvim_exec( +    [[ +    let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' plugins'] +]], +    false +  ) + +  -- 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 { +    _dashboard = { +      -- seems to be nobuflisted that makes my stuff disapear will do more testing +      { +        "FileType", +        "dashboard", +        "setlocal nocursorline noswapfile synmaxcol& signcolumn=no norelativenumber nocursorcolumn nospell  nolist  nonumber bufhidden=wipe colorcolumn= foldcolumn=0 matchpairs= ", +      }, +      { +        "FileType", +        "dashboard", +        "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=2", +      }, +      { "FileType", "dashboard", "nnoremap <silent> <buffer> q :q<CR>" }, +    }, +  } +end + +return M diff --git a/lua/core/floatterm.lua b/lua/core/floatterm.lua new file mode 100644 index 00000000..3d7e0e6e --- /dev/null +++ b/lua/core/floatterm.lua @@ -0,0 +1,76 @@ +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 new file mode 100644 index 00000000..ad40dd21 --- /dev/null +++ b/lua/core/formatter.lua @@ -0,0 +1,61 @@ +-- 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 + +require("formatter").setup { +  logging = false, +  filetype = formatter_filetypes, +} + +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 new file mode 100644 index 00000000..0e0ce1f4 --- /dev/null +++ b/lua/core/galaxyline.lua @@ -0,0 +1,353 @@ +local M = {} +M.config = function() +  O.plugin.galaxyline = { +    active = true, +    colors = { +      alt_bg = "#2E2E2E", +      grey = "#858585", +      blue = "#569CD6", +      green = "#608B4E", +      yellow = "#DCDCAA", +      orange = "#FF8800", +      purple = "#C586C0", +      magenta = "#D16D9E", +      cyan = "#4EC9B0", +      red = "#D16969", +      error_red = "#F44747", +      warning_orange = "#FF8800", +      info_yellow = "#FFCC66", +      hint_blue = "#9CDCFE", +    }, +  } +end + +M.setup = function() +  -- if not package.loaded['galaxyline'] then +  --   return +  -- end +  local status_ok, gl = pcall(require, "galaxyline") +  if not status_ok then +    return +  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") +  if not palette_status_ok then +    colors = O.plugin.galaxyline.colors +  end + +  local condition = require "galaxyline.condition" +  local gls = gl.section +  gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" } + +  table.insert(gls.left, { +    ViMode = { +      provider = function() +        -- auto change color according the vim mode +        local mode_color = { +          n = colors.blue, +          i = colors.green, +          v = colors.purple, +          [""] = colors.purple, +          V = colors.purple, +          c = colors.magenta, +          no = colors.blue, +          s = colors.orange, +          S = colors.orange, +          [""] = colors.orange, +          ic = colors.yellow, +          R = colors.red, +          Rv = colors.red, +          cv = colors.blue, +          ce = colors.blue, +          r = colors.cyan, +          rm = colors.cyan, +          ["r?"] = colors.cyan, +          ["!"] = colors.blue, +          t = colors.blue, +        } +        vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()]) +        return "▊" +      end, +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { "NONE", colors.alt_bg }, +    }, +  }) +  -- print(vim.fn.getbufvar(0, 'ts')) +  vim.fn.getbufvar(0, "ts") + +  table.insert(gls.left, { +    GitIcon = { +      provider = function() +        return "  " +      end, +      condition = condition.check_git_workspace, +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.orange, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.left, { +    GitBranch = { +      provider = "GitBranch", +      condition = condition.check_git_workspace, +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.left, { +    DiffAdd = { +      provider = "DiffAdd", +      condition = condition.hide_in_width, +      icon = "  ", +      highlight = { colors.green, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.left, { +    DiffModified = { +      provider = "DiffModified", +      condition = condition.hide_in_width, +      icon = " 柳", +      highlight = { colors.blue, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.left, { +    DiffRemove = { +      provider = "DiffRemove", +      condition = condition.hide_in_width, +      icon = "  ", +      highlight = { colors.red, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.left, { +    Filler = { +      provider = function() +        return " " +      end, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) +  -- get output from shell command +  function os.capture(cmd, raw) +    local f = assert(io.popen(cmd, "r")) +    local s = assert(f:read "*a") +    f:close() +    if raw then +      return s +    end +    s = string.gsub(s, "^%s+", "") +    s = string.gsub(s, "%s+$", "") +    s = string.gsub(s, "[\n\r]+", " ") +    return s +  end +  -- cleanup virtual env +  local function env_cleanup(venv) +    if string.find(venv, "/") then +      local final_venv = venv +      for w in venv:gmatch "([^/]+)" do +        final_venv = w +      end +      venv = final_venv +    end +    return venv +  end +  local PythonEnv = function() +    if vim.bo.filetype == "python" then +      local venv = os.getenv "CONDA_DEFAULT_ENV" +      if venv ~= nil then +        return "  (" .. env_cleanup(venv) .. ")" +      end +      venv = os.getenv "VIRTUAL_ENV" +      if venv ~= nil then +        return "  (" .. env_cleanup(venv) .. ")" +      end +      return "" +    end +    return "" +  end +  table.insert(gls.left, { +    VirtualEnv = { +      provider = PythonEnv, +      event = "BufEnter", +      highlight = { colors.green, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    DiagnosticError = { +      provider = "DiagnosticError", +      icon = "  ", +      highlight = { colors.red, colors.alt_bg }, +    }, +  }) +  table.insert(gls.right, { +    DiagnosticWarn = { +      provider = "DiagnosticWarn", +      icon = "  ", +      highlight = { colors.orange, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    DiagnosticInfo = { +      provider = "DiagnosticInfo", +      icon = "  ", +      highlight = { colors.yellow, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    DiagnosticHint = { +      provider = "DiagnosticHint", +      icon = "  ", +      highlight = { colors.blue, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    TreesitterIcon = { +      provider = function() +        if next(vim.treesitter.highlighter.active) ~= nil then +          return "  " +        end +        return "" +      end, +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.green, colors.alt_bg }, +    }, +  }) + +  local get_lsp_client = function(msg) +    msg = msg or "LSP Inactive" +    local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") +    local clients = vim.lsp.get_active_clients() +    if next(clients) == nil then +      return msg +    end +    local lsps = "" +    for _, client in ipairs(clients) do +      local filetypes = client.config.filetypes +      if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then +        -- print(client.name) +        if lsps == "" then +          -- print("first", lsps) +          lsps = client.name +        else +          if not string.find(lsps, client.name) then +            lsps = lsps .. ", " .. client.name +          end +          -- print("more", lsps) +        end +      end +    end +    if lsps == "" then +      return msg +    else +      return lsps +    end +  end + +  table.insert(gls.right, { +    ShowLspClient = { +      provider = get_lsp_client, +      condition = function() +        local tbl = { ["dashboard"] = true, [" "] = true } +        if tbl[vim.bo.filetype] then +          return false +        end +        return true +      end, +      icon = " ", +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    LineInfo = { +      provider = "LineColumn", +      separator = "  ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    PerCent = { +      provider = "LinePercent", +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    Tabstop = { +      provider = function() +        return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " +      end, +      condition = condition.hide_in_width, +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    BufferType = { +      provider = "FileTypeName", +      condition = condition.hide_in_width, +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    FileEncode = { +      provider = "FileEncode", +      condition = condition.hide_in_width, +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.right, { +    Space = { +      provider = function() +        return " " +      end, +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.short_line_left, { +    BufferType = { +      provider = "FileTypeName", +      separator = " ", +      separator_highlight = { "NONE", colors.alt_bg }, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  table.insert(gls.short_line_left, { +    SFileName = { +      provider = "SFileName", +      condition = condition.buffer_not_empty, +      highlight = { colors.grey, colors.alt_bg }, +    }, +  }) + +  --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}}) +end + +return M diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua new file mode 100644 index 00000000..553bdb41 --- /dev/null +++ b/lua/core/nvimtree.lua @@ -0,0 +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 +end +-- +M.setup = function() +  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 = O.auto_close_tree +  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, +  } + +  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 = { +    { 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() +  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 +      -- require'bufferline.state'.set_offset(31, 'File Explorer') +      require("bufferline.state").set_offset(31, "") +    end +    require("nvim-tree").find_file(true) +  end +end +-- +return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua new file mode 100644 index 00000000..07487a3c --- /dev/null +++ b/lua/core/telescope.lua @@ -0,0 +1,94 @@ +local M = {} +M.config = function() +  local status_ok, actions = pcall(require, "telescope.actions") +  if not status_ok then +    return +  end + +  O.plugin.telescope = { +    active = false, +    defaults = { +      find_command = { +        "rg", +        "--no-heading", +        "--with-filename", +        "--line-number", +        "--column", +        "--smart-case", +      }, +      prompt_prefix = " ", +      selection_caret = " ", +      entry_prefix = "  ", +      initial_mode = "insert", +      selection_strategy = "reset", +      sorting_strategy = "descending", +      layout_strategy = "horizontal", +      layout_config = { +        width = 0.75, +        prompt_position = "bottom", +        preview_cutoff = 120, +        horizontal = { mirror = false }, +        vertical = { mirror = false }, +      }, +      file_sorter = require("telescope.sorters").get_fzy_sorter, +      file_ignore_patterns = {}, +      generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, +      path_display = { "shorten" }, +      winblend = 0, +      border = {}, +      borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, +      color_devicons = true, +      use_less = true, +      set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, +      file_previewer = require("telescope.previewers").vim_buffer_cat.new, +      grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, +      qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + +      -- Developer configurations: Not meant for general override +      -- buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, +      mappings = { +        i = { +          ["<C-c>"] = actions.close, +          ["<C-j>"] = actions.move_selection_next, +          ["<C-k>"] = actions.move_selection_previous, +          ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist, +          ["<CR>"] = actions.select_default + actions.center, +          -- To disable a keymap, put [map] = false +          -- So, to not map "<C-n>", just put +          -- ["<c-t>"] = trouble.open_with_trouble, +          -- ["<c-x>"] = false, +          -- ["<esc>"] = actions.close, +          -- Otherwise, just set the mapping to the function that you want it to be. +          -- ["<C-i>"] = actions.select_horizontal, +          -- Add up multiple actions +          -- You can perform as many actions in a row as you like +          -- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action, +        }, +        n = { +          ["<C-j>"] = actions.move_selection_next, +          ["<C-k>"] = actions.move_selection_previous, +          ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist, +          -- ["<c-t>"] = trouble.open_with_trouble, +          -- ["<C-i>"] = my_cool_custom_action, +        }, +      }, +    }, +    extensions = { +      fzy_native = { +        override_generic_sorter = false, +        override_file_sorter = true, +      }, +    }, +  } +end + +M.setup = function() +  local status_ok, telescope = pcall(require, "telescope") +  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 }) +end + +return M diff --git a/lua/core/treesitter.lua b/lua/core/treesitter.lua new file mode 100644 index 00000000..2b7a2d54 --- /dev/null +++ b/lua/core/treesitter.lua @@ -0,0 +1,187 @@ +local M = {} +M.config = function() +  O.treesitter = { +    ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages +    ignore_install = {}, +    matchup = { +      enable = false, -- mandatory, false will disable the whole extension +      -- disable = { "c", "ruby" },  -- optional, list of language that will be disabled +    }, +    highlight = { +      enable = true, -- false will disable the whole extension +      additional_vim_regex_highlighting = true, +      disable = { "latex" }, +    }, +    context_commentstring = { +      enable = false, +      config = { css = "// %s" }, +    }, +    -- indent = {enable = true, disable = {"python", "html", "javascript"}}, +    -- TODO seems to be broken +    indent = { enable = { "javascriptreact" } }, +    autotag = { enable = false }, +    textobjects = { +      swap = { +        enable = false, +        -- swap_next = textobj_swap_keymaps, +      }, +      -- move = textobj_move_keymaps, +      select = { +        enable = false, +        -- keymaps = textobj_sel_keymaps, +      }, +    }, +    textsubjects = { +      enable = false, +      keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" }, +    }, +    playground = { +      enable = false, +      disable = {}, +      updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code +      persist_queries = false, -- Whether the query persists across vim sessions +      keybindings = { +        toggle_query_editor = "o", +        toggle_hl_groups = "i", +        toggle_injected_languages = "t", +        toggle_anonymous_nodes = "a", +        toggle_language_display = "I", +        focus_language = "f", +        unfocus_language = "F", +        update = "R", +        goto_node = "<cr>", +        show_help = "?", +      }, +    }, +    rainbow = { +      enable = false, +      extended_mode = true, -- Highlight also non-parentheses delimiters, boolean or table: lang -> boolean +      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) +end + +return M diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua new file mode 100644 index 00000000..ef875c30 --- /dev/null +++ b/lua/core/which-key.lua @@ -0,0 +1,197 @@ +local M = {} +M.config = function() +  O.plugin.which_key = { +    active = false, +    setup = { +      plugins = { +        marks = true, -- shows a list of your marks on ' and ` +        registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode +        -- the presets plugin, adds help for a bunch of default keybindings in Neovim +        -- No actual key bindings are created +        presets = { +          operators = false, -- adds help for operators like d, y, ... +          motions = false, -- adds help for motions +          text_objects = false, -- help for text objects triggered after entering an operator +          windows = true, -- default bindings on <c-w> +          nav = true, -- misc bindings to work with windows +          z = true, -- bindings for folds, spelling and others prefixed with z +          g = true, -- bindings for prefixed with g +        }, +        spelling = { enabled = true, suggestions = 20 }, -- use which-key for spelling hints +      }, +      icons = { +        breadcrumb = "»", -- symbol used in the command line area that shows your active key combo +        separator = "➜", -- symbol used between a key and it's label +        group = "+", -- symbol prepended to a group +      }, +      window = { +        border = "single", -- none, single, double, shadow +        position = "bottom", -- bottom, top +        margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] +        padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] +      }, +      layout = { +        height = { min = 4, max = 25 }, -- min and max height of the columns +        width = { min = 20, max = 50 }, -- min and max width of the columns +        spacing = 3, -- spacing between columns +      }, +      hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate +      show_help = true, -- show help message on the command line when the popup is visible +    }, + +    opts = { +      mode = "n", -- NORMAL mode +      prefix = "<leader>", +      buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings +      silent = true, -- use `silent` when creating keymaps +      noremap = true, -- use `noremap` when creating keymaps +      nowait = true, -- use `nowait` when creating keymaps +    }, +    vopts = { +      mode = "v", -- VISUAL mode +      prefix = "<leader>", +      buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings +      silent = true, -- use `silent` when creating keymaps +      noremap = true, -- use `noremap` when creating keymaps +      nowait = true, -- use `nowait` when creating keymaps +    }, +    -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode. +    -- see https://neovim.io/doc/user/map.html#:map-cmd +    vmappings = { +      ["/"] = { ":CommentToggle<CR>", "Comment" }, +    }, +    mappings = { +      ["w"] = { "<cmd>w!<CR>", "Save" }, +      ["q"] = { "<cmd>q!<CR>", "Quit" }, +      ["/"] = { "<cmd>CommentToggle<CR>", "Comment" }, +      ["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" }, +      p = { +        name = "Packer", +        c = { "<cmd>PackerCompile<cr>", "Compile" }, +        i = { "<cmd>PackerInstall<cr>", "Install" }, +        r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" }, +        s = { "<cmd>PackerSync<cr>", "Sync" }, +        u = { "<cmd>PackerUpdate<cr>", "Update" }, +      }, + +      -- " Available Debug Adapters: +      -- "   https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/ +      -- " Adapter configuration and installation instructions: +      -- "   https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation +      -- " Debug Adapter protocol: +      -- "   https://microsoft.github.io/debug-adapter-protocol/ +      -- " Debugging +      g = { +        name = "Git", +        j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" }, +        k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" }, +        l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" }, +        p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" }, +        r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" }, +        R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" }, +        s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" }, +        u = { +          "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>", +          "Undo Stage Hunk", +        }, +        o = { "<cmd>Telescope git_status<cr>", "Open changed file" }, +        b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" }, +        c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" }, +        C = { +          "<cmd>Telescope git_bcommits<cr>", +          "Checkout commit(for current file)", +        }, +      }, + +      l = { +        name = "LSP", +        a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" }, +        d = { +          "<cmd>Telescope lsp_document_diagnostics<cr>", +          "Document Diagnostics", +        }, +        w = { +          "<cmd>Telescope lsp_workspace_diagnostics<cr>", +          "Workspace Diagnostics", +        }, +        f = { "<cmd>silent FormatWrite<cr>", "Format" }, +        i = { "<cmd>LspInfo<cr>", "Info" }, +        j = { +          "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>", +          "Next Diagnostic", +        }, +        k = { +          "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>", +          "Prev Diagnostic", +        }, +        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_dynamic_workspace_symbols<cr>", +          "Workspace Symbols", +        }, +      }, + +      s = { +        name = "Search", +        b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" }, +        c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" }, +        f = { "<cmd>Telescope find_files<cr>", "Find File" }, +        h = { "<cmd>Telescope help_tags<cr>", "Find Help" }, +        M = { "<cmd>Telescope man_pages<cr>", "Man Pages" }, +        r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" }, +        R = { "<cmd>Telescope registers<cr>", "Registers" }, +        t = { "<cmd>Telescope live_grep<cr>", "Text" }, +        k = { "<cmd>Telescope keymaps<cr>", "Keymaps" }, +        C = { "<cmd>Telescope commands<cr>", "Commands" }, +      }, +      T = { +        name = "Treesitter", +        i = { ":TSConfigInfo<cr>", "Info" }, +      }, +    }, +  } +end + +M.setup = function() +  -- if not package.loaded['which-key'] then +  --  return +  -- end +  local status_ok, which_key = pcall(require, "which-key") +  if not status_ok then +    return +  end + +  which_key.setup(O.plugin.which_key.setup) + +  local opts = O.plugin.which_key.opts +  local vopts = O.plugin.which_key.vopts + +  local mappings = O.plugin.which_key.mappings +  local vmappings = O.plugin.which_key.vmappings + +  -- 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 + +  for k, v in pairs(O.user_which_key) do +    mappings[k] = v +  end + +  local wk = require "which-key" +  wk.register(mappings, opts) +  wk.register(vmappings, vopts) +end + +return M diff --git a/lua/core/zen.lua b/lua/core/zen.lua new file mode 100644 index 00000000..99a5d769 --- /dev/null +++ b/lua/core/zen.lua @@ -0,0 +1,34 @@ +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 | 
