From b9d674767b3f07e1e38e9e291b04332eb38b344a Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Fri, 24 Sep 2021 16:03:02 +0700 Subject: [PATCH] neovim: replace dashboard-nvim with alpha-nvim + persistence.nvim --- home/.config/nvim/lua/colors/nord.lua | 3 +- home/.config/nvim/lua/events.lua | 1 - home/.config/nvim/lua/mappings.lua | 10 +- home/.config/nvim/lua/modules/editor.lua | 1 + home/.config/nvim/lua/modules/tools.lua | 7 ++ home/.config/nvim/lua/modules/ui.lua | 112 +++++++++++++++++------ home/.config/nvim/lua/plugins.lua | 22 ++--- 7 files changed, 114 insertions(+), 42 deletions(-) diff --git a/home/.config/nvim/lua/colors/nord.lua b/home/.config/nvim/lua/colors/nord.lua index f34c497..4c4f845 100644 --- a/home/.config/nvim/lua/colors/nord.lua +++ b/home/.config/nvim/lua/colors/nord.lua @@ -1,3 +1,4 @@ +-- TODO: add other highlight groups from nord.vim local M = {} M.colors = { @@ -306,7 +307,7 @@ local function highlight_plugins() hi('EftChar' , c.orange, '', 'bold,underline', '') hi('EftSubChar', c.grey3, '', 'bold,underline', '') - -- Dashboard + -- dashboard-nvim / alpha-nvim hi('DashboardHeader' , c.cyan , '', 'bold' , '') hi('DashboardCenter' , c.blue , '', 'bold' , '') hi('DashboardShortcut', c.grey_bright, '', 'bold,italic', '') diff --git a/home/.config/nvim/lua/events.lua b/home/.config/nvim/lua/events.lua index dafe32b..45f5514 100644 --- a/home/.config/nvim/lua/events.lua +++ b/home/.config/nvim/lua/events.lua @@ -68,7 +68,6 @@ function M.load_autocmds() }, ft = { - {"FileType", "dashboard", "set showtabline=0 | autocmd WinLeave set showtabline=2"}, {"BufNewFile,BufRead", "*.md,*.mkd", "setfiletype markdown"}, {"BufNewFile,BufRead", "*.toml", "setfiletype toml"}, {"BufNewFile,BufRead", "*.rasi", "setfiletype css"}, diff --git a/home/.config/nvim/lua/mappings.lua b/home/.config/nvim/lua/mappings.lua index ca1f25d..defd0a6 100644 --- a/home/.config/nvim/lua/mappings.lua +++ b/home/.config/nvim/lua/mappings.lua @@ -129,7 +129,7 @@ wk.register({ d = {':bdelete', 'Close buffer'}, j = {':BufferLineCyclePrev', 'Previous buffer'}, k = {':BufferLineCycleNext', 'Next buffer'}, - n = {':DashboardNewFile', 'New file'}, + n = {':enew startinsert ', 'New buffer'}, u = {':UndotreeToggle', 'Undotree'}, z = {':ZenMode', 'Zen mode'} }, @@ -147,6 +147,14 @@ wk.register({ t = {':lua require("dapui").open()', 'Toggle UI'} }, + e = { + name = 'Session', + s = {':lua require("persistence").save()', 'Save session for current directory'}, + d = {':lua require("persistence").stop()', 'Stop automatically saving'}, + l = {':lua require("persistence").load({last = true})', 'Load last session'}, + r = {':lua require("persistence").load()', 'Load session for current directory'} + }, + -- Telescope f = { name = 'Telescope', diff --git a/home/.config/nvim/lua/modules/editor.lua b/home/.config/nvim/lua/modules/editor.lua index 8cd504c..dbdf42b 100644 --- a/home/.config/nvim/lua/modules/editor.lua +++ b/home/.config/nvim/lua/modules/editor.lua @@ -23,6 +23,7 @@ function M.blankline_conf() vim.g.indent_blankline_filetype_exclude = { 'startify', 'dashboard', + 'alpha', 'dotooagenda', 'log', 'fugitive', diff --git a/home/.config/nvim/lua/modules/tools.lua b/home/.config/nvim/lua/modules/tools.lua index 158a747..f7a38fe 100644 --- a/home/.config/nvim/lua/modules/tools.lua +++ b/home/.config/nvim/lua/modules/tools.lua @@ -259,4 +259,11 @@ function M.neoscroll_conf() require('neoscroll').setup() end +function M.session_conf() + require('persistence').setup { + dir = vim.fn.expand(vim.fn.stdpath('data') .. '/sessions/'), + options = {'buffers', 'curdir', 'tabpages', 'winsize'} + } +end + return M diff --git a/home/.config/nvim/lua/modules/ui.lua b/home/.config/nvim/lua/modules/ui.lua index 5dc7798..52b1d41 100644 --- a/home/.config/nvim/lua/modules/ui.lua +++ b/home/.config/nvim/lua/modules/ui.lua @@ -1,35 +1,95 @@ local M = {} function M.dashboard_conf() - -- vim.g.dashboard_disable_at_vimenter = 1 - -- vim.g.dashboard_disable_statusline = 1 - vim.g.dashboard_preview_file_height = 12 - vim.g.dashboard_preview_file_width = 80 - vim.g.dashboard_default_executive = 'telescope' - vim.g.dashboard_session_directory = vim.fn.stdpath('data') .. '/sessions' - vim.g.dashboard_custom_section = { - a = {description = {' Find File SPC f f'}, command = 'DashboardFindFile'}, - b = {description = {' Recents SPC f o'}, command = 'DashboardFindHistory'}, - c = {description = {' Find Word SPC f g'}, command = 'DashboardFindWord'}, - d = {description = {'洛 New File SPC b n'}, command = 'DashboardNewFile'}, - e = {description = {' Bookmarks SPC f m'}, command = 'DashboardJumpMark'} + local dashboard = require('alpha.themes.dashboard') + local button = dashboard.button + + dashboard.section.header = { + type = 'text', + val = { + [[<-. (`-')_ (`-') _ (`-') _ <-. (`-') ]], + [[ \( OO) ) ( OO).-/ .-> _(OO ) (_) \(OO )_ ]], + [[,--./ ,--/ (,------.(`-')----. ,--.(_/,-.\ ,-(`-'),--./ ,-.)]], + [[| \ | | | .---'( OO).-. '\ \ / (_/ | ( OO)| `.' |]], + [[| . '| |)(| '--. ( _) | | | \ / / | | )| |'.'| |]], + [[| |\ | | .--' \| |)| |_ \ /_)(| |_/ | | | |]], + [[| | \ | | `---. ' '-' '\-'\ / | |'->| | | |]], + [[`--' `--' `------' `-----' `-' `--' `--' `--']] + }, + opts = { + position = 'center', + -- wrap = 'overflow', + hl = 'DashboardHeader' + } } - vim.g.dashboard_custom_header = { - " ", - " ", - " ", - "<-. (`-')_ (`-') _ (`-') _ <-. (`-') ", - " \\( OO) ) ( OO).-/ .-> _(OO ) (_) \\(OO )_ ", - ",--./ ,--/ (,------.(`-')----. ,--.(_/,-.\\ ,-(`-'),--./ ,-.)", - "| \\ | | | .---'( OO).-. '\\ \\ / (_/ | ( OO)| `.' |", - "| . '| |)(| '--. ( _) | | | \\ / / | | )| |'.'| |", - "| |\\ | | .--' \\| |)| |_ \\ /_)(| |_/ | | | |", - "| | \\ | | `---. ' '-' '\\-'\\ / | |'->| | | |", - "`--' `--' `------' `-----' `-' `--' `--' `--'", + + dashboard.section.footer = { + type = 'text', + val = 'おかえりなさい', + opts = { + position = 'center', + hl = 'DashboardFooter' + } } - vim.g.dashboard_custom_footer = { - 'おかえりなさい' + + button = function(sc, txt, keybind, keybind_opts) + local sc_ = sc:gsub('%s', ''):gsub('SPC', '') + + local opts = { + position = 'center', + shortcut = sc, + cursor = 5, + width = 50, + align_shortcut = 'right', + hl = 'DashboardCenter', + hl_shortcut = 'DashboardShortcut', + } + if keybind then + keybind_opts = vim.F.if_nil(keybind_opts, {noremap = true, silent = true, nowait = true}) + opts.keymap = {'n', sc_, keybind, keybind_opts} + end + + local function on_press() + local key = vim.api.nvim_replace_termcodes(sc_ .. '', true, false, true) + vim.api.nvim_feedkeys(key, 'normal', false) + end + + return { + type = 'button', + val = txt, + on_press = on_press, + opts = opts, + } + end + + dashboard.section.buttons = { + type = 'group', + val = { + button('SPC b n', ' New file'), + button('SPC f f', ' Find file'), + button('SPC f o', ' Recent files'), + button('SPC f g', ' Find word'), + button('SPC f m', ' Bookmarks'), + button('SPC e l', ' Load last session') + }, + opts = {spacing = 1} } + + require('alpha').setup { + layout = { + {type = 'padding', val = 4}, + dashboard.section.header, + {type = 'padding', val = 2}, + dashboard.section.buttons, + dashboard.section.footer + }, + opts = {margin = 5} + } + + -- Hide tabline in dashboard buffer + vim.api.nvim_command [[ +autocmd FileType alpha set showtabline=0 | autocmd BufUnload set showtabline=2 +]] end function M.statusline_conf() diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index a4abb83..8de5a6c 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -25,18 +25,9 @@ return require('packer').startup( -------- local ui = require('modules.ui') use { - 'glepnir/dashboard-nvim', - cmd = { - 'Dashboard', - 'DashboardNewFile', - 'DashboardFindFile', - 'DashboardFindHistory', - 'DashboardFindWord', - 'DashboardJumpMark', - 'SessionLoad', - 'SessionSave' - }, - setup = ui.dashboard_conf + 'goolord/alpha-nvim', + event = 'VimEnter', + config = ui.dashboard_conf } use { -- TODO: consider moving to feline.nvim 'glepnir/galaxyline.nvim', @@ -380,10 +371,15 @@ return require('packer').startup( run = ':TSInstall http', config = tools.rest_conf } - use { + use { -- TODO: move to formater.nvim 'sbdchd/neoformat', cmd = 'Neoformat' } + use { + 'folke/persistence.nvim', + event = 'BufReadPre', + config = tools.session_conf + } use {'tweekmonster/startuptime.vim', cmd = 'StartupTime'} -- Just for benchmarking -- TODO: dial.nvim, rust-tools.nvim, crates.nvim, go.nvim, clojure-vim/*, vim-pandoc