diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-09-11 21:11:53 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-09-11 21:11:53 +0200 |
| commit | a9347a8d6783b360d0e4481151944b0f961404d9 (patch) | |
| tree | b61a5e6beb4d150449ecf004a7e4a6099f4917dc /.config | |
| parent | fd1646bb0d8bca44f263717ec63268947af1386c (diff) | |
| parent | 38ec7c480730e3f83322fa34a6a4ff700ca503d9 (diff) | |
| download | dotfiles-a9347a8d6783b360d0e4481151944b0f961404d9.tar.gz dotfiles-a9347a8d6783b360d0e4481151944b0f961404d9.zip | |
Merge commit '9489548bca74468976436df44134e4aeb40e8548'
Diffstat (limited to '.config')
| -rw-r--r-- | .config/nvim/.editorconfig | 38 | ||||
| -rw-r--r-- | .config/nvim/README.md | 53 | ||||
| -rw-r--r-- | .config/nvim/after/ftplugin/markdown.lua | 14 | ||||
| -rw-r--r-- | .config/nvim/autoload/utils.vim | 63 | ||||
| -rw-r--r-- | .config/nvim/init.lua | 198 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/colorscheme.lua | 44 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/dashboard.lua | 128 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/heirline.lua | 535 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/loclist.lua | 18 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/lsp.lua | 822 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/nvim-tree.lua | 430 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/quickfix.lua | 15 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/session.lua | 5 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/sniprun.lua | 57 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/telescope.lua | 513 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/trouble.lua | 88 | ||||
| -rw-r--r-- | .config/nvim/lua/plugins/web-devicons.lua | 33 | ||||
| -rw-r--r-- | .config/nvim/lua/user/keys.lua | 485 | ||||
| -rw-r--r-- | .config/nvim/lua/user/mods.lua | 510 | ||||
| -rw-r--r-- | .config/nvim/lua/user/opts.lua | 218 | ||||
| -rw-r--r-- | .config/nvim/lua/user/pack.lua | 272 |
21 files changed, 2675 insertions, 1864 deletions
diff --git a/.config/nvim/.editorconfig b/.config/nvim/.editorconfig deleted file mode 100644 index 86067d4..0000000 --- a/.config/nvim/.editorconfig +++ /dev/null @@ -1,38 +0,0 @@ -root = true - -[**] -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true -indent_style = space -indent_size = 4 -charset = utf-8 - -# TypeScript/JavaScript config -[**.{ts,js}] -indent_size = 2 - -# Json config -[**.json] -indent_size = 2 - -# Lua config -[**.lua] -indent_size = 2 - -# Latex config -[**.tex] -trim_trailing_whitespace = false - -# Markdown config -[**.md] -trim_trailing_whitespace = false - -# Textfile config -[**.txt] -trim_trailing_whitespace = false -insert_final_newline = false - -# Snippets config -[**.snippets] -indent_style = tab diff --git a/.config/nvim/README.md b/.config/nvim/README.md index a841b13..2849262 100644 --- a/.config/nvim/README.md +++ b/.config/nvim/README.md @@ -1,32 +1,33 @@ ## Neovim + #### Dependencies + nvm nvm install --lts - #### TODOS: -- [ ] Markdown filetype plugin or autocommand to add two spaces each line -- [ ] Markdown filetype plugin or autocommand to make backtick auto-correct properly -- [ ] Indent by filetype/fix global indent (2) -- [ ] Check history or telescope history of last files edited or opened. -- [ ] * Windows native support configuration -- [ ] * Python debugger -- [ ] README file heirachcy -- [ ] Markdown snippet for code blocks with list, ie.- `` and - ``` ``` -- [ ] Snippet for filler text with variations, ie. common sentences: The quick brown fox... and more and placeholder words -- [ ] Configure snippets.lua -- [ ] Documentation shortcuts for different languages quote in quote "locally" (preffered) or opening web browser -- [ ] Dictionary, an actual dictionary -- [ ] Null-ls/lsp keymap to check current buffer servers must check both same time -> NOTE: Different servers must be configured only to one or another, research null-ls being archived -- [ ] Don't highlight whitespaces in lazygit (maybe exclusively markdown) -- [ ] Configure prettier/prettierd servers to join a lot of different files (null-ls) -- [ ] Nvim-tree preview window similar to telescope -- [ ] Nvim-tree behaviour when delete current buffer -> NOTE: One idea is to create an autocmd to make a blank window (hidden) as a secondary window but when creating a opening a new file it does not ask which split to open in -- [ ] Nvim-tree conditionally when open going in the opposite direction will go back to nvim-tree ie. going right then goes to nvim-tree but is conditionally because of tmux etc... -- [x] Substitute keybinding -- [ ] Snippet/filetype plugin for markdown tick boxes -- [ ] Delete lua/user/func.lua -- [ ] Clean entire config by prioritizing single quotation marks over double -- [ ] <placeholder> + +- [ ] Markdown filetype plugin or autocommand to add two spaces each line +- [ ] Markdown filetype plugin or autocommand to make backtick auto-correct properly +- [x] Indent by filetype/fix global indent (2) +- [x] Check history or telescope history of last files edited or opened. +- [ ] - Windows native support configuration +- [ ] - Python debugger +- [ ] README file heirachcy +- [ ] Markdown snippet for code blocks with list, ie.- ``and -` ` +- [ ] Snippet for filler text with variations, ie. common sentences: The quick brown fox... and more and placeholder words +- [ ] Configure snippets.lua +- [ ] Documentation shortcuts for different languages quote in quote "locally" (preffered) or opening web browser +- [ ] Dictionary, an actual dictionary +- [ ] Null-ls/lsp keymap to check current buffer servers must check both same time + > NOTE: Different servers must be configured only to one or another, research null-ls being archived +- [ ] Don't highlight whitespaces in lazygit (maybe exclusively markdown) +- [ ] Configure prettier/prettierd servers to join a lot of different files (null-ls) +- [ ] Nvim-tree preview window similar to telescope +- [x] Nvim-tree behaviour when delete current buffer + > NOTE: One idea is to create an autocmd to make a blank window (hidden) as a secondary window but when creating a opening a new file it does not ask which split to open in +- [ ] Nvim-tree conditionally when open going in the opposite direction will go back to nvim-tree ie. going right then goes to nvim-tree but is conditionally because of tmux etc... +- [x] Substitute keybinding +- [ ] Snippet/filetype plugin for markdown tick boxes +- [ ] Delete lua/user/func.lua +- [ ] Clean entire config by prioritizing single quotation marks over double diff --git a/.config/nvim/after/ftplugin/markdown.lua b/.config/nvim/after/ftplugin/markdown.lua index ec30702..718a871 100644 --- a/.config/nvim/after/ftplugin/markdown.lua +++ b/.config/nvim/after/ftplugin/markdown.lua @@ -1,2 +1,16 @@ +vim.wo.spell = true +vim.bo.spelllang = "en" +vim.wo.wrap = true +vim.wo.linebreak = true +vim.wo.breakindent = true +vim.wo.colorcolumn = "0" +vim.wo.conceallevel = 3 vim.opt.softtabstop = 2 -- Tab key indents by 2 spaces. vim.opt.shiftwidth = 2 -- >> indents by 2 spaces. + +vim.b[0].undo_ftplugin = "setlocal nospell nowrap nolinebreak nobreakindent conceallevel=0" + +vim.cmd([[ + autocmd FileType markdown iabbrev <buffer> `` `` +]]) + diff --git a/.config/nvim/autoload/utils.vim b/.config/nvim/autoload/utils.vim index d244e90..f11a769 100644 --- a/.config/nvim/autoload/utils.vim +++ b/.config/nvim/autoload/utils.vim @@ -57,7 +57,7 @@ endfunction " Toggle statusline let s:hidden_all = 0 -function! ToggleHiddenAll() +function! utils#ToggleHiddenAll() if s:hidden_all == 0 let s:hidden_all = 1 set noshowmode @@ -148,3 +148,64 @@ endfunction "------------------------------------------------- + +" Disable annoying auto line break +fu! utils#DisableBr() + set wrap + set linebreak + set nolist " list disables linebreak + set textwidth=0 + set wrapmargin=0 + set formatoptions-=t +endfu + +" Disable line breaks for all file types +autocmd! BufNewFile,BufRead *.* call utils#DisableBr() + + +"------------------------------------------------- + +" Annoying timestamp issue on write (The file has been changed since reading it...) +"function! utils#ProcessFileChangedShell() +" if v:fcs_reason == 'mode' || v:fcs_reason == 'time' +" let v:fcs_choice = '' +" else +" let v:fcs_choice = 'ask' +" endif +"endfunction +"autocmd FileChangedShell <buffer> call utils#ProcessFileChangedShell() +" +"let lastline = line('$') +"let bufcontents = getline(1, lastline) +"edit! +"call setline(1, bufcontents) +"if line('$') > lastline +" execute lastline+1.',$:d _' +"endif + +" Annoying timestamp issue on write (The file has been changed since reading it...) +function! utils#ProcessFileChangedShell() + if v:fcs_reason == 'mode' || v:fcs_reason == 'time' + let v:fcs_choice = '' + else + let v:fcs_choice = 'ask' + endif +endfunction + +" Triggered when the file is changed externally +autocmd FileChangedShell <buffer> call utils#ProcessFileChangedShell() + +" Triggered before writing the buffer to the file +autocmd BufWritePre <buffer> call utils#BeforeWrite() + +function! utils#BeforeWrite() + let lastline = line('$') + let bufcontents = getline(1, lastline) + edit! + call setline(1, bufcontents) + if line('$') > lastline + execute lastline+1.',$:d _' + endif +endfunction + +"------------------------------------------------- diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 08f5cf7..d1f9911 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -44,114 +44,160 @@ --$ nvim --startuptime startup.log -c exit && tail -100 startup.log -- Load impatient (Faster loading times) -local impatient_ok, impatient = pcall(require, "impatient") +local impatient_ok, impatient = pcall(require, 'impatient') if impatient_ok then impatient.enable_profile() end - -- Schedule reading shadafile to improve the startup time -vim.opt.shadafile = "NONE" +vim.opt.shadafile = 'NONE' vim.schedule(function() - vim.opt.shadafile = "" - vim.cmd("silent! rsh") + vim.opt.shadafile = '' + vim.cmd('silent! rsh') end) - -- Load/reload modules local modules = { - "user.pack", -- Packer plugin manager - "user.opts", -- Options - "user.keys", -- Keymaps - "user.mods", -- Modules/functions + 'user.pack', -- Packer plugin manager + 'user.opts', -- Options + 'user.keys', -- Keymaps + 'user.mods', -- Modules/functions --"user.scripts", - "plugins.treesitter", - "plugins.neodev", - "plugins.colorscheme", - "plugins.telescope", - "plugins.nvim-tree", - "plugins.web-devicons", - "plugins.cmp", - "plugins.quickfix", + 'plugins.treesitter', + 'plugins.neodev', + --'plugins.colorscheme', + 'plugins.telescope', + 'plugins.nvim-tree', + 'plugins.web-devicons', + 'plugins.cmp', + 'plugins.quickfix', --"plugins.snippets", --"plugins.colorizer", --"plugins.prettier", --"plugins.git", - "plugins.lsp", + 'plugins.lsp', --"plugins.fugitive", - "plugins.gitsigns", - "plugins.neoscroll", - "plugins.statuscol", - "plugins.trouble", - "plugins.goto-preview", - "plugins.autopairs", - "plugins.navic", - "plugins.toggleterm", - "plugins.zen-mode", - "plugins.fidget", - "plugins.dap", - "plugins.neotest", - "plugins.heirline", - "plugins.dashboard", - "plugins.which-key", - "plugins.harpoon", + 'plugins.gitsigns', + 'plugins.sniprun', + 'plugins.session', + 'plugins.neoscroll', + 'plugins.statuscol', + 'plugins.trouble', + 'plugins.goto-preview', + 'plugins.autopairs', + 'plugins.navic', + 'plugins.toggleterm', + 'plugins.zen-mode', + 'plugins.fidget', + 'plugins.dap', + 'plugins.neotest', + 'plugins.heirline', + 'plugins.dashboard', + 'plugins.which-key', + 'plugins.harpoon', --"plugins.modify-blend", } - -- Refresh module cache for k, v in pairs(modules) do package.loaded[v] = nil require(v) end - --- Check if we have the latest stable version of nvim -local mods = require("user.mods") -local expected_ver = "0.9.0" -local nvim_ver = mods.get_nvim_version() - -if nvim_ver ~= expected_ver then - local msg = string.format("Unsupported nvim version: expect %s, but got %s instead!", expected_ver, nvim_ver) - vim.api.nvim_err_writeln(msg) - return -end - - --- Snippets -vim.g.snippets = "luasnip" - --- Notifications -vim.notify = require("notify") -- Requires plugin "rcarriga/nvim-notify" - -- Improve speed by disabling some default plugins/modules local builtins = { - "gzip", - "zip", - "zipPlugin", - "tar", - "tarPlugin", - "getscript", - "getscriptPlugin", - "vimball", - "vimballPlugin", - "2html_plugin", + 'gzip', + 'zip', + 'zipPlugin', + 'tar', + 'tarPlugin', + 'getscript', + 'getscriptPlugin', + 'vimball', + 'vimballPlugin', + '2html_plugin', --"matchit", --"matchparen", - "logiPat", - "rrhelper", - "netrw", - "netrwPlugin", - "netrwSettings", - "netrwFileHandlers", - "tutor_mode_plugin", - "fzf", - "spellfile_plugin", - "sleuth", + 'logiPat', + 'rrhelper', + 'netrw', + 'netrwPlugin', + 'netrwSettings', + 'netrwFileHandlers', + 'tutor_mode_plugin', + 'fzf', + 'spellfile_plugin', + 'sleuth', } for _, plugin in ipairs(builtins) do - vim.g["loaded_" .. plugin] = 1 + vim.g['loaded_' .. plugin] = 1 end vim.g.do_filetype_lua = 1 vim.g.did_load_filetypes = 0 + +-- Snippets +--vim.g.snippets = 'luasnip' + +-- Notifications +vim.notify = require('notify') -- Requires plugin "rcarriga/nvim-notify" + +-- Colorscheme + +-- Colors +vim.opt.termguicolors = true + +-- Available colorschemes: +-- [[ nightfly ayu onedark doom-one nvimgelion github_dark tokyonight ]] + +require('tokyonight').setup({ + style = 'night', + transparent = true, + transparent_sidebar = true, + styles = { + sidebars = 'transparent', + floats = 'transparent', + }, +}) + +-- Define default color scheme +local default_colorscheme = 'tokyonight' +local fallback_colorscheme = 'desert' + +-- Attempt to set the default color scheme +local status_ok, _ = pcall(vim.cmd, 'colorscheme ' .. default_colorscheme) + +-- If the default color scheme is not found, use the fallback color scheme +if not status_ok then + vim.cmd('colorscheme ' .. fallback_colorscheme) +end + +vim.api.nvim_command('syntax on') +vim.api.nvim_command('highlight Normal guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight NonText guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight NormalNC guibg=NONE') +vim.api.nvim_command('highlight SignColumn guibg=NONE') +vim.api.nvim_command('highlight FoldColumn guibg=NONE') +vim.api.nvim_command('highlight CursorLineSign guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight TabLine guibg=#333842 gui=bold') +vim.api.nvim_command('highlight Title guibg=NONE gui=bold') +vim.api.nvim_command('highlight TabLineSel guibg=#333842 gui=bold') +vim.api.nvim_command('highlight TabLineFill guibg=NONE gui=bold') +vim.api.nvim_command('highlight WinBar guibg=NONE gui=bold') +vim.api.nvim_command('highlight NormalFloat guibg=NONE') +vim.api.nvim_command('highlight LineNr guibg=NONE') +vim.api.nvim_command('highlight WinSeparator guibg=NONE gui=bold') +vim.api.nvim_command('highlight MsgSeparator guibg=NONE') +vim.api.nvim_command('highlight PmenuSel guibg=NONE') +vim.api.nvim_command('highlight winblend guibg=NONE') +vim.api.nvim_command('highlight EndOfBuffer guibg=NONE guifg=Normal') + +-- Set different window separator colorscheme +vim.cmd([[ +au WinEnter * setl winhl=WinSeparator:WinSeparatorA +au WinLeave * setl winhl=WinSeparator:WinSeparator +]]) + +require('notify').setup({ + background_colour = '#000000', +}) diff --git a/.config/nvim/lua/plugins/colorscheme.lua b/.config/nvim/lua/plugins/colorscheme.lua index 14edbdf..be78ac8 100644 --- a/.config/nvim/lua/plugins/colorscheme.lua +++ b/.config/nvim/lua/plugins/colorscheme.lua @@ -1,19 +1,3 @@ --- Colorscheme --- Available colorschemes: --- [[ nightfly ayu onedark doom-one nvimgelion github_dark tokyonight ]] - --- Define default color scheme -local default_colorscheme = "tokyonight-night" -local fallback_colorscheme = "desert" - --- Attempt to set the default color scheme -local status_ok, _ = pcall(vim.cmd, "colorscheme " .. default_colorscheme) - --- If the default color scheme is not found, use the fallback color scheme -if not status_ok then - vim.cmd("colorscheme " .. fallback_colorscheme) -end - --local function MyHighlights() -- vim.cmd('highlight Visual cterm=NONE ctermbg=76 ctermfg=16 gui=NONE guibg=#5fd700 guifg=#000000') -- vim.cmd('highlight StatusLine cterm=NONE ctermbg=231 ctermfg=160 gui=NONE guibg=#ffffff guifg=#d70000') @@ -30,20 +14,6 @@ end -- --setupMyColors() - -vim.api.nvim_command("syntax on") -vim.api.nvim_command("highlight Normal guibg=NONE") -vim.api.nvim_command("highlight NormalNC guibg=none") -vim.api.nvim_command("highlight SignColumn guibg=none") ---vim.api.nvim_command("highlight FoldColumn guibg=none") ---vim.api.nvim_command("highlight CursorLineSign guibg=none ctermbg=NONE") -vim.api.nvim_command("highlight TabLine guibg=#333842 gui=bold") -vim.api.nvim_command("highlight Title guibg=none gui=bold") -vim.api.nvim_command("highlight TabLineSel guibg=#333842 gui=bold") -vim.api.nvim_command("highlight TabLineFill guibg=none gui=bold") -vim.api.nvim_command("highlight WinBar guibg=none gui=bold") -vim.api.nvim_command("highlight NormalFloat guibg=none") -vim.api.nvim_command("highlight LineNr guibg=none") --vim.api.nvim_command("highlight FoldColumn guibg=none") --vim.api.nvim_command("highlight SignColumn guifg=none guibg=none cterm=NONE ctermfg=none ctermbg=NONE gui=NONE") @@ -52,20 +22,6 @@ vim.api.nvim_command("highlight LineNr guibg=none") --vim.api.nvim_command("highlight TabLineNC guibg=none gui=bold") --vim.api.nvim_command("highlight StatusLine guibg=#333842 gui=bold") --vim.api.nvim_command("highlight StatusLineNC guibg=none ctermfg=Cyan guifg=#80a0ff gui=bold") -vim.api.nvim_command("highlight WinSeparator guibg=none gui=bold") -vim.api.nvim_command("highlight MsgSeparator guibg=none") -vim.api.nvim_command("highlight PmenuSel guibg=none") -vim.api.nvim_command("highlight winblend guibg=none") -vim.api.nvim_command("highlight EndOfBuffer guibg=NONE guifg=Normal") --- Set different window separator colorscheme -vim.cmd [[ -au WinEnter * setl winhl=WinSeparator:WinSeparatorA -au WinLeave * setl winhl=WinSeparator:WinSeparator -]] - -require("notify").setup({ - background_colour = "#000000", -}) -- Custom colorscheme --vim.cmd([[ diff --git a/.config/nvim/lua/plugins/dashboard.lua b/.config/nvim/lua/plugins/dashboard.lua index b288f46..a78332b 100644 --- a/.config/nvim/lua/plugins/dashboard.lua +++ b/.config/nvim/lua/plugins/dashboard.lua @@ -1,4 +1,5 @@ -local db = require("dashboard") +local db = require('dashboard') + --vim.api.nvim_create_autocmd("VimEnter", { -- callback = function() -- -- disable line numbers @@ -7,69 +8,74 @@ local db = require("dashboard") -- -- always start in insert mode -- end, --}) + db.setup({ - theme = "hyper", - config = { - header = { - [[ ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗]], - [[ ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║]], - [[ ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║]], - [[ ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║]], - [[ ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║]], - [[ ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝]], - }, + theme = 'hyper', + config = { + mru = { limit = 10, label = '' }, + project = { limit = 10 }, + header = { + [[ ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗]], + [[ ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║]], + [[ ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║]], + [[ ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║]], + [[ ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║]], + [[ ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝]], + }, disable_move = false, - shortcut = { - { desc = " Plugins", group = "Number", action = "PackerStatus", key = "p" }, - --{ desc = " Plugins", group = "@property", action = "PackerStatus", key = "p" }, - { - desc = " Files", - group = "Number", - --group = "Label", - action = "Telescope find_files", - key = "f", - }, - { - desc = " Text", - group = "Number", - --group = "Label", - action = 'enew', - key = "t", - }, - { - desc = " Grep", - group = "Number", - --group = "Label", - action = "Telescope live_grep", - key = "g", - }, - { - desc = " Scheme", - group = "Number", - --group = "Label", - action = "Telescope colorscheme", - key = "s", - }, - { + shortcut = { + { desc = ' Plugins', group = 'Number', action = 'PackerStatus', key = 'p' }, + --{ desc = " Plugins", group = "@property", action = "PackerStatus", key = "p" }, + { + desc = ' Files', + group = 'Number', + --group = "Label", + action = 'Telescope find_files', + key = 'f', + }, + { + desc = ' Text', + group = 'Number', + --group = "Label", + action = 'enew', + key = 't', + }, + { + desc = ' Grep', + group = 'Number', + --group = "Label", + action = 'Telescope live_grep', + key = 'g', + }, + { + desc = ' Scheme', + group = 'Number', + --group = "Label", + action = 'Telescope colorscheme', + key = 's', + }, + { desc = ' Config', - group = "Number", - --group = "Label", + group = 'Number', + --group = "Label", action = ':edit ~/.config.nvim/init.lua', - key = "c", - }, - }, - }, - hide = { - statusline = false, - tabline = false, - winbar = false, - }, - -- preview = { --- command, -- preview command --- file_path, -- preview file path --- file_height, -- preview file height --- file_width, -- preview file width --- }, --- footer = {} --your footer + key = 'c', + }, + }, + footer = { '', 'Hello World!' }, + }, + hide = { + statusline = false, + tabline = false, + winbar = false, + }, }) +--highlights +---- General +--DashboardHeader DashboardFooter +---- Hyper theme +--DashboardProjectTitle DashboardProjectTitleIcon DashboardProjectIcon +--DashboardMruTitle DashboardMruIcon DashboardFiles DashboardShotCutIcon +---- Doome theme +--DashboardDesc DashboardKey DashboardIcon DashboardShotCut diff --git a/.config/nvim/lua/plugins/heirline.lua b/.config/nvim/lua/plugins/heirline.lua index 5c3eb44..46e0ccc 100644 --- a/.config/nvim/lua/plugins/heirline.lua +++ b/.config/nvim/lua/plugins/heirline.lua @@ -1,44 +1,45 @@ -local conditions = require("heirline.conditions") -local utils = require("heirline.utils") +local conditions = require('heirline.conditions') +local utils = require('heirline.utils') local colors = { --bg = "#23232e", bg = nil, - nobg = "NONE", - white = "#f8f8f2", - black = "#000000", - darkgray = "#23232e", - gray = "#2d2b3a", - lightgray = "#d6d3ea", - pink = "#f92672", - green = "#50fa7b", - blue = "#39BAE6", - yellow = "#f1fa8c", - orange = "#ffb86c", - purple = "#BF40BF", - violet = "#7F00FF", - red = "#ff5555", - cyan = "#66d9eC", + nobg = 'NONE', + white = '#f8f8f2', + black = '#000000', + darkgray = '#23232e', + gray = '#2d2b3a', + lightgray = '#d6d3ea', + pink = '#f92672', + green = '#50fa7b', + blue = '#39BAE6', + yellow = '#f1fa8c', + orange = '#ffb86c', + purple = '#BF40BF', + violet = '#7F00FF', + red = '#ff5555', + cyan = '#66d9eC', diag = { - warn = utils.get_highlight("DiagnosticSignWarn").fg, - error = utils.get_highlight("DiagnosticSignError").fg, - hint = utils.get_highlight("DiagnosticSignHint").fg, - info = utils.get_highlight("DiagnosticSignInfo").fg, + warn = utils.get_highlight('DiagnosticSignWarn').fg, + error = utils.get_highlight('DiagnosticSignError').fg, + hint = utils.get_highlight('DiagnosticSignHint').fg, + info = utils.get_highlight('DiagnosticSignInfo').fg, }, git = { - del = "#e95678", - add = "#a6e22e", - change = "#ae81ff", + active = '#f34f29', + del = '#ff5555', + add = '#50fa7b', + change = '#ae81ff', }, } -require("heirline").load_colors(colors) +require('heirline').load_colors(colors) -local Align = { provider = "%=", hl = { bg = colors.bg } } -local Space = { provider = " ", hl = { bg = colors.bg } } -local Tab = { provider = " " } -local LeftSpace = { provider = "" } -local RightSpace = { provider = "" } +local Align = { provider = '%=', hl = { bg = colors.bg } } +local Space = { provider = ' ', hl = { bg = colors.bg } } +local Tab = { provider = ' ' } +local LeftSpace = { provider = '' } +local RightSpace = { provider = '' } local ViMode = { init = function(self) @@ -50,100 +51,104 @@ local ViMode = { end, static = { mode_names = { - n = " NORMAL ", - no = "PENDING ", - nov = " N? ", - noV = " N? ", - ["no\22"] = " N? ", - niI = " Ni ", - niR = " Nr ", - niV = " Nv ", - nt = "TERMINAL", - v = " VISUAL ", - vs = " Vs ", - V = " V·LINE ", - ["\22"] = "V·BLOCK ", - ["\22s"] = "V·BLOCK ", - s = " SELECT ", - S = " S·LINE ", - ["\19"] = "S·BLOCK ", - i = " INSERT ", - ix = "insert x", - ic = "insert c", - R = "REPLACE ", - Rc = " Rc ", - Rx = " Rx ", - Rv = "V·REPLACE ", - Rvc = " Rv ", - Rvx = " Rv ", - c = "COMMAND ", - cv = " VIM EX ", - ce = " EX ", - r = " PROMPT ", - rm = " MORE ", - ["r?"] = "CONFIRM ", - ["!"] = " SHELL ", - t = "TERMINAL", + n = ' NORMAL ', + no = 'PENDING ', + nov = ' N? ', + noV = ' N? ', + ['no\22'] = ' N? ', + niI = ' Ni ', + niR = ' Nr ', + niV = ' Nv ', + nt = 'TERMINAL', + v = ' VISUAL ', + vs = ' Vs ', + V = ' V·LINE ', + ['\22'] = 'V·BLOCK ', + ['\22s'] = 'V·BLOCK ', + s = ' SELECT ', + S = ' S·LINE ', + ['\19'] = 'S·BLOCK ', + i = ' INSERT ', + ix = 'insert x', + ic = 'insert c', + R = 'REPLACE ', + Rc = ' Rc ', + Rx = ' Rx ', + Rv = 'V·REPLACE ', + Rvc = ' Rv ', + Rvx = ' Rv ', + c = 'COMMAND ', + cv = ' VIM EX ', + ce = ' EX ', + r = ' PROMPT ', + rm = ' MORE ', + ['r?'] = 'CONFIRM ', + ['!'] = ' SHELL ', + t = 'TERMINAL', }, }, provider = function(self) - return " %2(" .. self.mode_names[self.mode] .. "%) " + return ' %2(' .. self.mode_names[self.mode] .. '%) ' + end, + hl = function(self) + return { fg = 'darkgray', bg = self.mode_color, bold = true } end, - hl = function(self) return { fg = "darkgray", bg = self.mode_color, bold = true } end, update = { - "ModeChanged", + 'ModeChanged', }, } -- LSP local LSPActive = { condition = conditions.lsp_attached, - update = { "LspAttach", "LspDetach" }, + update = { 'LspAttach', 'LspDetach' }, provider = function() local buf_clients = vim.lsp.buf_get_clients() local buf_client_names = {} -- add client for _, client in pairs(buf_clients) do - if client.name ~= "null-ls" then + if client.name ~= 'null-ls' then table.insert(buf_client_names, client.name) end end - return "⚙️ " .. table.concat(buf_client_names, "") + return '⚙️ ' .. table.concat(buf_client_names, '') end, hl = { fg = colors.lightgray, bold = false }, } local Navic = { - condition = function() return require("nvim-navic").is_available() end, + condition = function() + return require('nvim-navic').is_available() + end, static = { -- create a type highlight map type_hl = { - File = "Directory", - Module = "@include", - Namespace = "@namespace", - Package = "@include", - Class = "@structure", - Method = "@method", - Property = "@property", - Field = "@field", - Constructor = "@constructor", - Enum = "@field", - Interface = "@type", - Function = "@function", - Variable = "@variable", - Constant = "@constant", - String = "@string", - Number = "@number", - Boolean = "@boolean", - Array = "@field", - Object = "@type", - Key = "@keyword", - Null = "@comment", - EnumMember = "@field", - Struct = "@structure", - Event = "@keyword", - Operator = "@operator", - TypeParameter = "@type", + File = 'Directory', + Module = '@include', + Namespace = '@namespace', + Package = '@include', + Class = '@structure', + Method = '@method', + Property = '@property', + Field = '@field', + Constructor = '@constructor', + Enum = '@field', + Interface = '@type', + Function = '@function', + Variable = '@variable', + Constant = '@constant', + String = '@string', + Number = '@number', + Boolean = '@boolean', + Array = '@field', + Object = '@type', + Key = '@keyword', + Null = '@comment', + EnumMember = '@field', + Struct = '@structure', + Event = '@keyword', + Operator = '@operator', + TypeParameter = '@type', }, -- bit operation dark magic, see below... enc = function(line, col, winnr) @@ -155,10 +160,10 @@ local Navic = { local col = bit.band(bit.rshift(c, 6), 1023) local winnr = bit.band(c, 63) return line, col, winnr - end + end, }, init = function(self) - local data = require("nvim-navic").get_data() or {} + local data = require('nvim-navic').get_data() or {} local children = {} -- create a child for each level for i, d in ipairs(data) do @@ -171,7 +176,7 @@ local Navic = { }, { -- escape `%`s (elixir) and buggy default separators - provider = d.name:gsub("%%", "%%%%"):gsub("%s*->%s*", ''), + provider = d.name:gsub('%%', '%%%%'):gsub('%s*->%s*', ''), -- highlight icon only or location name as well -- hl = self.type_hl[d.type], @@ -183,14 +188,14 @@ local Navic = { local line, col, winnr = self.dec(minwid) vim.api.nvim_win_set_cursor(vim.fn.win_getid(winnr), { line, col }) end, - name = "heirline_navic", + name = 'heirline_navic', }, }, } -- add a separator only if needed if #data > 1 and i < #data then table.insert(child, { - provider = " > ", + provider = ' > ', hl = { fg = 'bright_fg' }, }) end @@ -203,18 +208,18 @@ local Navic = { provider = function(self) return self.child:eval() end, - hl = { fg = "gray" }, - update = 'CursorMoved' + hl = { fg = 'gray' }, + update = 'CursorMoved', } -- Diagnostics local Diagnostics = { condition = conditions.has_diagnostics, static = { - error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, - warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, - info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, - hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + error_icon = vim.fn.sign_getdefined('DiagnosticSignError')[1].text, + warn_icon = vim.fn.sign_getdefined('DiagnosticSignWarn')[1].text, + info_icon = vim.fn.sign_getdefined('DiagnosticSignInfo')[1].text, + hint_icon = vim.fn.sign_getdefined('DiagnosticSignHint')[1].text, }, init = function(self) self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) @@ -222,23 +227,23 @@ local Diagnostics = { self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) end, - update = { "DiagnosticChanged", "BufEnter" }, + update = { 'DiagnosticChanged', 'BufEnter' }, { provider = function(self) -- 0 is just another output, we can decide to print it or not! - return self.errors > 0 and (self.error_icon .. self.errors .. " ") + return self.errors > 0 and (self.error_icon .. self.errors .. ' ') end, hl = { fg = colors.diag.error, bg = colors.bg }, }, { provider = function(self) - return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + return self.warnings > 0 and (self.warn_icon .. self.warnings .. ' ') end, hl = { fg = colors.diag.warn, bg = colors.bg }, }, { provider = function(self) - return self.info > 0 and (self.info_icon .. self.info .. " ") + return self.info > 0 and (self.info_icon .. self.info .. ' ') end, hl = { fg = colors.diag.info, bg = colors.bg }, }, @@ -250,11 +255,11 @@ local Diagnostics = { }, on_click = { callback = function() - require("trouble").toggle({ mode = "document_diagnostics" }) + require('trouble').toggle({ mode = 'document_diagnostics' }) -- or -- vim.diagnostic.setqflist() end, - name = "heirline_diagnostics", + name = 'heirline_diagnostics', }, } @@ -266,29 +271,44 @@ local Git = { self.status_dict = vim.b.gitsigns_status_dict self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 end, - --hl = { fg = "orange" }, - hl = { fg = colors.orange, bg = colors.bg }, + --{ + -- -- git branch name + -- provider = function(self) + -- --return ' ' .. self.status_dict.head + -- return ' ' .. self.status_dict.head + -- end, + -- --hl = { bold = true }, + -- hl = { fg = colors.git.active, bold = true, bg = colors.bg }, + --}, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + -- git branch icon + provider = function() + return ' ' + end, + hl = { fg = colors.git.active, bg = colors.bg }, + }, + { -- git branch name provider = function(self) - return " " .. self.status_dict.head + return self.status_dict.head end, - --hl = { bold = true }, - hl = { bold = true, bg = colors.bg }, + hl = { fg = colors.white, bg = colors.bg }, }, - -- You could handle delimiters, icons and counts similar to Diagnostics + { condition = function(self) return self.has_changes end, --provider = "(" - provider = " ", + provider = '', }, { provider = function(self) local count = self.status_dict.added or 0 --return count > 0 and ("+" .. count) - return count > 0 and (" " .. count) + return count > 0 and (' ' .. count) end, --hl = { fg = "git_add" }, hl = { fg = colors.git.add, bg = colors.bg }, @@ -297,7 +317,7 @@ local Git = { provider = function(self) local count = self.status_dict.removed or 0 --return count > 0 and ("-" .. count) - return count > 0 and (" " .. count) + return count > 0 and (' ' .. count) end, --hl = { fg = "git_del" }, hl = { fg = colors.git.del, bg = colors.bg }, @@ -306,7 +326,7 @@ local Git = { provider = function(self) local count = self.status_dict.changed or 0 --return count > 0 and ("~" .. count) - return count > 0 and (" 柳" .. count) + return count > 0 and (' ' .. count) end, --hl = { fg = "git_change" }, hl = { fg = colors.git.change, bg = colors.bg }, @@ -327,10 +347,10 @@ local Git = { -- opening of a floating window -- (this also applies to telescope) vim.defer_fn(function() - vim.cmd("Lazygit") + vim.cmd('Lazygit') end, 100) end, - name = "heirline_git", + name = 'heirline_git', }, } @@ -455,12 +475,11 @@ local FileNameBlock = { local FileIcon = { init = function(self) local filename = self.filename - local extension = vim.fn.fnamemodify(filename, ":e") - self.icon, self.icon_color = - require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + local extension = vim.fn.fnamemodify(filename, ':e') + self.icon, self.icon_color = require('nvim-web-devicons').get_icon_color(filename, extension, { default = true }) end, provider = function(self) - return self.icon and (self.icon .. " ") + return self.icon and (self.icon .. ' ') end, hl = function(self) return { fg = self.icon_color, bg = colors.bg } @@ -471,9 +490,9 @@ local FileName = { provider = function(self) -- first, trim the pattern relative to the current directory. For other -- options, see :h filename-modifers - local filename = vim.fn.fnamemodify(self.filename, ":.") - if filename == "" then - return "No Name" + local filename = vim.fn.fnamemodify(self.filename, ':.') + if filename == '' then + return 'No Name' end -- now, if the filename would occupy more than 1/4th of the available -- space, we trim the file path to its initials @@ -491,7 +510,7 @@ local FileFlags = { { provider = function() if vim.bo.modified then - return " [+]" -- ±[+] + return ' [+]' -- ±[+] end end, hl = { fg = colors.green, bg = colors.bg }, @@ -499,7 +518,7 @@ local FileFlags = { { provider = function() if not vim.bo.modifiable or vim.bo.readonly then - return " " + return ' ' end end, --hl = { fg = colors.orange }, @@ -526,7 +545,7 @@ local FileType = { local FileEncoding = { Space, provider = function() - local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + local enc = (vim.bo.fenc ~= '' and vim.bo.fenc) or vim.o.enc -- :h 'enc' return enc:lower() end, --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, @@ -537,34 +556,34 @@ local FileFormat = { provider = function() local fmt = vim.bo.fileformat --return fmt ~= "unix" and fmt:upper() - return fmt ~= "unix" and fmt:lower() + return fmt ~= 'unix' and fmt:lower() end, - hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight('Statusline').fg, bold = true, bg = colors.bg }, } -- FileSize and FileLastModified local FileSize = { provider = function() -- stackoverflow, compute human readable file size - local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local suffix = { 'b', 'k', 'M', 'G', 'T', 'P', 'E' } local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) fsize = (fsize < 0 and 0) or fsize if fsize < 1024 then return fsize .. suffix[1] end local i = math.floor((math.log(fsize) / math.log(1024))) - return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + return string.format('%.2g%s', fsize / math.pow(1024, i), suffix[i + 1]) end, - hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight('Statusline').fg, bold = true, bg = colors.bg }, } local FileLastModified = { -- did you know? Vim is full of functions! provider = function() local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) - return (ftime > 0) and os.date("%c", ftime) + return (ftime > 0) and os.date('%c', ftime) end, - hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight('Statusline').fg, bold = true, bg = colors.bg }, } -- Spell @@ -573,17 +592,17 @@ local Spell = { condition = function() return vim.wo.spell end, - provider = " 暈", + provider = ' 暈', hl = { bold = true, fg = colors.yellow }, } local HelpFileName = { condition = function() - return vim.bo.filetype == "help" + return vim.bo.filetype == 'help' end, provider = function() local filename = vim.api.nvim_buf_get_name(0) - return vim.fn.fnamemodify(filename, ":t") + return vim.fn.fnamemodify(filename, ':t') end, hl = { fg = colors.blue }, } @@ -600,37 +619,37 @@ local SearchCount = { end, provider = function(self) local search = self.search - return string.format("[%d/%d]", search.current, math.min(search.total, search.maxcount)) + return string.format('[%d/%d]', search.current, math.min(search.total, search.maxcount)) end, } local MacroRec = { condition = function() - return vim.fn.reg_recording() ~= "" and vim.o.cmdheight == 0 + return vim.fn.reg_recording() ~= '' and vim.o.cmdheight == 0 end, - provider = " ", - hl = { fg = "orange", bold = true }, - utils.surround({ "[", "]" }, nil, { + provider = ' ', + hl = { fg = 'orange', bold = true }, + utils.surround({ '[', ']' }, nil, { provider = function() return vim.fn.reg_recording() end, - hl = { fg = "green", bold = true }, + hl = { fg = 'green', bold = true }, }), update = { - "RecordingEnter", - "RecordingLeave", - } + 'RecordingEnter', + 'RecordingLeave', + }, } local ShowCmd = { condition = function() return vim.o.cmdheight == 0 end, - provider = ":%3.5(%S%)", + provider = ':%3.5(%S%)', } local cursor_location = { - { provider = " %1(%4l:%-3(%c%) %)%*", hl = { fg = colors.black, bold = true } }, + { provider = '%1(%4l:%-3(%c%)%) %*', hl = { fg = colors.black, bold = true } }, } local Ruler = { cursor_location } @@ -655,16 +674,16 @@ local WordCount = { condition = function() return conditions.buffer_matches({ filetype = { - "markdown", - "txt", - "vimwiki", + 'markdown', + 'txt', + 'vimwiki', }, }) end, Space, { provider = function() - return "W:" .. vim.fn.wordcount().words + return 'W:' .. vim.fn.wordcount().words end, }, } @@ -672,31 +691,31 @@ local WordCount = { -- Working Directory local WorkDir = { init = function(self) - self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + self.icon = (vim.fn.haslocaldir(0) == 1 and 'l' or 'g') .. ' ' .. ' ' local cwd = vim.fn.getcwd(0) - self.cwd = vim.fn.fnamemodify(cwd, ":~") + self.cwd = vim.fn.fnamemodify(cwd, ':~') end, - hl = { fg = "colors.blue", bold = true }, + hl = { fg = 'colors.blue', bold = true }, flexible = 1, { -- evaluates to the full-lenth path provider = function(self) - local trail = self.cwd:sub(-1) == "/" and "" or "/" - return self.icon .. self.cwd .. trail .. " " + local trail = self.cwd:sub(-1) == '/' and '' or '/' + return self.icon .. self.cwd .. trail .. ' ' end, }, { -- evaluates to the shortened path provider = function(self) local cwd = vim.fn.pathshorten(self.cwd) - local trail = self.cwd:sub(-1) == "/" and "" or "/" - return self.icon .. cwd .. trail .. " " + local trail = self.cwd:sub(-1) == '/' and '' or '/' + return self.icon .. cwd .. trail .. ' ' end, }, { -- evaluates to "", hiding the component - provider = "", - } + provider = '', + }, } -- Snippets Indicator @@ -720,7 +739,7 @@ FileNameBlock = utils.insert( FileIcon, utils.insert(FileNameModifier, FileName), -- a new table where FileName is a child of FileNameModifier unpack(FileFlags), -- A small optimisation, since their parent does nothing - { provider = "%<" } -- this means that the statusline is cut here when there's not enough space + { provider = '%<' } -- this means that the statusline is cut here when there's not enough space ) local FileInfoBlock = { @@ -735,30 +754,32 @@ FileInfoBlock = utils.insert( Space, FileIcon, FileType, - { provider = "%<" } -- this means that the statusline is cut here when there's not enough space + { provider = '%<' } -- this means that the statusline is cut here when there's not enough space ) -LeftSpace = utils.surround({ "", " " }, function(self) +LeftSpace = utils.surround({ '', '' }, function(self) return self:mode_color() -end, { LeftSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +end, { LeftSpace, hl = { fg = utils.get_highlight('statusline').bg, force = true } }) -RightSpace = utils.surround({ "", "" }, function(self) +RightSpace = utils.surround({ '', '' }, function(self) return self:mode_color() -end, { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +end, { RightSpace, hl = { fg = utils.get_highlight('statusline').bg, force = true } }) -LSPActive = utils.surround({ "", "" }, function(self) +LSPActive = utils.surround({ '', '' }, function(self) return self:mode_color() end, { Space, LSPActive, hl = { bg = colors.darkgray, force = true } }) -FileInfoBlock = utils.surround({ "", "" }, function(self) +FileInfoBlock = utils.surround({ '', '' }, function(self) return self:mode_color() end, { FileInfoBlock, Space, hl = { bg = colors.gray, force = true } }) -Ruler = utils.surround({ "", "" }, colors.gray, { Ruler, hl = { fg = colors.gray, force = true } }) +Ruler = utils.surround({ '', '' }, colors.gray, { Ruler, hl = { fg = colors.gray, force = true } }) local left = { - { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { bg = colors.nobg, force = true } }, + { ViMode, hl = { fg = utils.get_highlight('statusline').bg, force = true } }, { LeftSpace, hl = { bg = colors.nobg, force = true } }, + { Space, hl = { bg = colors.nobg, force = true } }, { FileNameBlock, hl = { bg = colors.nobg, force = true } }, { Space, hl = { bg = colors.nobg, force = true } }, { Git, hl = { bg = colors.nobg, force = true } }, @@ -779,15 +800,17 @@ local right = { { Space, hl = { bg = colors.nobg, force = true } }, { FileInfoBlock, hl = { bg = colors.nobg, force = true } }, { RightSpace, hl = { bg = colors.nobg, force = true } }, - { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight('statusline').bg, force = true } }, + { LeftSpace, hl = { bg = colors.nobg, force = true } }, } local sections = { left, middle, right } local DefaultStatusline = { sections } local specialleft = { - { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, - { LeftSpace, hl = { bg = colors.nobg, force = true } }, + { RightSpace, hl = { bg = colors.nobg, force = true } }, + { ViMode, hl = { fg = utils.get_highlight('statusline').bg, force = true } }, + { LeftSpace, hl = { bg = colors.nobg, force = true } }, } local specialmiddle = { @@ -798,7 +821,8 @@ local specialmiddle = { local specialright = { { RightSpace, hl = { bg = colors.nobg, force = true } }, - { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight('statusline').bg, force = true } }, + { LeftSpace, hl = { bg = colors.nobg, force = true } }, } local specialsections = { specialleft, specialmiddle, specialright } @@ -807,26 +831,26 @@ local InactiveStatusline = { condition = conditions.is_not_active, --{ FileNameBlock, hl = { bg = colors.nobg, force = true } }, --{ Align, hl = { bg = colors.nobg, force = true } }, - specialsections + specialsections, } local SpecialStatusline = { condition = function() return conditions.buffer_matches({ - buftype = { "nofile", "prompt", "help", "quickfix" }, - filetype = { "^git.*", "fugitive", "dashboard", }, + buftype = { 'nofile', 'prompt', 'help', 'quickfix' }, + filetype = { '^git.*', 'fugitive', 'dashboard' }, }) end, - specialsections + specialsections, } --local InactiveStatusline = SpecialStatusline local TerminalStatusline = { condition = function() - return conditions.buffer_matches({ buftype = { "terminal" } }) + return conditions.buffer_matches({ buftype = { 'terminal' } }) end, - specialsections + specialsections, } local StatusLine = { @@ -851,7 +875,7 @@ local StatusLine = { no = colors.blue, nov = colors.blue, noV = colors.blue, - ["no\22"] = colors.blue, + ['no\22'] = colors.blue, niI = colors.blue, niR = colors.blue, niV = colors.blue, @@ -859,11 +883,11 @@ local StatusLine = { v = colors.purple, vs = colors.purple, V = colors.purple, - ["\22"] = colors.purple, - ["\22s"] = colors.purple, + ['\22'] = colors.purple, + ['\22s'] = colors.purple, s = colors.purple, S = colors.purple, - ["\19"] = colors.purple, + ['\19'] = colors.purple, i = colors.green, ix = colors.green, ic = colors.green, @@ -878,12 +902,12 @@ local StatusLine = { ce = colors.orange, r = colors.red, rm = colors.red, - ["r?"] = colors.red, - ["!"] = colors.orange, + ['r?'] = colors.red, + ['!'] = colors.orange, t = colors.orange, }, mode_color = function(self) - local mode = conditions.is_active() and vim.fn.mode() or "n" + local mode = conditions.is_active() and vim.fn.mode() or 'n' return self.mode_colors[mode] end, hl = function(self) @@ -898,7 +922,6 @@ local StatusLine = { DefaultStatusline, } - -- --- WinBar -- @@ -914,9 +937,9 @@ local WinbarFileName = { provider = function(self) -- first, trim the pattern relative to the current directory. For other -- options, see :h filename-modifers - local filename = vim.fn.fnamemodify(self.filename, ":.") - if filename == "" then - return "No Name" + local filename = vim.fn.fnamemodify(self.filename, ':.') + if filename == '' then + return 'No Name' end -- now, if the filename would occupy more than 1/4th of the available -- space, we trim the file path to its initials @@ -935,15 +958,15 @@ WinbarFileNameBlock = utils.insert( FileIcon, utils.insert(WinbarFileName), -- a new table where FileName is a child of FileNameModifier unpack(FileFlags), -- A small optimisation, since their parent does nothing - { provider = "%<" } -- this means that the statusline is cut here when there's not enough space + { provider = '%<' } -- this means that the statusline is cut here when there's not enough space ) -vim.api.nvim_create_autocmd("User", { - pattern = "HeirlineInitWinbar", +vim.api.nvim_create_autocmd('User', { + pattern = 'HeirlineInitWinbar', callback = function(args) local buf = args.buf - local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) - local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + local buftype = vim.tbl_contains({ 'prompt', 'nofile', 'help', 'quickfix' }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ 'gitcommit', 'fugitive' }, vim.bo[buf].filetype) if buftype or filetype then vim.opt_local.winbar = nil end @@ -970,11 +993,11 @@ local CloseButton = { end, -- a small performance improvement: -- re register the component callback only on layout/buffer changes. - update = { "WinNew", "WinClosed", "BufEnter" }, - { provider = " " }, + update = { 'WinNew', 'WinClosed', 'BufEnter' }, + { provider = ' ' }, { - provider = "", - hl = { fg = "gray" }, + provider = '', + hl = { fg = 'gray' }, On_click = { minwid = function() return vim.api.nvim_get_current_win() @@ -982,7 +1005,7 @@ local CloseButton = { callback = function(_, minwid) vim.api.nvim_win_close(minwid, true) end, - name = "heirline_winbar_close_button", + name = 'heirline_winbar_close_button', }, }, } @@ -993,8 +1016,8 @@ local Center = { -- Hide the winbar for special buffers condition = function() return conditions.buffer_matches({ - buftype = { "terminal", "nofile", "prompt", "help", "quickfix" }, - filetype = { "dap-ui", "NvimTree", "^git.*", "fugitive", "dashboard", }, + buftype = { 'terminal', 'nofile', 'prompt', 'help', 'quickfix' }, + filetype = { 'dap-ui', 'NvimTree', '^git.*', 'fugitive', 'dashboard' }, }) end, init = function() @@ -1004,7 +1027,7 @@ local Center = { { -- A special winbar for terminals condition = function() - return conditions.buffer_matches({ buftype = { "terminal" } }) + return conditions.buffer_matches({ buftype = { 'terminal' } }) end, FileType, Space, @@ -1016,16 +1039,15 @@ local Center = { return not conditions.is_active() end, --utils.surround({ "", "" }, colors.nobg, { FileIcon, { WinbarFileName, hl = { fg = colors.gray } }, FileFlags } ), - utils.surround({ "", "" }, colors.nobg, { WinbarFileNameBlock }), + utils.surround({ '', '' }, colors.nobg, { WinbarFileNameBlock }), }, -- A winbar for regular files - utils.surround({ "", "" }, colors.nobg, { FileNameBlock }), + utils.surround({ '', '' }, colors.nobg, { FileNameBlock }), } --local WinBar = { Align, Center, Align } local WinBar = { Space, Center } - -- TabLine --local TablineBufnr = { -- provider = function(self) @@ -1040,7 +1062,7 @@ local TablineFileName = { provider = function(self) -- self.filename will be defined later, just keep looking at the example! local filename = self.filename - filename = filename == "" and "No Name" or vim.fn.fnamemodify(filename, ":t") + filename = filename == '' and 'No Name' or vim.fn.fnamemodify(filename, ':t') return filename end, hl = function(self) @@ -1052,7 +1074,7 @@ local TablineFileFlags = { { provider = function(self) if vim.bo[self.bufnr].modified then - return " [+] " + return ' [+] ' end end, hl = { fg = colors.green }, @@ -1060,22 +1082,21 @@ local TablineFileFlags = { { provider = function(self) if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then - return " " + return ' ' end end, - hl = { fg = "orange" }, + hl = { fg = 'orange' }, }, } local TablineFileIcon = { init = function(self) local filename = self.filename - local extension = vim.fn.fnamemodify(filename, ":e") - self.icon, self.icon_color = - require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + local extension = vim.fn.fnamemodify(filename, ':e') + self.icon, self.icon_color = require('nvim-web-devicons').get_icon_color(filename, extension, { default = true }) end, provider = function(self) - return self.icon and (" " .. self.icon .. " ") + return self.icon and (' ' .. self.icon .. ' ') end, hl = function(self) return { fg = self.icon_color } @@ -1089,17 +1110,17 @@ local TablineFileNameBlock = { end, hl = function(self) if self.is_active then - return "TabLineSel" + return 'TabLineSel' -- why not? --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then --return { fg = "gray", bg = colors.bg } else - return "TabLineFill" + return 'TabLineFill' end end, on_click = { callback = function(_, minwid, _, button) - if button == "m" then -- close on mouse middle click + if button == 'm' then -- close on mouse middle click vim.api.nvim_buf_delete(minwid, { force = false }) else vim.api.nvim_win_set_buf(0, minwid) @@ -1108,7 +1129,7 @@ local TablineFileNameBlock = { minwid = function(self) return self.bufnr end, - name = "heirline_tabline_buffer_callback", + name = 'heirline_tabline_buffer_callback', }, --TablineBufnr, TablineFileIcon, @@ -1119,11 +1140,11 @@ local TablineFileNameBlock = { -- a nice "x" button to close the buffer local TablineCloseButton = { condition = function(self) - return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + return not vim.api.nvim_buf_get_option(self.bufnr, 'modified') end, - { provider = " " }, + { provider = ' ' }, { - provider = " ", + provider = ' ', --hl = { fg = "red", bg = colors.bg }, hl = { fg = colors.red }, on_click = { @@ -1133,43 +1154,43 @@ local TablineCloseButton = { minwid = function(self) return self.bufnr end, - name = "heirline_tabline_close_buffer_callback", + name = 'heirline_tabline_close_buffer_callback', }, }, } -- The final touch! -local TablineBufferBlock = utils.surround({ "", "" }, function(self) +local TablineBufferBlock = utils.surround({ '', '' }, function(self) --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) if self.is_active then - return utils.get_highlight("TabLineSel").bg + return utils.get_highlight('TabLineSel').bg else - return utils.get_highlight("TabLineFill").bg + return utils.get_highlight('TabLineFill').bg end end, { Tab, TablineFileNameBlock, TablineCloseButton }) local BufferLine = utils.make_buflist( TablineBufferBlock, - { provider = " ", hl = { fg = colors.white } }, -- left truncation, optional (defaults to "<") - { provider = " ", hl = { fg = colors.white } } -- right trunctation, also optional (defaults to ...... yep, ">") + { provider = ' ', hl = { fg = colors.white } }, -- left truncation, optional (defaults to "<") + { provider = ' ', hl = { fg = colors.white } } -- right trunctation, also optional (defaults to ...... yep, ">") -- by the way, open a lot of buffers and try clicking them ;) ) -- TabList local Tabpage = { provider = function(self) - return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + return '%' .. self.tabnr .. 'T ' .. self.tabnr .. ' %T' end, hl = function(self) if not self.is_active then - return "TabLineFill" + return 'TabLineFill' else - return "TabLineSel" + return 'TabLineSel' end end, } local TabpageClose = { - provider = "%999X %X", + provider = '%999X %X', --hl = "TabLine", hl = { fg = colors.red, bg = colors.bg }, } @@ -1180,7 +1201,7 @@ local TabPages = { return #vim.api.nvim_list_tabpages() >= 2 end, { - provider = "%=", + provider = '%=', }, utils.make_tablist(Tabpage), TabpageClose, @@ -1193,8 +1214,8 @@ local TabLineOffset = { local bufnr = vim.api.nvim_win_get_buf(win) self.winid = win - if vim.api.nvim_buf_get_option(bufnr, "filetype") == "NvimTree" then - self.title = "NvimTree" + if vim.api.nvim_buf_get_option(bufnr, 'filetype') == 'NvimTree' then + self.title = 'NvimTree' return true end end, @@ -1202,15 +1223,17 @@ local TabLineOffset = { local title = self.title local width = vim.api.nvim_win_get_width(self.winid) local pad = math.ceil((width - #title) / 2) - return string.rep(" ", pad) .. title .. string.rep(" ", pad) - end, - hl = function(self) - if vim.api.nvim_get_current_win() == self.winid then - return "TablineSel" - else - return "TablineFill" - end + return string.rep(' ', pad) .. title .. string.rep(' ', pad) end, + hl = { fg = colors.white, bg = '#333842', bold = true }, + + --hl = function(self) + -- if vim.api.nvim_get_current_win() == self.winid then + -- return 'TablineSel' + -- else + -- return 'TablineFill' + -- end + --end, } local TabLine = { @@ -1219,7 +1242,7 @@ local TabLine = { TabPages, } -require("heirline").setup({ +require('heirline').setup({ statusline = StatusLine, winbar = WinBar, tabline = TabLine, @@ -1245,7 +1268,7 @@ local function goto_buf(index) end local function addKey(key, index) - vim.keymap.set("", "<A-" .. key .. ">", function() + vim.keymap.set('', '<A-' .. key .. '>', function() goto_buf(index) end, { noremap = true, silent = true }) end @@ -1253,4 +1276,4 @@ end for i = 1, 9 do addKey(i, i) end -addKey("0", 10) +addKey('0', 10) diff --git a/.config/nvim/lua/plugins/loclist.lua b/.config/nvim/lua/plugins/loclist.lua new file mode 100644 index 0000000..9b72a94 --- /dev/null +++ b/.config/nvim/lua/plugins/loclist.lua @@ -0,0 +1,18 @@ +local M = {} + +function M.loclist_toggle() + for _, info in ipairs(vim.fn.getwininfo()) do + if info.loclist == 1 then + vim.cmd('lclose') + return + end + end + + if next(vim.fn.getloclist(0)) == nil then + print('loc list empty') + return + end + vim.cmd('lopen') +end + +return M diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index b875182..92278f3 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -1,140 +1,127 @@ ---local mason = require('mason') -require("mason").setup() -require("mason-null-ls").setup({ - handlers = {}, - ensure_installed = nil, - automatic_installation = true, - automatic_setup = true, -}) -local lspconfig = require("lspconfig") -local mason_lspconfig = require("mason-lspconfig") -local null_ls = require("null-ls") ---local lsp_lines = require('lsp_lines') +local lspconfig = require('lspconfig') +local mason_lspconfig = require('mason-lspconfig') +local null_ls = require('null-ls') +-- local lsp_lines = require('lsp_lines') +require('mason').setup() +require('mason-null-ls').setup({ handlers = {}, ensure_installed = nil, automatic_installation = true, automatic_setup = true }) local keymap = vim.keymap local cmd = vim.cmd -local border = { - { "┌", "FloatBorder" }, - { "─", "FloatBorder" }, - { "┐", "FloatBorder" }, - { "│", "FloatBorder" }, - { "┘", "FloatBorder" }, - { "─", "FloatBorder" }, - { "└", "FloatBorder" }, - { "│", "FloatBorder" }, -} - -local signs = { Error = " ", Warn = "▲", Info = "", Hint = "⚑" } -for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) -end +local border = { { '┌', 'FloatBorder' }, { '─', 'FloatBorder' }, { '┐', 'FloatBorder' }, { '│', 'FloatBorder' }, { '┘', 'FloatBorder' }, { '─', 'FloatBorder' }, { '└', 'FloatBorder' }, { '│', 'FloatBorder' } } + +-- Set up LSP servers if not done before +if not vim.g.lsp_setup_done then + -- Clear existing LSP clients + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + local clients = require('user.mods').get_lsp_clients(bufnr) ---lsp_lines.setup() - ---vim.keymap.set("n", "g?", function() --- local lines_enabled = not vim.diagnostic.config().virtual_lines --- vim.diagnostic.config( --- { --- virtual_lines = lines_enabled, --- virtual_text = not lines_enabled --- } --- ) ---end, { noremap = true, silent = true }) - -vim.diagnostic.config({ - underline = false, - signs = true, - virtual_text = true, - --virtual_lines = { only_current_line = true }, - virtual_lines = false, - float = { - show_header = true, - source = "if_many", - --border = 'rounded', - border = border, - focusable = true, - }, - update_in_insert = false, -- default to false - severity_sort = false, -- default to false -}) - -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - underline = false, - virtual_text = false, - signs = true, - update_in_insert = false, -}) - -vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) -vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) - --- Use an on_attach function to only map the following keys after the language server attaches to the current buffer -local on_attach = function(client, bufnr) - -- Enable completion triggered by <c-x><c-o> - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - local map = function(mode, l, r, opts) - opts = opts or {} - opts.silent = true - opts.noremap = true - opts.buffer = bufnr - keymap.set(mode, l, r, opts) + for _, client in ipairs(clients) do + client.stop() + end end - -- Mappings - map("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>") - --map("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>") - map("n", "gd", "<cmd>lua require('goto-preview').goto_preview_definition()<CR>") - --map("n", "gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>") - map("n", "gi", "<cmd>lua require('goto-preview').goto_preview_implementation()<CR>") - --map("n", "gr", "<Cmd>lua vim.lsp.buf.references()<CR>") - map("n", "gr", "<cmd>lua require('goto-preview').goto_preview_references()<CR>") - map("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>") -- most lsp servers don't implement textDocument/Declaration, so gD is useless for now. - map("n", "<leader>k", "<Cmd>lua vim.lsp.buf.signature_help()<CR>") - --map("n", "gt", "<Cmd>lua vim.lsp.buf.type_definition()<CR>") - map("n", "gt", "<cmd>lua require('goto-preview').goto_preview_type_definition()<CR>") - map("n", "gn", "<Cmd>lua vim.lsp.buf.rename()<CR>") - map("n", "ga", "<Cmd>lua vim.lsp.buf.code_action()<CR>") - map("n", "gf", "<Cmd>lua vim.lsp.buf.formatting()<CR>") - map("n", "go", "<Cmd>lua vim.diagnostic.open_float()<CR>") - map( - "n", - "<leader>go", - ":call utils#ToggleDiagnosticsOpenFloat()<CR> | :echom ('Toggle Diagnostics Float open/close...')<CR> | :sl! | echo ('')<CR>" - ) - map("n", "[d", "<Cmd>lua vim.diagnostic.goto_prev()<CR>") - map("n", "]d", "<Cmd>lua vim.diagnostic.goto_next()<CR>") - map("n", "gs", "<Cmd>lua vim.lsp.buf.document_symbol()<CR>") - map("n", "gw", "<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>") - map("n", "<leader>wa", "<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>") - map("n", "<leader>wr", "<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>") - map("n", "<leader>wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end) - - -- TODO: Use the nicer new API for autocommands - cmd("augroup lsp_aucmds") - if client.server_capabilities.documentHighlightProvider then - cmd("au CursorHold <buffer> lua vim.lsp.buf.document_highlight()") - cmd("au CursorMoved <buffer> lua vim.lsp.buf.clear_references()") + + local signs = { Error = ' ', Warn = '▲', Info = '', Hint = '⚑' } + -- + for type, icon in pairs(signs) do + local hl = 'DiagnosticSign' .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end - cmd("augroup END") -end --- Toggle diagnostics visibility -vim.g.diagnostics_visible = true -function _G.toggle_diagnostics() - if vim.g.diagnostics_visible then - vim.g.diagnostics_visible = false - vim.diagnostic.disable() - else - vim.g.diagnostics_visible = true - vim.diagnostic.enable() + -- lsp_lines.setup() + + -- vim.keymap.set("n", "g?", function() + -- local lines_enabled = not vim.diagnostic.config().virtual_lines + -- vim.diagnostic.config( + -- { + -- virtual_lines = lines_enabled, + -- virtual_text = not lines_enabled + -- } + -- ) + -- end, { noremap = true, silent = true }) + + vim.diagnostic.config({ + underline = false, + signs = true, + virtual_text = true, -- virtual_lines = { only_current_line = true }, + virtual_lines = false, + float = { + show_header = true, + source = 'if_many', -- border = 'rounded', + border = border, + focusable = true, + }, + update_in_insert = false, -- default to false + severity_sort = true, -- default to false + }) + + vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { underline = false, virtual_text = false, signs = true, update_in_insert = false }) + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'rounded' }) + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = 'rounded' }) + + -- Use an on_attach function to only map the following keys after the language server attaches to the current buffer + local on_attach = function(client, bufnr) + -- Enable completion triggered by <c-x><c-o> + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.noremap = true + opts.buffer = bufnr + keymap.set(mode, l, r, opts) + end + -- Mappings + map('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>') + -- map("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>") + map('n', 'gd', "<cmd>lua require('goto-preview').goto_preview_definition()<CR>") + -- map("n", "gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>") + map('n', 'gi', "<cmd>lua require('goto-preview').goto_preview_implementation()<CR>") + -- map("n", "gr", "<Cmd>lua vim.lsp.buf.references()<CR>") + map('n', 'gr', "<cmd>lua require('goto-preview').goto_preview_references()<CR>") + map('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>') -- most lsp servers don't implement textDocument/Declaration, so gD is useless for now. + map('n', '<leader>k', '<Cmd>lua vim.lsp.buf.signature_help()<CR>') + -- map("n", "gt", "<Cmd>lua vim.lsp.buf.type_definition()<CR>") + map('n', 'gt', "<cmd>lua require('goto-preview').goto_preview_type_definition()<CR>") + map('n', 'gn', '<Cmd>lua vim.lsp.buf.rename()<CR>') + map('n', 'ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>') + map('n', 'gf', '<Cmd>lua vim.lsp.buf.formatting()<CR>') + map('n', 'go', '<Cmd>lua vim.diagnostic.open_float()<CR>') + map('n', '<leader>go', ":call utils#ToggleDiagnosticsOpenFloat()<CR> | :echom ('Toggle Diagnostics Float open/close...')<CR> | :sl! | echo ('')<CR>") + map('n', 'gq', '<Cmd>lua vim.diagnostic.setloclist()<CR>') + map('n', '[d', '<Cmd>lua vim.diagnostic.goto_prev()<CR>') + map('n', ']d', '<Cmd>lua vim.diagnostic.goto_next()<CR>') + map('n', 'gs', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>') + map('n', 'gw', '<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>') + map('n', '<leader>wa', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>') + map('n', '<leader>wr', '<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>') + map('n', '<leader>wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end) + + -- TODO: Use the nicer new API for autocommands + cmd('augroup lsp_aucmds') + if client.server_capabilities.documentHighlightProvider then + cmd('au CursorHold <buffer> lua vim.lsp.buf.document_highlight()') + cmd('au CursorMoved <buffer> lua vim.lsp.buf.clear_references()') + end + cmd('augroup END') end -end --- Open float for diagnostics automatically -vim.cmd([[ + -- Toggle diagnostics visibility + vim.g.diagnostics_visible = true + function _G.toggle_diagnostics() + if vim.g.diagnostics_visible then + vim.g.diagnostics_visible = false + vim.diagnostic.disable() + else + vim.g.diagnostics_visible = true + vim.diagnostic.enable() + end + end + + -- Open float for diagnostics automatically + vim.cmd([[ augroup OpenFloat " autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,}) autocmd CursorHold * lua vim.diagnostic.open_float(nil, {focusable = false,}) @@ -142,337 +129,288 @@ augroup OpenFloat augroup END ]]) --- Suppress error messages from lang servers -vim.lsp.set_log_level("debug") -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require("cmp_nvim_lsp").default_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true -capabilities.offsetEncoding = { "utf-16" } - -local function prefer_null_ls_fmt(client) - client.server_capabilities.documentHighlightProvider = true - client.server_capabilities.documentFormattingProvider = true - on_attach(client) -end + -- Suppress error messages from lang servers + vim.lsp.set_log_level('debug') + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').default_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities.offsetEncoding = { 'utf-16' } -local servers = { - asm_lsp = {}, - bashls = {}, - clangd = {}, - cssls = { - filetypes = { "css", "scss", "less", "sass" }, - root_dir = lspconfig.util.root_pattern("package.json", ".git"), - }, - -- ghcide = {}, - html = {}, - jsonls = { prefer_null_ls = true, cmd = { "--stdio" } }, - intelephense = {}, - julials = { - on_new_config = function(new_config, _) - local julia = vim.fn.expand("~/.julia/environments/nvim-lspconfig/bin/julia") - if lspconfig.util.path.is_file(julia) then - new_config.cmd[1] = julia - end - end, - settings = { julia = { format = { indent = 2 } } }, - }, - pyright = { - settings = { - python = { - formatting = { provider = "yapf" }, - linting = { pytypeEnabled = true }, - }, + local function prefer_null_ls_fmt(client) + client.server_capabilities.documentHighlightProvider = true + client.server_capabilities.documentFormattingProvider = true + on_attach(client) + end + + local servers = { + asm_lsp = {}, + bashls = {}, + clangd = {}, + cssls = { filetypes = { 'css', 'scss', 'less', 'sass' }, root_dir = lspconfig.util.root_pattern('package.json', '.git') }, -- ghcide = {}, + html = {}, + jsonls = { prefer_null_ls = true, cmd = { '--stdio' } }, + intelephense = {}, + julials = { + on_new_config = function(new_config, _) + local julia = vim.fn.expand('~/.julia/environments/nvim-lspconfig/bin/julia') + if lspconfig.util.path.is_file(julia) then + new_config.cmd[1] = julia + end + end, + settings = { julia = { format = { indent = 2 } } }, }, - }, - rust_analyzer = { - settings = { - ["rust-analyzer"] = { - cargo = { allFeatures = true }, - checkOnSave = { - command = "clippy", - extraArgs = { "--no-deps" }, - }, + pyright = { settings = { python = { formatting = { provider = 'yapf' }, linting = { pytypeEnabled = true } } } }, + rust_analyzer = { + settings = { + ['rust-analyzer'] = { cargo = { allFeatures = true }, checkOnSave = { command = 'clippy', extraArgs = { '--no-deps' } } }, }, }, - }, - dartls = { - cmd = { "dart", "language-server", "--protocol=lsp" }, - filetypes = { "dart" }, - init_options = { - closingLabels = true, - flutterOutline = true, - onlyAnalyzeProjectsWithOpenFiles = true, - outline = true, - suggestFromUnimportedLibraries = true, + dartls = { + cmd = { 'dart', 'language-server', '--protocol=lsp' }, + filetypes = { 'dart' }, + init_options = { + closingLabels = true, + flutterOutline = true, + onlyAnalyzeProjectsWithOpenFiles = true, + outline = true, + suggestFromUnimportedLibraries = true, + }, -- root_dir = root_pattern("pubspec.yaml"), + settings = { dart = { completeFunctionCalls = true, showTodos = true } }, + on_attach = function(client, bufnr) end, }, - -- root_dir = root_pattern("pubspec.yaml"), - settings = { - dart = { - completeFunctionCalls = true, - showTodos = true, - }, - }, - on_attach = function(client, bufnr) end, - }, - lua_ls = { - on_attach = on_attach, - capabilities = capabilities, - debounce_text_changes = 500, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - path = vim.split(package.path, ";"), - }, - diagnostics = { - enable = true, - globals = { "vim" }, - }, - workspace = { - maxPreload = 2000, - preloadFileSize = 50000, - checkThirdParty = false, + lua_ls = { + on_attach = on_attach, + capabilities = capabilities, + debounce_text_changes = 500, + settings = { + Lua = { + runtime = { version = 'LuaJIT', path = vim.split(package.path, ';') }, + diagnostics = { enable = true, globals = { 'vim' } }, + workspace = { maxPreload = 2000, preloadFileSize = 50000, checkThirdParty = false }, }, }, }, - }, - sqlls = {}, - tsserver = { - capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()), - on_attach = function(client) - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - end, - filetypes = { - "javascript", - "javascriptreact", - "javascript.jsx", - "typescript", - "typescriptreact", - "typescript.tsx", + sqlls = {}, + tsserver = { + capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()), + on_attach = function(client) + client.server_capabilities.document_formatting = false + client.server_capabilities.document_range_formatting = false + end, + filetypes = { 'javascript', 'javascriptreact', 'javascript.jsx', 'typescript', 'typescriptreact', 'typescript.tsx' }, }, - }, - vimls = {}, - yamlls = {}, -} - -mason_lspconfig.setup({ - ensure_installed = servers, -- will be installed by mason - automatic_installation = true, -}) - --- Your other configurations ... ---require("lspconfig").dartls.setup({ capabilities = capabilities }) ---local installed_lsp = mason_lspconfig.ensure_installed ---local mason_lspconfig = require("mason-lspconfig").ensure_installed - ---require("lspconfig").setup({ --- function() --- for _, lsp in ipairs(installed_lsp) do --- if --- lsp ~= "sqls" --- --and lsp ~= "sumneko_lua" --- --and lsp ~= "stylelint_lsp" --- --and lsp ~= "rust_analyzer" --- --and lsp ~= "sourcekit" --- and lsp ~= "dartls" --- then --- lspconfig[lsp].setup({ --- on_attach = on_attach, --- capabilities = capabilities, --- }) --- end --- end --- end, ---}) - -for server, config in pairs(servers) do - if config.prefer_null_ls then - if config.on_attach then - local old_on_attach = config.on_attach - config.on_attach = function(client, bufnr) - old_on_attach(client, bufnr) - prefer_null_ls_fmt(client) + vimls = {}, + yamlls = {}, + } + + mason_lspconfig.setup({ + ensure_installed = servers, -- will be installed by mason + automatic_installation = true, + }) + + -- Your other configurations ... + -- require("lspconfig").dartls.setup({ capabilities = capabilities }) + -- local installed_lsp = mason_lspconfig.ensure_installed + -- local mason_lspconfig = require("mason-lspconfig").ensure_installed + + -- require("lspconfig").setup({ + -- function() + -- for _, lsp in ipairs(installed_lsp) do + -- if + -- lsp ~= "sqls" + -- --and lsp ~= "sumneko_lua" + -- --and lsp ~= "stylelint_lsp" + -- --and lsp ~= "rust_analyzer" + -- --and lsp ~= "sourcekit" + -- and lsp ~= "dartls" + -- then + -- lspconfig[lsp].setup({ + -- on_attach = on_attach, + -- capabilities = capabilities, + -- }) + -- end + -- end + -- end, + -- }) + + for server, config in pairs(servers) do + if config.prefer_null_ls then + if config.on_attach then + local old_on_attach = config.on_attach + config.on_attach = function(client, bufnr) + old_on_attach(client, bufnr) + prefer_null_ls_fmt(client) + end + else + config.on_attach = prefer_null_ls_fmt end - else - config.on_attach = prefer_null_ls_fmt + elseif not config.on_attach then + config.on_attach = on_attach end - elseif not config.on_attach then - config.on_attach = on_attach + + lspconfig[server].setup(config) end - lspconfig[server].setup(config) -end + -- null_ls setup + local builtins = null_ls.builtins + local augroup = vim.api.nvim_create_augroup('LspFormatting', {}) --- null_ls setup -local builtins = null_ls.builtins -local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - ---local eslint_opts = { --- -- condition = function(utils) --- -- return utils.root_has_file ".eslintrc.js" or utils.root_has_file ".eslintrc" or utils.root_has_file ".eslintrc.json" --- -- end, --- -- diagnostics_format = "#{m} [#{c}]", --- prefer_local = true, ---} - ---null_ls.setup({ -local sources = { - -- Diagnostics - builtins.diagnostics.chktex, - --null_ls.builtins.code_actions.eslint_d, - --null_ls.builtins.diagnostics.eslint_d, - --null_ls.builtins.formatting.eslint_d, - -- null_ls.builtins.diagnostics.cppcheck, - -- null_ls.builtins.diagnostics.proselint, - -- null_ls.builtins.diagnostics.pylint, - --builtins.diagnostics.selene, - builtins.diagnostics.dotenv_linter, - builtins.diagnostics.shellcheck.with({ - -- shell script diagnostics - diagnostic_config = { - -- see :help vim.diagnostic.config() - underline = true, - virtual_text = false, - signs = true, - update_in_insert = false, - severity_sort = true, - }, - diagnostics_format = "[#{c}] #{m} (#{s})", - -- this will run every time the source runs, - -- so you should prefer caching results if possible - }), - builtins.diagnostics.zsh.with({ - filetypes = "zsh", - "sh", - }), - builtins.diagnostics.todo_comments, - builtins.diagnostics.teal, - -- null_ls.builtins.diagnostics.vale, - builtins.diagnostics.vint, - builtins.diagnostics.tidy, - builtins.diagnostics.php, - builtins.diagnostics.phpcs, - builtins.diagnostics.flake8, - builtins.diagnostics.eslint_d.with({ - condition = function(utils) - return utils.root_has_file(".eslintrc.json") + -- local eslint_opts = { + -- -- condition = function(utils) + -- -- return utils.root_has_file ".eslintrc.js" or utils.root_has_file ".eslintrc" or utils.root_has_file ".eslintrc.json" + -- -- end, + -- -- diagnostics_format = "#{m} [#{c}]", + -- prefer_local = true, + -- } + + -- null_ls.setup({ + local sources = { -- Diagnostics + builtins.diagnostics.chktex, -- null_ls.builtins.code_actions.eslint_d, + -- null_ls.builtins.diagnostics.eslint_d, + -- null_ls.builtins.formatting.eslint_d, + -- null_ls.builtins.diagnostics.cppcheck, + -- null_ls.builtins.diagnostics.proselint, + -- null_ls.builtins.diagnostics.pylint, + -- builtins.diagnostics.selene, + builtins.diagnostics.dotenv_linter, + builtins.diagnostics.shellcheck.with({ -- shell script diagnostics + diagnostic_config = { -- see :help vim.diagnostic.config() + underline = true, + virtual_text = false, + signs = true, + update_in_insert = false, + severity_sort = true, + }, + diagnostics_format = '[#{c}] #{m} (#{s})', -- this will run every time the source runs, + -- so you should prefer caching results if possible + }), + builtins.diagnostics.zsh.with({ filetypes = 'zsh', 'sh' }), + builtins.diagnostics.todo_comments, + builtins.diagnostics.teal, + -- null_ls.builtins.diagnostics.vale, + builtins.diagnostics.vint, + builtins.diagnostics.tidy, + builtins.diagnostics.php, + builtins.diagnostics.phpcs, + builtins.diagnostics.flake8, + builtins.diagnostics.eslint_d.with({ + condition = function(utils) + return utils.root_has_file('.eslintrc.json') + end, + }), + builtins.formatting.eslint_d, + -- null_ls.builtins.diagnostics.write_good.with { filetypes = { 'markdown', 'tex' } }, + + -- Formatting + builtins.formatting.shfmt.with({ filetypes = { 'bash', 'zsh', 'sh' }, extra_args = { '-i', '2', '-ci' } }), + builtins.formatting.shellharden, + builtins.formatting.trim_whitespace.with({ filetypes = { 'tmux', 'teal', 'zsh' } }), -- builtins.formatting.beautysh, + builtins.formatting.beautysh.with({ filetypes = 'zsh' }), + builtins.formatting.clang_format, + builtins.formatting.rustfmt, + builtins.formatting.sql_formatter, + -- null_ls.builtins.formatting.cmake_format, + builtins.formatting.isort, + builtins.formatting.htmlbeautifier, -- null_ls.builtins.formatting.prettier, + builtins.formatting.prettierd, + builtins.formatting.prettier.with({ + filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'json', 'yaml', 'markdown', 'html', 'css', 'scss', 'less', 'graphql', 'vue', 'svelte' }, + extra_args = { '--single-quote', '--tab-width 4', '--print-width 200' }, + }), + builtins.formatting.rustfmt, + -- builtins.formatting.stylua, + -- builtins.formatting.lua_format, + builtins.formatting.stylua.with({ + filetypes = { 'lua' }, + command = 'stylua', + args = { '--quote_style', 'AutoPreferSingle', '--indent-width', '2', '--column-width', '160', '--indent-type', 'Spaces', '-' }, + }), + -- builtins.formatting.dart_format, + builtins.formatting.dart_format.with({ filetypes = { 'dart' } }), + builtins.formatting.trim_whitespace, + builtins.formatting.yapf, + -- null_ls.builtins.formatting.black + + -- Code Actions + builtins.code_actions.shellcheck, -- shell script code actions + -- builtins.code_actions.eslint_d.with(eslint_opts), + -- null_ls.builtins.code_actions.refactoring.with { filetypes = { 'javascript', 'typescript', 'lua', 'python', 'c', 'cpp' } }, + builtins.code_actions.gitsigns, + builtins.code_actions.gitrebase, -- Hover + builtins.hover.dictionary, + builtins.hover.printenv, + } + -- }) + -- Linters/Formatters ensure installed + -- for _, pkg_name in ipairs({ + -- "dart-debug-Adaptor", + -- "stylua", + -- "prettier", + -- "prettierd", + -- }) do + + -- Import the builtins table from the null-ls module and store it in the null_ls_sources variable + null_ls.setup({ + sources = sources, + update_in_insert = true, + on_attach = function(client, bufnr) + if client.supports_method('textDocument/formatting') then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd('BufWritePre', { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format() + end, + }) + end end, - }), - builtins.formatting.eslint_d, - -- null_ls.builtins.diagnostics.write_good.with { filetypes = { 'markdown', 'tex' } }, - - -- Formatting - builtins.formatting.shfmt.with({ - filetypes = { "bash", "zsh", "sh" }, - extra_args = { "-i", "2", "-ci" }, - }), - builtins.formatting.shellharden, - builtins.formatting.trim_whitespace.with({ - filetypes = { "tmux", "teal", "zsh" }, - }), - --builtins.formatting.beautysh, - builtins.formatting.beautysh.with({ - filetypes = "zsh", - }), - builtins.formatting.clang_format, - builtins.formatting.rustfmt, - builtins.formatting.sql_formatter, - -- null_ls.builtins.formatting.cmake_format, - builtins.formatting.isort, - builtins.formatting.htmlbeautifier, - -- null_ls.builtins.formatting.prettier, - builtins.formatting.prettierd, - builtins.formatting.prettier.with({ - filetypes = { - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "json", - "yaml", - "markdown", - "html", - "css", - "scss", - "less", - "graphql", - "vue", - "svelte", - }, - extra_args = { "--single-quote", "--tab-width 4", "--print-width 200" }, - }), - builtins.formatting.rustfmt, - builtins.formatting.stylua, - --builtins.formatting.dart_format, - builtins.formatting.dart_format.with({ - filetypes = { "dart" }, - }), - builtins.formatting.trim_whitespace, - builtins.formatting.yapf, - -- null_ls.builtins.formatting.black - - -- Code Actions - builtins.code_actions.shellcheck, -- shell script code actions - --builtins.code_actions.eslint_d.with(eslint_opts), - -- null_ls.builtins.code_actions.refactoring.with { filetypes = { 'javascript', 'typescript', 'lua', 'python', 'c', 'cpp' } }, - builtins.code_actions.gitsigns, - builtins.code_actions.gitrebase, - - -- Hover - builtins.hover.dictionary, - builtins.hover.printenv, -} ---}) --- Linters/Formatters ensure installed ---for _, pkg_name in ipairs({ --- "dart-debug-Adaptor", --- "stylua", --- "prettier", --- "prettierd", ---}) do - --- Import the builtins table from the null-ls module and store it in the null_ls_sources variable -null_ls.setup({ - sources = sources, - update_in_insert = true, - on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format() - end, - }) + }) + + -- Install all the null-ls sources using Mason + local registry = require('mason-registry') + for _, source_name in ipairs(sources) do + local ok, pkg = pcall(registry.get_package, source_name) + if ok then + if not pkg:is_installed() then + pkg:install() + end + end + end + -- Loop through the null_ls_sources table and install the packages + -- Install all sources for null-ls + -- local null_ls_sources = require("null-ls").builtins + + -- for _, source_name in ipairs(null_ls_sources) do + -- local ok, pkg = pcall(mason.get_package, source_name) + -- if ok then + -- if not pkg:is_installed() then + -- pkg:install() + -- end + -- end + -- end + vim.api.nvim_create_user_command('NullLsToggle', function() + -- you can also create commands to disable or enable sources + require('null-ls').toggle({}) + end, {}) + + local null_ls_stop = function() + local null_ls_client + local clients = require('user.mods').get_lsp_clients(bufnr) + + for _, client in ipairs(clients) do + if client.name == 'null-ls' then + null_ls_client = client + end end - end, -}) - --- Install all the null-ls sources using Mason -local registry = require("mason-registry") -for _, source_name in ipairs(sources) do - local ok, pkg = pcall(registry.get_package, source_name) - if ok then - if not pkg:is_installed() then - pkg:install() + if not null_ls_client then + return end + + null_ls_client.stop() end + + vim.api.nvim_create_user_command('NullLsStop', null_ls_stop, {}) + + vim.g.lsp_setup_done = true end --- Loop through the null_ls_sources table and install the packages --- Install all sources for null-ls ---local null_ls_sources = require("null-ls").builtins - ---for _, source_name in ipairs(null_ls_sources) do --- local ok, pkg = pcall(mason.get_package, source_name) --- if ok then --- if not pkg:is_installed() then --- pkg:install() --- end --- end ---end -vim.api.nvim_create_user_command("NullLsToggle", function() - -- you can also create commands to disable or enable sources - require("null-ls").toggle({}) -end, {}) diff --git a/.config/nvim/lua/plugins/nvim-tree.lua b/.config/nvim/lua/plugins/nvim-tree.lua index e2298b5..cab6f1b 100644 --- a/.config/nvim/lua/plugins/nvim-tree.lua +++ b/.config/nvim/lua/plugins/nvim-tree.lua @@ -1,106 +1,367 @@ -local status_ok, nvim_tree = pcall(require, "nvim-tree") -if not status_ok then - return -end +----------------------------------------------------------- +-- Neovim File Tree Configuration +----------------------------------------------------------- -local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") -if not config_status_ok then - return -end +--- To see mappings `g?` on nvim-tree +--- To see default mappings `:nvim-tree-default-mappings` -local tree_cb = nvim_tree_config.nvim_tree_callback +local icons = { + webdev_colors = true, + git_placement = 'signcolumn', + modified_placement = 'after', + padding = ' ', + show = { + file = true, + folder = true, + folder_arrow = true, + git = true, + modified = true, + }, --- To see mappings `g?` on nvim-tree --- To see default mappings `:nvim-tree-default-mappings` + glyphs = { + default = '', + symlink = '', + folder = { + arrow_open = '', + arrow_closed = '', + default = ' ', + open = ' ', + empty = ' ', + empty_open = ' ', + symlink = '', + symlink_open = '', + }, -nvim_tree.setup({ - update_focused_file = { - enable = true, - update_cwd = true, + git = { + deleted = '', + unmerged = '', + untracked = '', + unstaged = '', + staged = '', + renamed = '➜', + ignored = '◌', + }, }, - git = { - enable = true, - ignore = false, - timeout = 500, -}, - renderer = { - root_folder_modifier = ":t", - indent_markers = { + web_devicons = { + folder = { enable = true, + color = true, }, + }, +} + +local renderer = { + group_empty = true, -- default: true. Compact folders that only contain a single folder into one node in the file tree. + highlight_git = false, + full_name = false, + highlight_opened_files = 'icon', -- "none" (default), "icon", "name" or "all" + highlight_modified = 'icon', -- "none", "name" or "all". Nice and subtle, override the open icon + root_folder_label = ':~:s?$?/..?', + indent_width = 2, + indent_markers = { + enable = true, + inline_arrows = true, icons = { - glyphs = { - default = "", - symlink = "", - folder = { - arrow_open = "", - arrow_closed = "", - default = "", - open = "", - empty = "", - empty_open = "", - symlink = "", - symlink_open = "", - }, - git = { - unstaged = "", - staged = "S", - unmerged = "", - renamed = "➜", - untracked = "U", - deleted = "", - ignored = "◌", - }, - }, + corner = '└', + edge = '│', + item = '│', + bottom = '─', + none = ' ', }, }, + icons = icons, +} + +local system_open = { cmd = 'zathura' } + +local HEIGHT_RATIO = 0.8 +local WIDTH_RATIO = 0.15 + +local float = { + enable = false, + open_win_config = function() + local screen_w = vim.opt.columns:get() + local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() + local window_w = screen_w * WIDTH_RATIO + local window_h = screen_h * HEIGHT_RATIO + local window_w_int = math.floor(window_w) + local window_h_int = math.floor(window_h) + local center_x = (screen_w - window_w) / 2 + local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get() + return { + border = 'rounded', + relative = 'editor', + row = center_y, + col = center_x, + width = window_w_int, + height = window_h_int, + } + end, +} + +local view = { + cursorline = true, + hide_root_folder = false, + float = float, + --signcolumn = 'no', + width = function() + return math.floor(vim.opt.columns:get() * WIDTH_RATIO) + end, + side = 'left', +} + +local api = require('nvim-tree.api') +local function on_attach(bufnr) + local function opts(desc) + return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + local mappings = { + ['<C-]>'] = { api.tree.change_root_to_node, 'CD' }, + ['<C-e>'] = { api.node.open.replace_tree_buffer, 'Open: In Place' }, + ['<C-k>'] = { api.node.show_info_popup, 'Info' }, + ['<C-r>'] = { api.fs.rename_sub, 'Rename: Omit Filename' }, + ['<C-t>'] = { api.node.open.tab, 'Open: New Tab' }, + ['<C-v>'] = { api.node.open.vertical, 'Open: Vertical Split' }, + ['<C-x>'] = { api.node.open.horizontal, 'Open: Horizontal Split' }, + ['<BS>'] = { api.node.navigate.parent_close, 'Close Directory' }, + -- ["<CR>"] = { api.node.open.edit, "Open" }, + ['<Tab>'] = { api.node.open.preview, 'Open Preview' }, + ['>'] = { api.node.navigate.sibling.next, 'Next Sibling' }, + ['<'] = { api.node.navigate.sibling.prev, 'Previous Sibling' }, + ['.'] = { api.node.run.cmd, 'Run Command' }, + ['-'] = { api.tree.change_root_to_parent, 'Up' }, + ['a'] = { api.fs.create, 'Create' }, + ['bmv'] = { api.marks.bulk.move, 'Move Bookmarked' }, + ['B'] = { api.tree.toggle_no_buffer_filter, 'Toggle No Buffer' }, + ['c'] = { api.fs.copy.node, 'Copy' }, + -- ["C"] = { api.tree.toggle_git_clean_filter, "Toggle Git Clean" }, + ['[c'] = { api.node.navigate.git.prev, 'Prev Git' }, + [']c'] = { api.node.navigate.git.next, 'Next Git' }, + ['d'] = { api.fs.remove, 'Delete' }, + ['D'] = { api.fs.trash, 'Trash' }, + ['E'] = { api.tree.expand_all, 'Expand All' }, + ['e'] = { api.fs.rename_basename, 'Rename: Basename' }, + [']e'] = { api.node.navigate.diagnostics.next, 'Next Diagnostic' }, + ['[e'] = { api.node.navigate.diagnostics.prev, 'Prev Diagnostic' }, + ['F'] = { api.live_filter.clear, 'Clean Filter' }, + ['f'] = { api.live_filter.start, 'Filter' }, + ['g?'] = { api.tree.toggle_help, 'Help' }, + ['gy'] = { api.fs.copy.absolute_path, 'Copy Absolute Path' }, + ['H'] = { api.tree.toggle_hidden_filter, 'Toggle Dotfiles' }, + ['I'] = { api.tree.toggle_gitignore_filter, 'Toggle Git Ignore' }, + ['J'] = { api.node.navigate.sibling.last, 'Last Sibling' }, + ['K'] = { api.node.navigate.sibling.first, 'First Sibling' }, + ['m'] = { api.marks.toggle, 'Toggle Bookmark' }, + -- ["o"] = { api.node.open.edit, "Open" }, + ['O'] = { api.node.open.no_window_picker, 'Open: No Window Picker' }, + ['p'] = { api.fs.paste, 'Paste' }, + ['P'] = { api.node.navigate.parent, 'Parent Directory' }, + ['q'] = { api.tree.close, 'Close' }, + ['r'] = { api.fs.rename, 'Rename' }, + ['R'] = { api.tree.reload, 'Refresh' }, + ['s'] = { api.node.run.system, 'Run System' }, + ['S'] = { api.tree.search_node, 'Search' }, + ['U'] = { api.tree.toggle_custom_filter, 'Toggle Hidden' }, + ['W'] = { api.tree.collapse_all, 'Collapse' }, + ['x'] = { api.fs.cut, 'Cut' }, + ['y'] = { api.fs.copy.filename, 'Copy Name' }, + ['Y'] = { api.fs.copy.relative_path, 'Copy Relative Path' }, + ['<2-LeftMouse>'] = { api.node.open.edit, 'Open' }, + ['<2-RightMouse>'] = { api.tree.change_root_to_node, 'CD' }, + + -- Mappings migrated from view.mappings.list + ['l'] = { api.node.open.edit, 'Open' }, + ['<CR>'] = { api.node.open.edit, 'Open' }, + ['o'] = { api.node.open.edit, 'Open' }, + ['h'] = { api.node.navigate.parent_close, 'Close Directory' }, + ['v'] = { api.node.open.vertical, 'Open: Vertical Split' }, + ['C'] = { api.tree.change_root_to_node, 'CD' }, + } + for keys, mapping in pairs(mappings) do + vim.keymap.set('n', keys, mapping[1], opts(mapping[2])) + end +end +--api.events.subscribe(api.events.Event.FileCreated, function(file) +-- vim.cmd('edit' .. file.fname) +--end) + +require('nvim-tree').setup({ + --auto_reload_on_write = true, + --create_in_closed_folder = false, + --hijack_cursor = true, + --disable_netrw = true, + --hijack_netrw = true, + --hijack_unnamed_buffer_when_opening = false, + --ignore_buffer_on_setup = false, + update_focused_file = { + enable = true, + update_cwd = true, + update_root = true, + ignore_list = {}, + }, + root_dirs = {}, + --prefer_startup_root = true, + --hijack_directories = { + -- enable = false, + --}, + --respect_buf_cwd = false, + sync_root_with_cwd = true, + --reload_on_bufenter = false, + view = view, + system_open = system_open, + renderer = renderer, + on_attach = on_attach, + notify = { + threshold = vim.log.levels.ERROR, + }, + git = { ignore = false }, diagnostics = { enable = true, show_on_dirs = true, icons = { - hint = "", - info = "", - warning = "", - error = "", + hint = '⚑', + info = '', + warning = '▲', + error = '', }, }, - view = { - width = 30, - --height = 30, - side = "left", - --mappings = { - -- list = { - -- { key = { "l", "<CR>", "o" }, cb = tree_cb("edit") }, - -- { key = "h", cb = tree_cb("close_node") }, - -- { key = "v", cb = tree_cb("vsplit") }, - -- { key = "u", action = "dir_up" }, - -- }, - --}, - }, trash = { - cmd = "gio trash", + cmd = 'gio trash', require_confirm = true, }, + modified = { + enable = true, + show_on_dirs = true, + show_on_open_dirs = true, + }, + --filters = { + -- dotfiles = false, + -- git_clean = false, + -- no_buffer = false, + -- custom = {}, + -- exclude = {}, + --}, + actions = { + use_system_clipboard = true, + change_dir = { + enable = true, + global = false, + restrict_above_cwd = false, + }, + remove_file = { + close_window = true, + }, + open_file = { + quit_on_open = true, + --eject = true, + resize_window = false, + window_picker = { + enable = true, + chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', + exclude = { + filetype = { 'notify', 'packer', 'qf', 'diff', 'fugitive', 'fugitiveblame' }, + buftype = { 'nofile', 'terminal', 'help' }, + }, + }, + }, + }, }) -vim.api.nvim_create_autocmd("QuitPre", { - callback = function() - local invalid_win = {} - local wins = vim.api.nvim_list_wins() - for _, w in ipairs(wins) do - local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(w)) - if bufname:match("NvimTree_") ~= nil then - table.insert(invalid_win, w) - end - end - if #invalid_win == #wins - 1 then - -- Should quit, so we close all invalid windows. - for _, w in ipairs(invalid_win) do vim.api.nvim_win_close(w, true) end - end +local api = require('nvim-tree.api') +local event = api.events.Event +--api.events.subscribe(event.TreeOpen, function(_) +-- vim.cmd([[setlocal statuscolumn=\ ]]) +-- vim.cmd([[setlocal cursorlineopt=number]]) +-- vim.cmd([[setlocal fillchars+=vert:🮇]]) +-- vim.cmd([[setlocal fillchars+=horizup:🮇]]) +-- vim.cmd([[setlocal fillchars+=vertright:🮇]]) +--end) + +local function open_nvim_tree(data) + vim.cmd.cd(data.file:match('(.+)/[^/]*$')) + local directory = vim.fn.isdirectory(data.file) == 1 + if not directory then + return end + require('nvim-tree.api').tree.open() +end +vim.api.nvim_create_autocmd({ 'VimEnter' }, { callback = open_nvim_tree }) + +-- Change Root To Global Current Working Directory +local function change_root_to_global_cwd() + local api = require('nvim-tree.api') + local global_cwd = vim.fn.getcwd(-1, -1) + api.tree.change_root(global_cwd) +end + +local function copy_file_to(node) + local file_src = node['absolute_path'] + -- The args of input are {prompt}, {default}, {completion} + -- Read in the new file path using the existing file's path as the baseline. + local file_out = vim.fn.input('COPY TO: ', file_src, 'file') + -- Create any parent dirs as required + local dir = vim.fn.fnamemodify(file_out, ':h') + vim.fn.system({ 'mkdir', '-p', dir }) + -- Copy the file + vim.fn.system({ 'cp', '-R', file_src, file_out }) +end + +local function edit_and_close(node) + api.node.open.edit(node, {}) + api.tree.close() +end + +--vim.api.nvim_create_augroup('NvimTreeRefresh', {}) +--vim.api.nvim_create_autocmd('BufEnter', { +-- pattern = 'NvimTree_1', +-- command = 'NvimTreeRefresh', +-- group = 'NvimTreeRefresh', +--}) + +vim.api.nvim_create_autocmd({ 'CursorHold' }, { + pattern = 'NvimTree*', + callback = function() + local def = vim.api.nvim_get_hl_by_name('Cursor', true) + vim.api.nvim_set_hl( + 0, + 'Cursor', + vim.tbl_extend('force', def, { + blend = 100, + }) + ) + vim.opt.guicursor:append('a:Cursor/lCursor') + end, +}) + +vim.api.nvim_create_autocmd({ 'BufLeave', 'WinClosed', 'WinLeave' }, { + pattern = 'NvimTree*', + callback = function() + local def = vim.api.nvim_get_hl_by_name('Cursor', true) + vim.api.nvim_set_hl( + 0, + 'Cursor', + vim.tbl_extend('force', def, { + blend = 0, + }) + ) + vim.opt.guicursor = 'n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20' + end, }) + -- Highlight Groups -vim.api.nvim_command("highlight NvimTreeNormal guibg=none") +vim.api.nvim_command('highlight NvimTreeNormal guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight NvimTreeNormalNC guibg=NONE ctermbg=NONE guifg=NONE') +vim.api.nvim_command('highlight NvimTreeNormalFloat guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight NvimTreeEndOfBuffer guibg=NONE ctermbg=NONE') --(NonText) +vim.api.nvim_command('highlight NvimTreeCursorLine guibg=#50fa7b guifg=#000000') +vim.api.nvim_command('highlight NvimTreeSymlinkFolderName guifg=#f8f8f2 guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight NvimTreeFolderName guifg=#f8f8f2 guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight NvimTreeRootFolder guifg=#f8f8f2 guibg=NONE ctermbg=NONE') +vim.api.nvim_command('highlight NvimTreeEmptyFolderName guifg=#f8f8f2 guibg=NONE ctermbg=NONE') --(Directory) +vim.api.nvim_command('highlight NvimTreeOpenedFolderName guifg=#f8f8f2 guibg=NONE ctermbg=NONE') --(Directory) +vim.api.nvim_command('highlight NvimTreeOpenedFile guifg=#50fa7b guibg=NONE ctermbg=NONE') + --vim.api.nvim_command("highlight NvimTreeSymlink ") --vim.api.nvim_command("highlight NvimTreeSymlinkFolderName ") --(Directory) --vim.api.nvim_command("highlight NvimTreeFolderName ") --(Directory) @@ -128,16 +389,9 @@ vim.api.nvim_command("highlight NvimTreeNormal guibg=none") --vim.api.nvim_command("highlight NvimTreeGitNew ") --vim.api.nvim_command("highlight NvimTreeGitDeleted ") --vim.api.nvim_command("highlight NvimTreeGitIgnored ") --(Comment) ---vim.api.nvim_command("highlight NvimTreeWindowPicker ") --vim.api.nvim_command("highlight NvimTreeNormal ") --vim.api.nvim_command("highlight NvimTreeEndOfBuffer ") --(NonText) ---vim.api.nvim_command("highlight NvimTreeCursorLine ") --(CursorLine) ---vim.api.nvim_command("highlight NvimTreeCursorLineNr ") --(CursorLineNr) ---vim.api.nvim_command("highlight NvimTreeLineNr ") --(LineNr) ---vim.api.nvim_command("highlight NvimTreeWinSeparator ") --(WinSeparator) --vim.api.nvim_command("highlight NvimTreeCursorColumn ") --(CursorColumn) - - --vim.api.nvim_command("highlight NvimTreeFileDirty ") --(NvimTreeGitDirty) --vim.api.nvim_command("highlight NvimTreeFileStaged ") --(NvimTreeGitStaged) --vim.api.nvim_command("highlight NvimTreeFileMerge ") --(NvimTreeGitMerge) @@ -145,10 +399,6 @@ vim.api.nvim_command("highlight NvimTreeNormal guibg=none") --vim.api.nvim_command("highlight NvimTreeFileNew ") --(NvimTreeGitNew) --vim.api.nvim_command("highlight NvimTreeFileDeleted ") --(NvimTreeGitDeleted) --vim.api.nvim_command("highlight NvimTreeFileIgnored ") --(NvimTreeGitIgnored) - - --vim.api.nvim_command("highlight NvimTreeLiveFilterPrefix ") --vim.api.nvim_command("highlight NvimTreeLiveFilterValue ") - - --vim.api.nvim_command("highlight NvimTreeBookmark ") diff --git a/.config/nvim/lua/plugins/quickfix.lua b/.config/nvim/lua/plugins/quickfix.lua index 4ea2374..4a76da0 100644 --- a/.config/nvim/lua/plugins/quickfix.lua +++ b/.config/nvim/lua/plugins/quickfix.lua @@ -1,18 +1,15 @@ local M = {} M.close = function() - vim.cmd.cclose() + vim.cmd.cclose() end M.open = function() - if vim.tbl_count(vim.fn.getqflist()) == 0 then - vim.notify( - "Nothing in quickfix list; not opening.", - vim.log.levels.WARN - ) - else - vim.cmd.copen() - end + if vim.tbl_count(vim.fn.getqflist()) == 0 then + vim.notify('Nothing in quickfix list; not opening.', vim.log.levels.WARN) + else + vim.cmd.copen() + end end return M diff --git a/.config/nvim/lua/plugins/session.lua b/.config/nvim/lua/plugins/session.lua new file mode 100644 index 0000000..0c84625 --- /dev/null +++ b/.config/nvim/lua/plugins/session.lua @@ -0,0 +1,5 @@ +require('auto-session').setup({ + log_level = 'error', + auto_session_suppress_dirs = { '~/', '~/projects', '~/downloads', '/' }, +}) +require('session-lens').setup({}) diff --git a/.config/nvim/lua/plugins/sniprun.lua b/.config/nvim/lua/plugins/sniprun.lua new file mode 100644 index 0000000..2556c24 --- /dev/null +++ b/.config/nvim/lua/plugins/sniprun.lua @@ -0,0 +1,57 @@ +local status_ok, sniprun = pcall(require, 'sniprun') +if not status_ok then + return +end + +sniprun.setup({ + -- selected_interpreters = {}, --# use those instead of the default for the current filetype + -- repl_enable = { "Python3_original" }, --# enable REPL-like behavior for the given interpreters + -- repl_disable = {}, --# disable REPL-like behavior for the given interpreters + + -- interpreter_options = { --# intepreter-specific options, see docs / :SnipInfo <name> + -- GFM_original = { + -- use_on_filetypes = { "markdown.pandoc" }, --# the 'use_on_filetypes' configuration key is + -- --# available for every interpreter + -- }, + -- }, + + --# you can combo different display modes as desired + display = { + -- "Classic", --# display results in the command-line area + 'VirtualTextOk', --# display ok results as virtual text (multiline is shortened) + -- "VirtualTextErr", --# display error results as virtual text + -- "TempFloatingWindow", --# display results in a floating window + -- "LongTempFloatingWindow", --# same as above, but only long results. To use with VirtualText__ + -- "Terminal", --# display results in a vertical split + -- "TerminalWithCode", --# display results and code history in a vertical split + -- "NvimNotify", --# display with the nvim-notify plugin + -- "Api" --# return output to a programming interface + }, + + display_options = { + terminal_width = 45, --# change the terminal display option width + notification_timeout = 5, --# timeout for nvim_notify output + }, + + --# You can use the same keys to customize whether a sniprun producing + --# no output should display nothing or '(no output)' + show_no_output = { + 'Classic', + 'TempFloatingWindow', --# implies LongTempFloatingWindow, which has no effect on its own + }, + + --# customize highlight groups (setting this overrides colorscheme) + -- snipruncolors = { + -- SniprunVirtualTextOk = { bg = "NONE", fg = "#66eeff", ctermbg = "Black", cterfg = "Cyan" }, + -- SniprunFloatingWinOk = { fg = "NONE", ctermfg = "Cyan" }, + -- SniprunVirtualTextErr = { bg = "#881515", fg = "#000000", ctermbg = "DarkRed", cterfg = "Black" }, + -- SniprunFloatingWinErr = { fg = "#881515", ctermfg = "DarkRed" }, + -- }, + + --# miscellaneous compatibility/adjustement settings + inline_messages = 0, --# inline_message (0/1) is a one-line way to display messages + --# to workaround sniprun not being able to display anything + + borders = 'single', --# display borders around floating windows + --# possible values are 'none', 'single', 'double', or 'shadow' +}) diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index 079f88b..0167aa3 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -1,91 +1,93 @@ local M = {} -- Shorten function names -local actions = require("telescope.actions") -local fb_actions = require("telescope").extensions.file_browser.actions +local actions = require('telescope.actions') +local fb_actions = require('telescope').extensions.file_browser.actions --local builtin = require("telescope.builtin") ---local themes = require("telescope.themes") --local utils = require("telescope.utils") ---local action_state = require("telescope.actions.state") --local layout_actions = require("telescope.actions.layout") ---local pickers = require("telescope.pickers") -local themes = require("telescope.themes") - +--local themes = require('telescope.themes') +local actions_set = require('telescope.actions.set') +local actions_state = require('telescope.actions.state') +local finders = require('telescope.finders') +local pickers = require('telescope.pickers') +local config = require('telescope.config').values require('telescope').setup({ defaults = { vimgrep_arguments = { - "rg", - "--color=never", - "--no-heading", - "--with-filename", - "--line-number", - "--column", - "--smart-case", - "--hidden", - "--fixed-strings", - "--trim", + 'rg', + '--color=never', + '--no-heading', + '--with-filename', + '--line-number', + '--column', + '--smart-case', + '--hidden', + '--fixed-strings', + '--trim', }, - prompt_prefix = " ", - selection_caret = " ", - entry_prefix = " ", - path_display = { "tail" }, + prompt_prefix = ' ', + selection_caret = ' ', + entry_prefix = ' ', + path_display = { 'tail' }, --path_display = { "truncate" }, --path_display = { "smart" }, file_ignore_patterns = { - "packer_compiled.lua", - "zcompdump", - "%.DS_Store", - "%.git/", - "%.spl", + 'packer_compiled.lua', + '~/.config/zsh/plugins', + 'zcompdump', + '%.DS_Store', + '%.git/', + '%.spl', --"%.log", - "%[No Name%]", -- new files / sometimes folders (netrw) - "/$", -- ignore folders (netrw) - "node_modules", - "%.png", - "%.zip", - "%.pxd", - "^.vim/", - "^.local/", - "^.cache/", - "^downloads/", - "^music/", + '%[No Name%]', -- new files / sometimes folders (netrw) + '/$', -- ignore folders (netrw) + 'node_modules', + '%.png', + '%.zip', + '%.pxd', + --"^.vim/", + '^.local/', + '^.cache/', + '^downloads/', + '^music/', --"^node_modules/", --"^undodir/", }, mappings = { i = { - ["<C-n>"] = actions.cycle_history_next, - ["<C-p>"] = actions.cycle_history_prev, + ['<C-n>'] = actions.cycle_history_next, + ['<C-p>'] = actions.cycle_history_prev, - ["<C-j>"] = actions.move_selection_next, - ["<C-k>"] = actions.move_selection_previous, + ['<C-j>'] = actions.move_selection_next, + ['<C-k>'] = actions.move_selection_previous, --["<C-c>"] = actions.close, - ["<Esc>"] = actions.close, -- close w/ one esc + ['<Esc>'] = actions.close, -- close w/ one esc --["<Esc>"] = "close", -- close w/ one esc - ["<?>"] = actions.which_key, -- keys from pressing <C-/> + ['<?>'] = actions.which_key, -- keys from pressing <C-/> - ["<Down>"] = actions.move_selection_next, - ["<Up>"] = actions.move_selection_previous, + ['<Down>'] = actions.move_selection_next, + ['<Up>'] = actions.move_selection_previous, - ["<CR>"] = actions.select_default, - ["<C-x>"] = actions.select_horizontal, - ["<C-y>"] = actions.select_vertical, - ["<C-t>"] = actions.select_tab, + ['<CR>'] = actions.select_default, + ['<C-x>'] = actions.select_horizontal, + ['<C-y>'] = actions.select_vertical, + ['<C-t>'] = actions.select_tab, - ["<C-u>"] = actions.preview_scrolling_up, - ["<C-d>"] = actions.preview_scrolling_down, + ['<C-u>'] = actions.preview_scrolling_up, + ['<C-d>'] = actions.preview_scrolling_down, - ["<PageUp>"] = actions.results_scrolling_up, - ["<PageDown>"] = actions.results_scrolling_down, + ['<PageUp>'] = actions.results_scrolling_up, + ['<PageDown>'] = actions.results_scrolling_down, - ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse, - ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better, - ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, - ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, - ["<C-l>"] = actions.complete_tag, - ["<C-_>"] = actions.which_key, -- keys from pressing <C-/> + ['<Tab>'] = actions.toggle_selection + actions.move_selection_worse, + ['<S-Tab>'] = actions.toggle_selection + actions.move_selection_better, + ['<C-q>'] = actions.send_to_qflist + actions.open_qflist, + ['<M-q>'] = actions.send_selected_to_qflist + actions.open_qflist, + ['<C-l>'] = actions.complete_tag, + ['<C-_>'] = actions.which_key, -- keys from pressing <C-/> --["<C-o>"] = function(prompt_bufnr) -- local selection = require("telescope.actions.state").get_selected_entry() -- local dir = vim.fn.fnamemodify(selection.path, ":p:h") @@ -102,36 +104,42 @@ require('telescope').setup({ -- -- Depending on what you want put `cd`, `lcd`, `tcd` -- vim.cmd(string.format("silent lcd %s", dir)) --end, - ["<esc>"] = actions.close, - ["<q>"] = actions.close, - ["<CR>"] = actions.select_default, - ["<C-x>"] = actions.select_horizontal, - ["<C-y>"] = actions.select_vertical, - ["<C-t>"] = actions.select_tab, - - ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse, - ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better, - ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, - ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, - - ["j"] = actions.move_selection_next, - ["k"] = actions.move_selection_previous, - ["H"] = actions.move_to_top, - ["M"] = actions.move_to_middle, - ["L"] = actions.move_to_bottom, - - ["<Down>"] = actions.move_selection_next, - ["<Up>"] = actions.move_selection_previous, - ["gg"] = actions.move_to_top, - ["G"] = actions.move_to_bottom, - - ["<C-u>"] = actions.preview_scrolling_up, - ["<C-d>"] = actions.preview_scrolling_down, - - ["<PageUp>"] = actions.results_scrolling_up, - ["<PageDown>"] = actions.results_scrolling_down, - - ["?"] = actions.which_key, + ['<esc>'] = actions.close, + ['<q>'] = actions.close, + ['<CR>'] = actions.select_default, + ['<C-x>'] = actions.select_horizontal, + ['<C-y>'] = actions.select_vertical, + ['<C-t>'] = actions.select_tab, + + ['<Tab>'] = actions.toggle_selection + actions.move_selection_worse, + ['<S-Tab>'] = actions.toggle_selection + actions.move_selection_better, + ['<C-q>'] = actions.send_to_qflist + actions.open_qflist, + ['<M-q>'] = actions.send_selected_to_qflist + actions.open_qflist, + + ['j'] = actions.move_selection_next, + ['k'] = actions.move_selection_previous, + ['H'] = actions.move_to_top, + ['M'] = actions.move_to_middle, + ['L'] = actions.move_to_bottom, + + ['<Down>'] = actions.move_selection_next, + ['<Up>'] = actions.move_selection_previous, + ['gg'] = actions.move_to_top, + ['G'] = actions.move_to_bottom, + + ['<C-u>'] = actions.preview_scrolling_up, + ['<C-d>'] = actions.preview_scrolling_down, + + ['<PageUp>'] = actions.results_scrolling_up, + ['<PageDown>'] = actions.results_scrolling_down, + ['cd'] = function(prompt_bufnr) + local selection = require('telescope.actions.state').get_selected_entry() + local dir = vim.fn.fnamemodify(selection.path, ':p:h') + require('telescope.actions').close(prompt_bufnr) + -- Depending on what you want put `cd`, `lcd`, `tcd` + vim.cmd(string.format('silent lcd %s', dir)) + end, + ['?'] = actions.which_key, --["<C-o>"] = function(prompt_bufnr) -- local selection = require("telescope.actions.state").get_selected_entry() -- local dir = vim.fn.fnamemodify(selection.path, ":p:h") @@ -146,9 +154,9 @@ require('telescope').setup({ filesize_limit = 3, timeout = 250, }, - selection_strategy = "reset", - sorting_strategy = "ascending", - scroll_strategy = "limit", + selection_strategy = 'reset', + sorting_strategy = 'ascending', + scroll_strategy = 'limit', color_devicons = true, layout_strategy = 'horizontal', layout_config = { @@ -156,14 +164,22 @@ require('telescope').setup({ height = 0.95, preview_cutoff = 70, width = 0.92, - preview_width = { 0.55, max = 50 } + preview_width = { 0.55, max = 50 }, }, bottom_pane = { height = 12, preview_cutoff = 70, - prompt_position = "bottom", + prompt_position = 'bottom', }, }, + find_files = { + --cwd = '%:p:h', + cwd = vim.fn.getcwd(), + prompt_prefix = ' ', + --hidden = true, + --no_ignore = false, + follow = true, + }, --pickers = { -- live_grep = { -- disable_coordinates = true, @@ -208,13 +224,6 @@ require('telescope').setup({ -- prompt_prefix=' ', -- show_line = false, --}, - find_files = { - cwd = '%:p:h', - --cwd = vim.fn.getcwd(), - prompt_prefix = ' ', - hidden = true, - follow = true, - }, --keymaps = { prompt_prefix='? ' }, --oldfiles = { prompt_prefix=' ' }, --highlights = { prompt_prefix=' ' }, @@ -251,21 +260,21 @@ require('telescope').setup({ extensions = { file_browser = { - theme = "dropdown", + theme = 'dropdown', -- disables netrw and use telescope-file-browser in its place - hijack_netrw = true, + hijack_netrw = false, mappings = { -- your custom insert mode mappings - ["i"] = { - ["<C-w>"] = function() - vim.cmd("normal vbd") + ['i'] = { + ['<C-w>'] = function() + vim.cmd('normal vbd') end, - --["<C-h>"] = fb_actions.goto_parent_dir, + ['<C-h>'] = fb_actions.goto_parent_dir, }, - ["n"] = { + ['n'] = { -- your custom normal mode mappings - ["N"] = fb_actions.create, - --["<C-h>"] = fb_actions.goto_parent_dir, + ['N'] = fb_actions.create, + ['<C-h>'] = fb_actions.goto_parent_dir, --["/"] = function() -- vim.cmd("startinsert") --end, @@ -281,14 +290,15 @@ require('telescope').setup({ -- have to be loaded after telescope setup/config require('telescope').load_extension('fzf') require('telescope').load_extension('ui-select') -require("telescope").load_extension("file_browser") +require('telescope').load_extension('file_browser') require('telescope').load_extension('changed_files') require('telescope').load_extension('media_files') ---require('telescope').extensions.notify.notify() require('telescope').load_extension('notify') require('telescope').load_extension('dap') -require("telescope").load_extension("session-lens") -require("telescope").load_extension("flutter") +require('telescope').load_extension('session-lens') +require('telescope').load_extension('flutter') +require('telescope').load_extension('recent_files') +--require('telescope').load_extension('projects') --M.curbuf = function(opts) -- opts = opts @@ -301,119 +311,174 @@ require("telescope").load_extension("flutter") --end function M.find_configs() - require("telescope.builtin").find_files { + require('telescope.builtin').find_files({ hidden = true, no_ignore = false, - prompt_title = " Find Configs", - results_title = "Config Files", - path_display = { "smart" }, + prompt_title = ' Find Configs', + results_title = 'Config Files', + path_display = { 'smart' }, search_dirs = { - "~/.config/nvim", - "~/.config/zsh", - "~/.config/tmux", - "~/.config/X11", - "~/.config/alacritty", - "~/.config/kitty", - "~/.config/wezterm", - "~/.config/bspwm", - "~/.config/sxhkd", - "~/.config/picom", - "~/.config/polybar", - "~/.bashrc", - "~/.ssh", - "~/.vim", - "~/.profile", - "~/.zprofile", - "~/README.md", + '~/.vim', + '~/.config/nvim', + '~/.config/zsh', + '~/.config/tmux', + '~/.config/X11', + '~/.config/alacritty', + '~/.config/kitty', + '~/.config/wezterm', + '~/.config/bspwm', + '~/.config/sxhkd', + '~/.config/picom', + '~/.config/polybar', + '~/.bashrc', + '~/.profile', + '~/.zprofile', + '~/.gitconfig', + '~/.gitsubtrees', + '~/.gitignore', + '~/.editorconfig', + '~/.prettierrc.yml', + '~/.ssh', + '~/README.md', }, - -- cwd = "~/.config/nvim/", file_ignore_patterns = { - "~/.config/nvim/startup.log", - "packer_compiled.lua", - "resurrect", - "tmux/plugins", + '/nvim/startup.log', + 'zsh/plugins', + 'packer_compiled.lua', + 'resurrect', + 'tmux/plugins', --"^~/.config/tmux/plugins", - "%.txt", - ".git", - "autoload/plugged", - "plug.vim", - "zcompdump", + '%.txt', + '.git/', + 'autoload/plugged', + 'plug.vim', + 'zcompdump', }, - layout_strategy = "horizontal", + layout_strategy = 'horizontal', layout_config = { preview_width = 0.65, width = 0.75 }, - } + }) end function M.find_scripts() - require("telescope.builtin").find_files { + require('telescope.builtin').find_files({ hidden = true, no_ignore = true, - prompt_title = " Find Scripts", - path_display = { "smart" }, + prompt_title = ' Find Scripts', + path_display = { 'smart' }, search_dirs = { - "~/.local/bin/scripts", + '~/.local/bin/scripts', }, - layout_strategy = "horizontal", + layout_strategy = 'horizontal', layout_config = { preview_width = 0.65, width = 0.75 }, - } + }) end +--function M.find_projects() -- aka Workspaces +-- require('telescope.builtin').find_files({ +-- hidden = true, +-- no_ignore = true, +-- prompt_title = ' Find Projects', +-- path_display = { 'smart' }, +-- search_dirs = { +-- '~/projects', +-- }, +-- layout_strategy = 'horizontal', +-- layout_config = { preview_width = 0.65, width = 0.75 }, +-- }) +--end + function M.find_projects() - require("telescope.builtin").find_files { - hidden = true, - no_ignore = true, - prompt_title = " Find Projects", - path_display = { "smart" }, - search_dirs = { - "~/projects", - }, - layout_strategy = "horizontal", - layout_config = { preview_width = 0.65, width = 0.75 }, - } + local search_dir = '~/projects' + pickers + .new({}, { + prompt_title = 'Change Directory', + finder = finders.new_oneshot_job({ + 'find', + vim.fn.expand(search_dir), + '-type', + 'd', + '-maxdepth', + '1', + }), + previewer = require('telescope.previewers').vim_buffer_cat.new({}), + sorter = config.generic_sorter({}), + attach_mappings = function(prompt_bufnr, map) + actions_set.select:replace(function() + local entry = actions_state.get_selected_entry() + if entry ~= nil then + local dir = entry.value + actions.close(prompt_bufnr, false) + vim.fn.chdir(dir) + vim.cmd('e .') + vim.cmd("echon ''") + print('cwd: ' .. vim.fn.getcwd()) + end + end) + return true + end, + }) + :find() end function M.grep_notes() local opts = {} opts.hidden = false opts.search_dirs = { - "~/documents/notes/", + '~/documents/notes/', } - opts.prompt_prefix = " " - opts.prompt_title = " Grep Notes" - opts.path_display = { "smart" } - require("telescope.builtin").live_grep(opts) + opts.prompt_prefix = ' ' + opts.prompt_title = ' Grep Notes' + opts.path_display = { 'smart' } + require('telescope.builtin').live_grep(opts) end function M.find_notes() - require("telescope.builtin").find_files { - hidden = false, - prompt_title = " Find Notes", - path_display = { "smart" }, + require('telescope.builtin').find_files({ + hidden = true, + no_ignore = false, + prompt_title = ' Find Notes', + path_display = { 'smart' }, search_dirs = { - "~/documents/notes/private/", - "~/documents/notes", + '~/documents/notes/private/', + '~/documents/notes', + '~/notes/private', + '~/notes', }, - --cwd = "~documents/notes", - layout_strategy = "horizontal", + layout_strategy = 'horizontal', layout_config = { preview_width = 0.65, width = 0.75 }, - } + }) +end + +function M.find_books() + require('telescope.builtin').find_files({ + hidden = true, + no_ignore = false, + prompt_title = ' Find Books', + path_display = { 'smart' }, + search_dirs = { + '~/documents/books', + '~/books', + }, + layout_strategy = 'horizontal', + layout_config = { preview_width = 0.65, width = 0.75 }, + }) end function M.file_explorer() - require("telescope.builtin").file_browser({ - prompt_title = "File Browser", - cwd = "~", - layout_strategy = "horizontal", + require('telescope.builtin').file_browser({ + prompt_title = 'File Browser', + cwd = '~', + layout_strategy = 'horizontal', }) end function M.grep_current_dir() - local buffer_dir = require("telescope.utils").buffer_dir() + local buffer_dir = require('telescope.utils').buffer_dir() local opts = { - prompt_title = "Live Grep in " .. buffer_dir, + prompt_title = 'Live Grep in ' .. buffer_dir, cwd = buffer_dir, } - require("telescope.builtin").live_grep(opts) + require('telescope.builtin').live_grep(opts) end -------------------------------------------------------------------------------- @@ -427,7 +492,7 @@ local dropdown = require('telescope.themes').get_dropdown({ results_title = '', layout_config = { --anchor = "S", - prompt_position = 'top' + prompt_position = 'top', }, }) @@ -450,29 +515,22 @@ local with_title = function(opts, extra) end return vim.tbl_extend('force', opts, { - prompt_title = title + prompt_title = title, }, extra or {}) end ---vim.api.nvim_create_augroup('findhere', { clear = true }) ---vim.api.nvim_command('augroup findhere') ---vim.api.nvim_command('autocmd!') ---vim.api.nvim_command('autocmd VimEnter * lua require("plugins/telescope").findhere()') ---vim.api.nvim_command('augroup END') - - ---local findhere = function() +-- Find here function M.findhere() -- Open file browser if argument is a folder local arg = vim.api.nvim_eval('argv(0)') - if arg and (vim.fn.isdirectory(arg) ~= 0 or arg == "") then + if arg and (vim.fn.isdirectory(arg) ~= 0 or arg == '') then vim.defer_fn(function() require('telescope.builtin').find_files(with_title(dropdown)) --- require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({ --- hidden = true, --- results_title = '', --- layout_config = { prompt_position = 'top' }, --- })) + -- require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({ + -- hidden = true, + -- results_title = '', + -- layout_config = { prompt_position = 'top' }, + -- })) end, 10) end end @@ -480,10 +538,57 @@ end -- Define the custom command findhere/startup vim.cmd('command! Findhere lua require("plugins.telescope").findhere()') --vim.cmd('command! Startup lua require("plugins.telescope").findhere()') - --vim.api.nvim_command('autocmd VimEnter * lua require("plugins/telescope").findhere()') --- Merge the existing M table with the startup function table ---M = vim.tbl_extend('force', M, { findhere = findhere }) +-- Find dirs +function M.find_dirs() + local root_dir = vim.fn.input('Enter the root directory: ') + + -- Check if root_dir is empty + if root_dir == '' then + print('No directory entered. Aborting.') + return + end + + local entries = {} + + -- Use vim.fn.expand() to get an absolute path + local root_path = vim.fn.expand(root_dir) + + local subdirs = vim.fn.readdir(root_path) + if subdirs then + for _, subdir in ipairs(subdirs) do + if vim.fn.isdirectory(root_path .. '/' .. subdir) == 1 then + table.insert(entries, subdir) + end + end + end + + pickers + .new({}, { + prompt_title = 'Change Directory', + finder = finders.new_table({ + results = entries, + }), + previewer = config.file_previewer({}), + sorter = config.generic_sorter({}), + attach_mappings = function(prompt_bufnr, map) + actions_set.select:replace(function() + local entry = actions_state.get_selected_entry() + if entry ~= nil then + local selected_subdir = entry.value + actions.close(prompt_bufnr, false) + local selected_path = root_path .. '/' .. selected_subdir + vim.fn.chdir(selected_path) + vim.cmd('e .') + vim.cmd("echon ''") + print('cwd: ' .. vim.fn.getcwd()) + end + end) + return true + end, + }) + :find() +end return M diff --git a/.config/nvim/lua/plugins/trouble.lua b/.config/nvim/lua/plugins/trouble.lua index d4f50dc..7d74730 100644 --- a/.config/nvim/lua/plugins/trouble.lua +++ b/.config/nvim/lua/plugins/trouble.lua @@ -1,47 +1,47 @@ -require("trouble").setup { - position = "bottom", -- position of the list can be: bottom, top, left, right - height = 10, -- height of the trouble list when position is top or bottom - width = 50, -- width of the list when position is left or right - icons = true, -- use devicons for filenames - mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist" - fold_open = "", -- icon used for open folds - fold_closed = "", -- icon used for closed folds - group = true, -- group results by file - padding = true, -- add an extra new line on top of the list - action_keys = { -- key mappings for actions in the trouble list - -- map to {} to remove a mapping, for example: - -- close = {}, - close = "q", -- close the list - cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor - refresh = "r", -- manually refresh - jump = {"<cr>", "<tab>"}, -- jump to the diagnostic or open / close folds - open_split = { "<c-x>" }, -- open buffer in new split - open_vsplit = { "<c-v>" }, -- open buffer in new vsplit - open_tab = { "<c-t>" }, -- open buffer in new tab - jump_close = {"o"}, -- jump to the diagnostic and close the list - toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode - toggle_preview = "P", -- toggle auto_preview - hover = "K", -- opens a small popup with the full multiline message - preview = "p", -- preview the diagnostic location - close_folds = {"zM", "zm"}, -- close all folds - open_folds = {"zR", "zr"}, -- open all folds - toggle_fold = {"zA", "za"}, -- toggle fold of current file - previous = "k", -- previous item - next = "j" -- next item +require('trouble').setup({ + position = 'bottom', -- position of the list can be: bottom, top, left, right + height = 10, -- height of the trouble list when position is top or bottom + width = 50, -- width of the list when position is left or right + icons = true, -- use devicons for filenames + mode = 'document_diagnostics', -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist" + fold_open = '', -- icon used for open folds + fold_closed = '', -- icon used for closed folds + group = true, -- group results by file + padding = true, -- add an extra new line on top of the list + action_keys = { -- key mappings for actions in the trouble list + -- map to {} to remove a mapping, for example: + -- close = {}, + close = 'q', -- close the list + cancel = '<esc>', -- cancel the preview and get back to your last window / buffer / cursor + refresh = 'r', -- manually refresh + jump = { '<cr>', '<tab>' }, -- jump to the diagnostic or open / close folds + open_split = { '<c-x>' }, -- open buffer in new split + open_vsplit = { '<c-v>' }, -- open buffer in new vsplit + open_tab = { '<c-t>' }, -- open buffer in new tab + jump_close = { 'o' }, -- jump to the diagnostic and close the list + toggle_mode = 'm', -- toggle between "workspace" and "document" diagnostics mode + toggle_preview = 'P', -- toggle auto_preview + hover = 'K', -- opens a small popup with the full multiline message + preview = 'p', -- preview the diagnostic location + close_folds = { 'zM', 'zm' }, -- close all folds + open_folds = { 'zR', 'zr' }, -- open all folds + toggle_fold = { 'zA', 'za' }, -- toggle fold of current file + previous = 'k', -- previous item + next = 'j', -- next item }, - indent_lines = true, -- add an indent guide below the fold icons - auto_open = false, -- automatically open the list when you have diagnostics - auto_close = false, -- automatically close the list when you have no diagnostics - auto_preview = true, -- automatically preview the location of the diagnostic. <esc> to close preview and go back to last window - auto_fold = false, -- automatically fold a file trouble list at creation - auto_jump = {"lsp_definitions"}, -- for the given modes, automatically jump if there is only a single result + indent_lines = true, -- add an indent guide below the fold icons + auto_open = false, -- automatically open the list when you have diagnostics + auto_close = false, -- automatically close the list when you have no diagnostics + auto_preview = true, -- automatically preview the location of the diagnostic. <esc> to close preview and go back to last window + auto_fold = false, -- automatically fold a file trouble list at creation + auto_jump = { 'lsp_definitions' }, -- for the given modes, automatically jump if there is only a single result signs = { - -- icons / text used for a diagnostic - error = "", - warning = "", - hint = "", - information = "", - other = "" + -- icons / text used for a diagnostic + error = '', + warning = '▲', + information = '', + hint = '⚑', + other = '', }, - use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client -} + use_diagnostic_signs = true, -- enabling this will use the signs defined in your lsp client +}) diff --git a/.config/nvim/lua/plugins/web-devicons.lua b/.config/nvim/lua/plugins/web-devicons.lua index 2f68275..06f2d1c 100644 --- a/.config/nvim/lua/plugins/web-devicons.lua +++ b/.config/nvim/lua/plugins/web-devicons.lua @@ -1,17 +1,22 @@ ---local status, icons = pcall(require, "nvim-web-devicons") ---if (not status) then return end ---icons.setup { -require'nvim-web-devicons'.setup { +local devicons = require('nvim-web-devicons') + +-- Set devicons overrides early. +devicons.setup({ override = { + js = { icon = '', color = '#f5c06f', name = 'Js' }, + jsx = { icon = '', color = '#689fb6', name = 'Jsx' }, + ts = { icon = '', color = '#4377c1', name = 'Ts' }, + tsx = { icon = '', color = '#4377c1', name = 'Tsx' }, + png = { icon = '', color = '#d4843e', name = 'Png' }, + webp = { icon = '', color = '#3498db', name = 'Webp' }, + jpg = { icon = '', color = '#16a085', name = 'Jpg' }, + svg = { icon = '', color = '#3affdb', name = 'Svg' }, zsh = { - icon = "", - color = "#428850", - cterm_color = "65", - name = "Zsh" - }; - color_icons = true; + icon = '', + color = '#428850', + cterm_color = '65', + name = 'Zsh', + }, }, - -- globally enable default icons (default to false) - -- will get overriden by `get_icons` option - --default = true -} + color_icons = true, +}) diff --git a/.config/nvim/lua/user/keys.lua b/.config/nvim/lua/user/keys.lua index 36f7fbd..ebafd21 100644 --- a/.config/nvim/lua/user/keys.lua +++ b/.config/nvim/lua/user/keys.lua @@ -1,5 +1,3 @@ ---[[ key.lua ]] -------------- Shorten Function Names -------------- local keymap = vim.keymap local map = function(mode, l, r, opts) opts = opts or {} @@ -8,14 +6,13 @@ local map = function(mode, l, r, opts) keymap.set(mode, l, r, opts) end local term_opts = { noremap = true, silent = false } +local bufnr = vim.api.nvim_get_current_buf() ---------------- Standard Operations --------------- -- Semi-colon as leader key -vim.g.mapleader = ";" +vim.g.mapleader = ';' -- "jk" and "kj" to exit insert-mode -map("i", "jk", "<esc>") -map("i", "kj", "<esc>") +map('i', 'jk', '<esc>') -- Jump to next match on line using `.` instead of `;` NOTE: commented out in favour of "ggandor/flit.nvim" --map("n", ".", ";") @@ -24,205 +21,181 @@ map("i", "kj", "<esc>") --map("n", "<Space>", ".") -- Reload nvim config -map( - "n", - "<leader><CR>", - "<cmd>luafile ~/.config/nvim/init.lua<CR> | :echom ('Nvim config loading...') | :sl! | echo ('')<CR>" -) +map('n', '<leader><CR>', "<cmd>luafile ~/.config/nvim/init.lua<CR> | :echom ('Nvim config loading...') | :sl! | echo ('')<CR>") --------------- Extended Operations --------------- -- Conditional 'q' to quit on floating/quickfix/help windows otherwise still use it for macros -- TODO: Have a list of if available on system/packages, example "Zen Mode" to not work on it (quit Zen Mode) -map("n", "q", function() +map('n', 'q', function() local config = vim.api.nvim_win_get_config(0) - if config.relative ~= "" then -- is_floating_window? - return ":silent! close!<CR>" - elseif vim.o.buftype == "quickfix" then - return ":quit<CR>" - elseif vim.o.buftype == "help" then - return ":close<CR>" + if config.relative ~= '' then -- is_floating_window? + return ':silent! close!<CR>' + elseif vim.o.buftype == 'quickfix' then + return ':quit<CR>' + elseif vim.o.buftype == 'help' then + return ':close<CR>' else - return "q" + return 'q' end end, { expr = true, replace_keycodes = true }) -- Combine buffers list with buffer name -map("n", "<Leader>b", ":buffers<CR>:buffer<Space>") +map('n', '<Leader>b', ':buffers<CR>:buffer<Space>') -- Buffer confirmation -map("n", "<leader>y", ":BufferPick<CR>") +map('n', '<leader>y', ':BufferPick<CR>') -- Map buffer next, prev and delete to <leader>+(n/p/d) respectively -map("n", "<leader>n", ":bn<cr>") -map("n", "<leader>p", ":bp<cr>") -map("n", "<leader>d", ":bd<cr>") +map('n', '<leader>n', ':bn<cr>') +map('n', '<leader>p', ':bp<cr>') +map('n', '<leader>d', ':bd<cr>') + +-- Delete file of current buffer +map('n', '<leader>rm', "<CMD>call delete(expand('%')) | bdelete!<CR>") -- List marks -map("n", "<Leader>m", ":marks<CR>") +map('n', '<Leader>m', ':marks<CR>') -- Messages -map("n", "<Leader>M", ":messages<CR>") - --- Clear messages +map('n', '<Leader>M', ':messages<CR>') -- Clear messages or just refresh/redraw the screen -map("n", "<leader>u", ":echo '' | redraw<CR>") +map('n', '<leader>u', ":echo '' | redraw<CR>") -- Unsets the 'last search pattern' register by hitting return --map("n", "<CR>", "!silent :noh<CR><CR>") -- Toggle set number -map("n", "<leader>$", ":NumbersToggle<CR>") -map("n", "<leader>%", ":NumbersOnOff<CR>") +map('n', '<leader>$', ':NumbersToggle<CR>') +map('n', '<leader>%', ':NumbersOnOff<CR>') -- Easier split navigations, just ctrl-j instead of ctrl-w then j ---map("n", "<C-J>", "<C-W><C-J>") ---map("n", "<C-K>", "<C-W><C-K>") ---map("n", "<C-L>", "<C-W><C-L>") ---map("n", "<C-H>", "<C-W><C-H>") -map("t", "<C-[>", "<C-\\><C-N>") -map("t", "<C-h>", "<C-\\><C-N><C-h>") -map("t", "<C-j>", "<C-\\><C-N><C-j>") -map("t", "<C-k>", "<C-\\><C-N><C-k>") -map("t", "<C-l>", "<C-\\><C-N><C-l>") ---map("t", "<C-x>", "<C-c>") ---map("n", "<C-x>", "<C-c>") ---map("n", "<C-r>", ":<C-u>call MyFunc(v:count)<CR>") +map('t', '<C-[>', '<C-\\><C-N>') +map('t', '<C-h>', '<C-\\><C-N><C-h>') +map('t', '<C-j>', '<C-\\><C-N><C-j>') +map('t', '<C-k>', '<C-\\><C-N><C-k>') +map('t', '<C-l>', '<C-\\><C-N><C-l>') -- Split window -map("n", "<leader>h", ":split<CR>") -map("n", "<leader>v", ":vsplit<CR>") -map("n", "<leader>c", "<C-w>c") +map('n', '<leader>h', ':split<CR>') +map('n', '<leader>v', ':vsplit<CR>') +map('n', '<leader>c', '<C-w>c') -- Resize Panes -map("n", "<Leader>+", ":resize +5<CR>") -map("n", "<Leader>-", ":resize -5<CR>") -map("n", "<Leader><", ":vertical resize +5<CR>") -map("n", "<Leader>>", ":vertical resize -5<CR>") -map("n", "<Leader>=", "<C-w>=") - --- Map Alt+(h/j/k/l) in insert mode to move directional -map("i", "<A-h>", "<left>") -map("i", "<A-j>", "<down>") -map("i", "<A-k>", "<up>") -map("i", "<A-l>", "<right>") - --- Map Alt+(h/j/k/l) in command mode to move directional -vim.api.nvim_set_keymap("c", "<A-h>", "<Left>", { noremap = true }) -vim.api.nvim_set_keymap("c", "<A-j>", "<Down>", { noremap = true }) -vim.api.nvim_set_keymap("c", "<A-k>", "<Up>", { noremap = true }) -vim.api.nvim_set_keymap("c", "<A-l>", "<Right>", { noremap = true }) +map('n', '<Leader>+', ':resize +5<CR>') +map('n', '<Leader>-', ':resize -5<CR>') +map('n', '<Leader><', ':vertical resize +5<CR>') +map('n', '<Leader>>', ':vertical resize -5<CR>') +map('n', '<Leader>=', '<C-w>=') + +-- Map Alt+(h/j/k/l) in insert(include terminal/command) mode to move directional +map({ 'i', 't', 'c' }, '<A-h>', '<left>') +map({ 'i', 't', 'c' }, '<A-j>', '<down>') +map({ 'i', 't', 'c' }, '<A-k>', '<up>') +map({ 'i', 't', 'c' }, '<A-l>', '<right>') -- Create tab, edit and move between them -map("n", "<C-T>n", ":tabnew<CR>") -map("n", "<C-T>e", ":tabedit") -map("n", "<leader>[", ":tabprev<CR>") -map("n", "<leader>]", ":tabnext<CR>") +map('n', '<C-T>n', ':tabnew<CR>') +map('n', '<C-T>e', ':tabedit') +map('n', '<leader>[', ':tabprev<CR>') +map('n', '<leader>]', ':tabnext<CR>') -- "Zoom" a split window into a tab and/or close it --map("n", "<Leader>,", ":tabnew %<CR>") --map("n", "<Leader>.", ":tabclose<CR>") -- Vim TABs -map("n", "<leader>1", "1gt<CR>") -map("n", "<leader>2", "2gt<CR>") -map("n", "<leader>3", "3gt<CR>") -map("n", "<leader>4", "4gt<CR>") -map("n", "<leader>5", "5gt<CR>") -map("n", "<leader>6", "6gt<CR>") -map("n", "<leader>7", "7gt<CR>") -map("n", "<leader>8", "8gt<CR>") -map("n", "<leader>9", "9gt<CR>") -map("n", "<leader>0", "10gt<CR>") - --- Move to the next and previous item in the quickfixlist ---map("n", "]c", "<Cmd>cnext<CR>") ---map("n", "[c", "<Cmd>cprevious<CR>") +map('n', '<leader>1', '1gt<CR>') +map('n', '<leader>2', '2gt<CR>') +map('n', '<leader>3', '3gt<CR>') +map('n', '<leader>4', '4gt<CR>') +map('n', '<leader>5', '5gt<CR>') +map('n', '<leader>6', '6gt<CR>') +map('n', '<leader>7', '7gt<CR>') +map('n', '<leader>8', '8gt<CR>') +map('n', '<leader>9', '9gt<CR>') +map('n', '<leader>0', '10gt<CR>') -- Hitting ESC when inside a terminal to get into normal mode --map("t", "<Esc>", [[<C-\><C-N>]]) -- Move block (indentation) easily -map("n", "<", "<<", term_opts) -map("n", ">", ">>", term_opts) -map("x", "<", "<gv", term_opts) -map("x", ">", ">gv", term_opts) +map('n', '<', '<<', term_opts) +map('n', '>', '>>', term_opts) +map('x', '<', '<gv', term_opts) +map('x', '>', '>gv', term_opts) -- Set alt+(j/k) to switch lines of texts or simply move them -map("n", "<A-k>", ':let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>') -map("n", "<A-j>", ':let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>') - --- Search and replace -map("v", "<leader>sr", 'y:%s/<C-r><C-r>"//g<Left><Left>c') +map('n', '<A-k>', ':let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>') +map('n', '<A-j>', ':let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>') -- Toggle Diff -map("n", "<leader>td", "<Cmd>call utils#ToggleDiff()<CR>") +map('n', '<leader>df', '<Cmd>call utils#ToggleDiff()<CR>') -- Toggle Verbose -map("n", "<leader>vt", "<Cmd>call utils#VerboseToggle()<CR>") +map('n', '<leader>vt', '<Cmd>call utils#VerboseToggle()<CR>') -- Jump List -map("n", "<leader>j", "<Cmd>call utils#GotoJump()<CR>") +map('n', '<leader>j', '<Cmd>call utils#GotoJump()<CR>') -- Map delete to Ctrl+l -map("i", "<C-l>", "<Del>") +map('i', '<C-l>', '<Del>') -- Clear screen -map("n", "<leader><C-l>", "<Cmd>!clear<CR>") +map('n', '<leader><C-l>', '<Cmd>!clear<CR>') -- Change file to an executable -map( - "n", - "<Leader>x", - ":lua require('user.mods').Toggle_executable()<CR> | :echom ('Toggle executable')<CR> | :sl! | echo ('')<CR>" -) ---map("n", "<leader>x", ":!chmod +x %<CR>") +map('n', '<Leader>x', ":lua require('user.mods').Toggle_executable()<CR> | :echom ('Toggle executable')<CR> | :sl! | echo ('')<CR>") +-- map("n", "<leader>x", ":!chmod +x %<CR>") -- Paste without replace clipboard -map("v", "p", '"_dP') +map('v', 'p', '"_dP') -- Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in -- visual mode to select text to swap with --map("v", "<C-X>", "<Esc>`.``gvP``P") -- Change Working Directory to current project -map("n", "<leader>cd", ":cd %:p:h<CR>:pwd<CR>") +map('n', '<leader>cd', ':cd %:p:h<CR>:pwd<CR>') -- Open the current file in the default program (on Mac this should just be just `open`) -map("n", "<leader>o", ":!xdg-open %<cr><cr>") +map('n', '<leader>o', ':!xdg-open %<cr><cr>') -- URL handling -if vim.fn.has("mac") == 1 then - map("", "gx", '<Cmd>call jobstart(["open", expand("<cfile>")], {"detach": v:true})<CR>', {}) -elseif vim.fn.has("unix") == 1 then - map("", "gx", '<Cmd>call jobstart(["xdg-open", expand("<cfile>")], {"detach": v:true})<CR>', {}) -elseif vim.fn.has("wsl") == 1 then - map("", "gx", '<Cmd>call jobstart(["wslview", expand("<cfile>")], {"detach": v:true})<CR>', {}) +if vim.fn.has('mac') == 1 then + map('', 'gx', '<Cmd>call jobstart(["open", expand("<cfile>")], {"detach": v:true})<CR>', {}) +elseif vim.fn.has('unix') == 1 then + map('', 'gx', '<Cmd>call jobstart(["xdg-open", expand("<cfile>")], {"detach": v:true})<CR>', {}) +elseif vim.fn.has('wsl') == 1 then + map('', 'gx', '<Cmd>call jobstart(["wslview", expand("<cfile>")], {"detach": v:true})<CR>', {}) else - map[""].gx = { '<Cmd>lua print("Error: gx is not supported on this OS!")<CR>' } + map[''].gx = { '<Cmd>lua print("Error: gx is not supported on this OS!")<CR>' } end +-- Search and replace +map('v', '<leader>sr', 'y:%s/<C-r><C-r>"//g<Left><Left>c') + -- Substitute globally and locally in the selected region. -map("n", "ss", ":%s//g<Left><Left>") -map("v", "ss", ":s//g<Left><Left>") +map('n', '<leader>s', ':%s//g<Left><Left>') +map('v', '<leader>s', ':s//g<Left><Left>') -- Toggle completion -map("n", "<Leader>tc", ":lua require('user.mods').toggle_completion()<CR>") +map('n', '<Leader>tc', ':lua require("user.mods").toggle_completion()<CR>') -- Disable default completion. -map("i", "<C-n>", "<Nop>") -map("i", "<C-p>", "<Nop>") +map('i', '<C-n>', '<Nop>') +map('i', '<C-p>', '<Nop>') -- Set line wrap -map("n", "<M-z>", function() - local wrap_status = vim.api.nvim_exec("set wrap ?", true) +map('n', '<M-z>', function() + local wrap_status = vim.api.nvim_exec('set wrap ?', true) - if wrap_status == "nowrap" then - vim.api.nvim_command("set wrap linebreak") - print("Wrap enabled") + if wrap_status == 'nowrap' then + vim.api.nvim_command('set wrap linebreak') + print('Wrap enabled') else - vim.api.nvim_command("set wrap nowrap") - print("Wrap disabled") + vim.api.nvim_command('set wrap nowrap') + print('Wrap disabled') end end, { silent = true }) @@ -230,212 +203,205 @@ end, { silent = true }) --utils.map("n", "<F2>", "&foldlevel ? 'zM' : 'zR'", { expr = true }) -- Use space to toggle fold -map("n", "<Space>", "za") +map('n', '<Space>', 'za') -- Make a copy of current file --vim.cmd([[ --- map <leader>s :up \| saveas! %:p:r-<C-R>=strftime("%y.%m.%d-%H:%M")<CR>-bak.<C-R>=expand("%:e")<CR> \| 3sleep \| e #<CR> +-- map <leader>s :up \| saveas! %:p:r-<C-R>=strftime("%y.%m.%d-%H:%M")<CR>-bak.<C-R>=expand("%:e")<CR> \| 3sleep \| e #<CR> --]]) -map("n", "<leader>.b", ":!cp % %.backup<CR>") +map('n', '<leader>.b', ':!cp % %.backup<CR>') -- Toggle transparency -map("n", "<leader>tb", ":call utils#Toggle_transparent_background()<CR>") +map('n', '<leader>tb', ':call utils#Toggle_transparent_background()<CR>') -- Toggle zoom -map("n", "<leader>z", ":call utils#ZoomToggle()<CR>") -map("n", "<C-w>z", "<C-w>|<C-w>_") +map('n', '<leader>z', ':call utils#ZoomToggle()<CR>') +map('n', '<C-w>z', '<C-w>|<C-w>_') -- Toggle statusline -map("n", "<S-h>", ":call ToggleHiddenAll()<CR>") +map('n', '<S-h>', ':call utils#ToggleHiddenAll()<CR>') -- Open last closed buffer -map("n", "<C-t>", ":call OpenLastClosed()<CR>") +map('n', '<C-t>', ':call OpenLastClosed()<CR>') ---------------- Plugin Operations ---------------- -- Packer -map("n", "<leader>Pc", "<cmd>PackerCompile<cr>") -map("n", "<leader>Pi", "<cmd>PackerInstall<cr>") -map("n", "<leader>Ps", "<cmd>PackerSync<cr>") -map("n", "<leader>PS", "<cmd>PackerStatus<cr>") -map("n", "<leader>Pu", "<cmd>PackerUpdate<cr>") +map('n', '<leader>Pc', '<cmd>PackerCompile<cr>') +map('n', '<leader>Pi', '<cmd>PackerInstall<cr>') +map('n', '<leader>Ps', '<cmd>PackerSync<cr>') +map('n', '<leader>PS', '<cmd>PackerStatus<cr>') +map('n', '<leader>Pu', '<cmd>PackerUpdate<cr>') -- Tmux navigation (aserowy/tmux.nvim) -map("n", "<C-h>", "<CMD>NavigatorLeft<CR>") -map("n", "<C-l>", "<CMD>NavigatorRight<CR>") -map("n", "<C-k>", "<CMD>NavigatorUp<CR>") -map("n", "<C-j>", "<CMD>NavigatorDown<CR>") +map('n', '<C-h>', '<CMD>NavigatorLeft<CR>') +map('n', '<C-l>', '<CMD>NavigatorRight<CR>') +map('n', '<C-k>', '<CMD>NavigatorUp<CR>') +map('n', '<C-j>', '<CMD>NavigatorDown<CR>') -- ToggleTerm -map({ "n", "t" }, "<leader>tt", "<cmd>ToggleTerm<CR>") -map({ "n", "t" }, "<leader>th", "<cmd>lua Horizontal_term_toggle()<CR>") -map({ "n", "t" }, "<leader>tv", "<cmd>lua Vertical_term_toggle()<CR>") --- map["<C-\\>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" } --- map["<leader>tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } --- map["<leader>tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } --- map["<leader>tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } --- map["<leader>tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } --- map["<leader>tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- map["<leader>tf"] = { "<cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" } --- map["<leader>th"] = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", desc = "ToggleTerm horizontal split" } --- map["<leader>tv"] = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" } ---end +map({ 'n', 't' }, '<leader>tt', '<cmd>ToggleTerm<CR>') +map({ 'n', 't' }, '<leader>th', '<cmd>lua Horizontal_term_toggle()<CR>') +map({ 'n', 't' }, '<leader>tv', '<cmd>lua Vertical_term_toggle()<CR>') -- LazyGit -map({ "n", "t" }, "<leader>gg", "<cmd>lua Lazygit_toggle()<CR>") +map({ 'n', 't' }, '<leader>gg', '<cmd>lua Lazygit_toggle()<CR>') -map("n", "<leader>tg", "<cmd>lua Gh_dash()<CR>") +map('n', '<leader>tg', '<cmd>lua Gh_dash()<CR>') -- Fugitive git bindings -map("n", "<leader>gs", vim.cmd.Git) -map("n", "<leader>ga", ":Git add %:p<CR><CR>") +map('n', '<leader>gs', vim.cmd.Git) +map('n', '<leader>ga', ':Git add %:p<CR><CR>') --map("n", "<leader>gs", ":Gstatus<CR>") -map("n", "<leader>gc", ":Gcommit -v -q<CR>") -map("n", "<leader>gt", ":Gcommit -v -q %:p<CR>") +map('n', '<leader>gc', ':Gcommit -v -q<CR>') +map('n', '<leader>gt', ':Gcommit -v -q %:p<CR>') --map("n", "<leader>gd", ":Gdiff<CR>") -map("n", "<leader>ge", ":Gedit<CR>") +map('n', '<leader>ge', ':Gedit<CR>') --map("n", "<leader>gr", ":Gread<Cj>") -map("n", "<leader>gw", ":Gwrite<CR><CR>") -map("n", "<leader>gl", ":silent! Glog<CR>:bot copen<CR>") +map('n', '<leader>gw', ':Gwrite<CR><CR>') +map('n', '<leader>gl', ':silent! Glog<CR>:bot copen<CR>') --map("n", "<leader>gp", ":Ggrep<Space>") --map("n", "<Leader>gp", ":Git push<CR>") --map("n", "<Leader>gb", ":Gblame<CR>") -map("n", "<leader>gm", ":Gmove<Space>") +map('n', '<leader>gm', ':Gmove<Space>') --map("n", "<leader>gb", ":Git branch<Space>") --map("n", "<leader>go", ":Git checkout<Space>") --map("n", "<leader>gps", ":Dispatch! git push<CR>") --map("n", "<leader>gpl", ":Dispatch! git pull<CR>") -- Telescope -map("n", "<leader>ff", function() - require("telescope.builtin").find_files({ hidden = true, no_ignore = false }) +map('n', '<leader>ff', ":cd %:p:h<CR>:pwd<CR><cmd>lua require('telescope.builtin').find_files()<cr>") -- find files with hidden option +map('n', '<leader>fF', ":cd %:p:h<CR>:pwd<CR><cmd>lua require('user.mods').findFilesInCwd()<CR>", { noremap = true, silent = true, desc = 'Find files in cwd' }) +map('n', '<leader>f.', function() + require('telescope.builtin').find_files({ hidden = false, no_ignore = true }) end) -- find all files ---map("n", "<leader>fF", "<cmd>lua require('telescope.builtin').find_files()<cr>") -- find files with hidden option -map("n", "<leader>fg", "<cmd>lua require('telescope.builtin').live_grep()<cr>") -map("n", "<leader>fb", "<cmd>lua require('telescope.builtin').buffers()<cr>") -map("n", "<leader>fh", "<cmd>lua require('telescope.builtin').help_tags()<cr>") -map("n", "<leader>fc", "<cmd>lua require('telescope.builtin').commands()<cr>") -map("n", "<leader>ffc", "<cmd>lua require('telescope.builtin').current_buffer_fuzzy_find()<cr>") -map("n", "<leader>cf", "<cmd>Telescope changed_files<cr>") -map("n", "<leader>fp", "<cmd>Telescope pickers<cr>") -map("n", "<leader>fr", "<cmd>lua require('telescope.builtin').registers({})<CR>") -- registers picker -map("n", "<leader>fd", "<cmd>lua require('telescope.builtin').diagnostics()<cr>") -map("n", "<leader>fk", "<cmd>lua require('telescope.builtin').keymaps()<cr>") -map("n", "<leader>fn", [[<Cmd>lua require'plugins.telescope'.find_notes()<CR>]]) -- find notes -map("n", "<leader>fgn", [[<Cmd>lua require'plugins.telescope'.grep_notes()<CR>]]) -- search notes -map("n", "<leader>f.", [[<Cmd>lua require'plugins.telescope'.find_configs()<CR>]]) -- find configs -map("n", "<leader>fs", [[<Cmd>lua require'plugins.telescope'.find_scripts()<CR>]]) -- find scripts -map("n", "<leader>fw", [[<Cmd>lua require'plugins.telescope'.find_projects()<CR>]]) -- find projects -map("n", "<leader>fm", "<cmd>lua require('telescope').extensions.media_files.media_files({})<cr>") -- find media files -map("n", "<leader>fi", "<cmd>lua require('telescope').extensions.notify.notify({})<cr>") -- find notifications +map('n', '<leader>fg', "<cmd>lua require('telescope.builtin').live_grep()<cr>") +map('n', '<leader>fb', "<cmd>lua require('telescope.builtin').buffers()<cr>") +map('n', '<leader>fh', "<cmd>lua require('telescope.builtin').help_tags()<cr>") +map('n', '<leader>fc', "<cmd>lua require('telescope.builtin').commands()<cr>") +map('n', '<leader>cf', '<cmd>Telescope changed_files<cr>') +map('n', '<leader>fp', '<cmd>Telescope pickers<cr>') +map('n', '<leader>fd', "<cmd>lua require('telescope.builtin').diagnostics()<cr>") +map('n', '<leader>fk', "<cmd>lua require('telescope.builtin').keymaps()<cr>") +map('n', '<leader>fr', "<cmd>lua require('telescope.builtin').registers({})<CR>") -- registers picker +map('n', '<leader>fm', "<cmd>lua require('telescope').extensions.media_files.media_files({})<cr>") -- find media files +map('n', '<leader>fi', "<cmd>lua require('telescope').extensions.notify.notify({})<cr>") -- find notifications +map('n', '<Leader>fs', '<cmd>lua require("session-lens").search_session()<CR>') +map('n', '<leader>ffd', [[<Cmd>lua require'plugins.telescope'.find_dirs()<CR>]]) -- find dies +map('n', '<leader>ff.', [[<Cmd>lua require'plugins.telescope'.find_configs()<CR>]]) -- find configs +map('n', '<leader>ffs', [[<Cmd>lua require'plugins.telescope'.find_scripts()<CR>]]) -- find scripts +map('n', '<leader>ffw', [[<Cmd>lua require'plugins.telescope'.find_projects()<CR>]]) -- find projects +map('n', '<leader>ffb', [[<Cmd>lua require'plugins.telescope'.find_books()<CR>]]) -- find books +map('n', '<leader>ffn', [[<Cmd>lua require'plugins.telescope'.find_notes()<CR>]]) -- find notes +map('n', '<leader>fgn', [[<Cmd>lua require'plugins.telescope'.grep_notes()<CR>]]) -- search notes +map('n', '<Leader>ffr', "<cmd>lua require('telescope').extensions.recent_files.pick()<CR>") +map('n', '<leader>ffc', "<cmd>lua require('telescope.builtin').current_buffer_fuzzy_find()<cr>") +map('n', '<Leader>f/', "<cmd>lua require('telescope').extensions.file_browser.file_browser()<CR>") --map("n", "<leader>f/", "<cmd>lua require('plugins.telescope').curbuf()<cr>") -- find files with hidden option -map( - "n", - "<leader>fF", - ":cd %:p:h<CR>:pwd<CR><cmd>lua require('user.mods').findFilesInCwd()<CR>", - { noremap = true, silent = true, desc = "Find files in cwd" } -) +-- Map a shortcut to open the picker. -- FZF -map("n", "<leader>fz", "<cmd>lua require('fzf-lua').files()<CR>") +map('n', '<leader>fz', "<cmd>lua require('fzf-lua').files()<CR>") -- Nvim-tree -map("n", "<leader>f", ":NvimTreeToggle<CR>", {}) +map('n', '<leader>f', '<cmd>Rooter<CR>:NvimTreeToggle<CR>', {}) +map('n', '<leader>F', ':NvimTreeFindFileToggle<CR>', { noremap = false, silent = true }) -- Undotree -map("n", "<leader>u", vim.cmd.UndotreeToggle) +map('n', '<leader>u', vim.cmd.UndotreeToggle) -- Markdown-preview -map("n", "<leader>md", "<Plug>MarkdownPreviewToggle") -map("n", "<leader>mg", "<CMD>Glow<CR>") +map('n', '<leader>md', '<Plug>MarkdownPreviewToggle') +map('n', '<leader>mg', '<CMD>Glow<CR>') -- Autopairs -map("n", "<leader>ww", "<cmd>lua require('user.mods').Toggle_autopairs()<CR>") +map('n', '<leader>ww', "<cmd>lua require('user.mods').Toggle_autopairs()<CR>") -- Zen-mode toggle -map("n", "<leader>zm", "<CMD>ZenMode<CR> | :echom ('Zen Mode')<CR> | :sl! | echo ('')<CR>") +map('n', '<leader>zm', "<CMD>ZenMode<CR> | :echom ('Zen Mode')<CR> | :sl! | echo ('')<CR>") -- Vim-rooter -map( - "n", - "<leader>ro", - "<CMD>Rooter<CR> | :echom ('cd to root/project directory')<CR> | :sl! | echo ('')<CR>", - term_opts -) +map('n', '<leader>ro', "<CMD>Rooter<CR> | :echom ('cd to root/project directory')<CR> | :sl! | echo ('')<CR>", term_opts) -- Trouble (UI to show diagnostics) -map("n", "<leader>t", "<CMD>TroubleToggle<CR>") -map("n", "<leader>tw", "<CMD>TroubleToggle workspace_diagnostics<CR>") -map("n", "<leader>td", "<CMD>TroubleToggle document_diagnostics<CR>") -map("n", "<leader>tq", "<CMD>TroubleToggle quickfix<CR>") -map("n", "<leader>tl", "<CMD>TroubleToggle loclist<CR>") -map("n", "gR", "<CMD>TroubleToggle lsp_references<CR>") +map('n', '<leader>t', ':cd %:p:h<CR>:pwd<CR><CMD>TroubleToggle<CR>') +map('n', '<leader>tw', ':cd %:p:h<CR>:pwd<CR><CMD>TroubleToggle workspace_diagnostics<CR>') +map('n', '<leader>td', ':cd %:p:h<CR>:pwd<CR><CMD>TroubleToggle document_diagnostics<CR>') +map('n', '<leader>tq', ':cd %:p:h<CR>:pwd<CR><CMD>TroubleToggle quickfix<CR>') +map('n', '<leader>tl', ':cd %:p:h<CR>:pwd<CR><CMD>TroubleToggle loclist<CR>') +map('n', 'gR', '<CMD>TroubleToggle lsp_references<CR>') -- Null-ls -map("n", "<leader>ls", "<CMD>NullLsToggle<CR>") +map('n', '<leader>ls', '<CMD>NullLsToggle<CR>') -- Replacer -map("n", "<Leader>qr", ':lua require("replacer").run()<CR>') +map('n', '<Leader>qr', ':lua require("replacer").run()<CR>') -- Quickfix -map("n", "<leader>q", function() +map('n', '<leader>q', function() if vim.fn.getqflist({ winid = 0 }).winid ~= 0 then - require("plugins.quickfix").close() + require('plugins.quickfix').close() else - require("plugins.quickfix").open() - --require("quickfix").open() + require('plugins.quickfix').open() end -end, { desc = "Toggle quickfix window" }) +end, { desc = 'Toggle quickfix window' }) + +-- Move to the next and previous item in the quickfixlist +map('n', ']c', '<Cmd>cnext<CR>') +map('n', '[c', '<Cmd>cprevious<CR>') + +-- Location list +map('n', '<leader>l', '<cmd>lua require("plugins.loclist").loclist_toggle()<CR>') -- Dap (debugging) -local dap_ok, dap = pcall(require, "dap") -local dap_ui_ok, ui = pcall(require, "dapui") +local dap_ok, dap = pcall(require, 'dap') +local dap_ui_ok, ui = pcall(require, 'dapui') if not (dap_ok and dap_ui_ok) then - require("notify")("nvim-dap or dap-ui not installed!", "warning") + require('notify')('nvim-dap or dap-ui not installed!', 'warning') return end -vim.fn.sign_define("DapBreakpoint", { text = "🐞" }) +vim.fn.sign_define('DapBreakpoint', { text = '🐞' }) -- Start debugging session -map("n", "<leader>ds", function() +map('n', '<leader>ds', function() dap.continue() ui.toggle({}) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false) -- Spaces buffers evenly + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-w>=', false, true, true), 'n', false) -- Spaces buffers evenly end) -- Set breakpoints, get variable values, step into/out of functions, etc. -map("n", "<leader>dC", dap.continue) ---map("n", "<leader>dC", dap.close) ---map("n", "<leader>dt", dap.terminate) -map("n", "<leader>dt", ui.toggle) -map("n", "<leader>dd", function() +map('n', '<leader>dC', dap.continue) +-- map("n", "<leader>dC", dap.close) +-- map("n", "<leader>dt", dap.terminate) +map('n', '<leader>dt', ui.toggle) +map('n', '<leader>dd', function() dap.disconnect({ terminateDebuggee = true }) end) -map("n", "<leader>dn", dap.step_over) -map("n", "<leader>di", dap.step_into) -map("n", "<leader>do", dap.step_out) -map("n", "<leader>db", dap.toggle_breakpoint) -map("n", "<leader>dB", function() +map('n', '<leader>dn', dap.step_over) +map('n', '<leader>di', dap.step_into) +map('n', '<leader>do', dap.step_out) +map('n', '<leader>db', dap.toggle_breakpoint) +map('n', '<leader>dB', function() dap.clear_breakpoints() - require("notify")("Breakpoints cleared", "warn") + require('notify')('Breakpoints cleared', 'warn') end) -map("n", "<leader>dl", require("dap.ui.widgets").hover) -map("n", "<leader>de", function() - require("dapui").float_element() -end, { desc = "Open Element" }) -map("n", "<leader>dq", function() - require("dapui").close() - require("dap").repl.close() - local session = require("dap").session() +map('n', '<leader>dl', require('dap.ui.widgets').hover) +map('n', '<leader>de', function() + require('dapui').float_element() +end, { desc = 'Open Element' }) +map('n', '<leader>dq', function() + require('dapui').close() + require('dap').repl.close() + local session = require('dap').session() if session then - require("dap").terminate() + require('dap').terminate() end - require("nvim-dap-virtual-text").refresh() -end, { desc = "Terminate Debug" }) -map("n", "<leader>dc", function() - require("telescope").extensions.dap.commands() -end, { desc = "DAP-Telescope: Commands" }) + require('nvim-dap-virtual-text').refresh() +end, { desc = 'Terminate Debug' }) +map('n', '<leader>dc', function() + require('telescope').extensions.dap.commands() +end, { desc = 'DAP-Telescope: Commands' }) --vim.keymap.set("n", "<leader>B", ":lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>") --vim.keymap.set("v", "<leader>B", ":lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>") --vim.keymap.set("n", "<leader>lp", ":lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>") @@ -443,15 +409,26 @@ end, { desc = "DAP-Telescope: Commands" }) -- Close debugger and clear breakpoints --map("n", "<leader>de", function() --- dap.clear_breakpoints() --- ui.toggle({}) --- dap.terminate() --- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false) --- require("notify")("Debugger session ended", "warn") +-- dap.clear_breakpoints() +-- ui.toggle({}) +-- dap.terminate() +-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-w>=", false, true, true), "n", false) +-- require("notify")("Debugger session ended", "warn") --end) --- Dashboard -map("n", "<leader><Space>", "<CMD>Dashboard<CR>") +-- Toggle Dashboard +map('n', '<leader><Space>', '<CMD>lua require("user.mods").toggle_dashboard()<CR>') -- Lsp Lines toggle -map("", "<Leader>l", require("lsp_lines").toggle, { desc = "Toggle lsp_lines" }) +map('', '<Leader>ll', require('lsp_lines').toggle, { desc = 'Toggle lsp_lines' }) + +-- SnipRun +map({ 'n', 'v' }, '<leader>r', '<Plug>SnipRun<CR>') + +-- Codi +map('n', '<leader>co', '<CMD>lua require("user.mods").toggleCodi()<CR>') + +-- Scratch buffer +map('n', '<leader>ss', '<CMD>lua require("user.mods").Scratch("float")<CR>') +map('n', '<leader>sh', '<CMD>lua require("user.mods").Scratch("horizontal")<CR>') +map('n', '<leader>sv', '<CMD>lua require("user.mods").Scratch("vertical")<CR>') diff --git a/.config/nvim/lua/user/mods.lua b/.config/nvim/lua/user/mods.lua index 2f14acd..6420ed5 100644 --- a/.config/nvim/lua/user/mods.lua +++ b/.config/nvim/lua/user/mods.lua @@ -24,19 +24,17 @@ M.has = function(feat) return false end - -------------------------------------------------- - -- Format on save -local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) -require("null-ls").setup({ +local format_augroup = vim.api.nvim_create_augroup('LspFormatting', {}) +require('null-ls').setup({ -- you can reuse a shared lspconfig on_attach callback here on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, + if client.supports_method('textDocument/formatting') then + vim.api.nvim_clear_autocmds({ group = format_augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd('BufWritePre', { + group = format_augroup, buffer = bufnr, callback = function() -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead @@ -48,6 +46,8 @@ require("null-ls").setup({ end, }) +vim.cmd([[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]) +--vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] -------------------------------------------------- @@ -55,11 +55,19 @@ require("null-ls").setup({ ---@param item any ---@return boolean? function M.empty(item) - if not item then return true end + if not item then + return true + end local item_type = type(item) - if item_type == 'string' then return item == '' end - if item_type == 'number' then return item <= 0 end - if item_type == 'table' then return vim.tbl_isempty(item) end + if item_type == 'string' then + return item == '' + end + if item_type == 'number' then + return item <= 0 + end + if item_type == 'table' then + return vim.tbl_isempty(item) + end return item ~= nil end @@ -70,7 +78,7 @@ function M.may_create_dir(dir) local res = fn.isdirectory(dir) if res == 0 then - fn.mkdir(dir, "p") + fn.mkdir(dir, 'p') end end @@ -79,16 +87,16 @@ end --- Toggle cmp completion vim.g.cmp_toggle_flag = false -- initialize local normal_buftype = function() - return vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt" + return vim.api.nvim_buf_get_option(0, 'buftype') ~= 'prompt' end M.toggle_completion = function() - local ok, cmp = pcall(require, "cmp") + local ok, cmp = pcall(require, 'cmp') if ok then local next_cmp_toggle_flag = not vim.g.cmp_toggle_flag if next_cmp_toggle_flag then - print("completion on") + print('completion on') else - print("completion off") + print('completion off') end cmp.setup({ enabled = function() @@ -101,42 +109,60 @@ M.toggle_completion = function() end, }) else - print("completion not available") + print('completion not available') end end - -------------------------------------------------- --- Make sure using latest neovim version function M.get_nvim_version() local actual_ver = vim.version() - local nvim_ver_str = string.format("%d.%d.%d", actual_ver.major, actual_ver.minor, actual_ver.patch) + local nvim_ver_str = string.format('%d.%d.%d', actual_ver.major, actual_ver.minor, actual_ver.patch) return nvim_ver_str end function M.add_pack(name) - local status, error = pcall(vim.cmd, "packadd " .. name) + local status, error = pcall(vim.cmd, 'packadd ' .. name) return status end -------------------------------------------------- +-- Define a global function to retrieve LSP clients based on Neovim version +function M.get_lsp_clients(bufnr) + local mods = require('user.mods') + --local expected_ver = '0.10.0' + local nvim_ver = mods.get_nvim_version() + + local version_major, version_minor = string.match(nvim_ver, '(%d+)%.(%d+)') + version_major = tonumber(version_major) + version_minor = tonumber(version_minor) + + if version_major > 0 or (version_major == 0 and version_minor >= 10) then + return vim.lsp.get_clients({ buffer = bufnr }) + else + return vim.lsp.buf_get_clients() + end +end + +-------------------------------------------------- + --- Toggle autopairs on/off (requires "windwp/nvim-autopairs") function M.Toggle_autopairs() - local ok, autopairs = pcall(require, "nvim-autopairs") + local ok, autopairs = pcall(require, 'nvim-autopairs') if ok then if autopairs.state.disabled then autopairs.enable() - print("autopairs on") + print('autopairs on') else autopairs.disable() - print("autopairs off") + print('autopairs off') end else - print("autopairs not available") + print('autopairs not available') end end @@ -159,12 +185,13 @@ end --]]) function M.findFilesInCwd() - vim.cmd("let g:rooter_manual_only = 1") -- Toggle the rooter plugin - require("plugins.telescope").findhere() + vim.cmd('let g:rooter_manual_only = 1') -- Toggle the rooter plugin + require('plugins.telescope').findhere() vim.defer_fn(function() - vim.cmd("let g:rooter_manual_only = 0") -- Change back to automatic rooter + vim.cmd('let g:rooter_manual_only = 0') -- Change back to automatic rooter end, 100) end + --function M.findFilesInCwd() -- vim.cmd("let g:rooter_manual_only = 1") -- Toggle the rooter plugin -- require("plugins.telescope").findhere() @@ -182,12 +209,12 @@ function M.Toggle_executable() -- File is executable, unset the executable permission vim.fn.system('chmod -x ' .. current_file) --print(current_file .. ' is no longer executable.') - print("No longer executable") + print('No longer executable') else -- File is not executable, set the executable permission vim.fn.system('chmod +x ' .. current_file) --print(current_file .. ' is now executable.') - print("Now executable") + print('Now executable') end end @@ -212,21 +239,21 @@ end ------ -local prev_cwd = "" +local prev_cwd = '' function M.Set_git_env_vars() local cwd = vim.fn.getcwd() - if prev_cwd == "" then + if prev_cwd == '' then -- First buffer being opened, set prev_cwd to cwd prev_cwd = cwd elseif cwd ~= prev_cwd then -- Working directory has changed since last buffer was opened prev_cwd = cwd - local git_dir_job = vim.fn.jobstart({ "git", "rev-parse", "--git-dir" }) + local git_dir_job = vim.fn.jobstart({ 'git', 'rev-parse', '--git-dir' }) local command_status = vim.fn.jobwait({ git_dir_job })[1] if command_status > 0 then - vim.env.GIT_DIR = vim.fn.expand("$HOME/.cfg") - vim.env.GIT_WORK_TREE = vim.fn.expand("~") + vim.env.GIT_DIR = vim.fn.expand('$HOME/.cfg') + vim.env.GIT_WORK_TREE = vim.fn.expand('~') else vim.env.GIT_DIR = nil vim.env.GIT_WORK_TREE = nil @@ -234,16 +261,11 @@ function M.Set_git_env_vars() end end -vim.cmd [[augroup my_git_env_vars]] -vim.cmd [[ autocmd!]] -vim.cmd [[ autocmd BufEnter * lua require('user.mods').Set_git_env_vars()]] -vim.cmd [[ autocmd VimEnter * lua require('user.mods').Set_git_env_vars()]] -vim.cmd [[augroup END]] - --------------------------------------------------- - -vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]] ---vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] +vim.cmd([[augroup my_git_env_vars]]) +vim.cmd([[ autocmd!]]) +vim.cmd([[ autocmd BufEnter * lua require('user.mods').Set_git_env_vars()]]) +vim.cmd([[ autocmd VimEnter * lua require('user.mods').Set_git_env_vars()]]) +vim.cmd([[augroup END]]) -------------------------------------------------- @@ -266,11 +288,11 @@ function M.update_tmux_status() file:close() if nvim_running then -- Neovim is running, update the mode file and refresh tmux - VI_MODE = "" -- Clear VI_MODE to show Neovim mode - vim.cmd("silent !tmux refresh-client -S") + VI_MODE = '' -- Clear VI_MODE to show Neovim mode + vim.cmd('silent !tmux refresh-client -S') end ---- Force tmux to update the status - vim.cmd("silent !tmux refresh-client -S") + vim.cmd('silent !tmux refresh-client -S') end vim.cmd([[ @@ -295,6 +317,7 @@ vim.cmd([[ --autocmd FocusGained * lua require("user.mods").update_tmux_status() --autocmd FocusLost * lua require("user.mods").update_tmux_status() --autocmd CmdwinEnter,CmdwinLeave * lua require("user.mods").update_tmux_status() + -------------------------------------------------- -- function OpenEmulatorList() @@ -311,8 +334,6 @@ vim.cmd([[ -- -- vim.api.nvim_create_user_command('OpenEmulators', OpenEmulatorList, {}) - - --local api = vim.api --local fn = vim.fn --local cmd = vim.cmd @@ -396,43 +417,42 @@ function M.Update_neovim() -- Create a new floating window local bufnr, winid = vim.api.nvim_create_buf(false, true) vim.api.nvim_open_win(bufnr, true, { - relative = "editor", + relative = 'editor', width = 80, height = 20, row = 2, col = 2, - style = "minimal", - border = "single", + style = 'minimal', + border = 'single', }) -- Function to append a line to the buffer in the floating window local function append_line(line) - vim.api.nvim_buf_set_option(bufnr, "modifiable", true) + vim.api.nvim_buf_set_option(bufnr, 'modifiable', true) vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, { line }) - vim.api.nvim_buf_set_option(bufnr, "modifiable", false) + vim.api.nvim_buf_set_option(bufnr, 'modifiable', false) end -- Download the latest version of Neovim - append_line("Downloading the latest version of Neovim...") - os.execute( - "curl -L -o nvim-linux64.tar.gz https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz") - append_line("Download complete.") + append_line('Downloading the latest version of Neovim...') + os.execute('curl -L -o nvim-linux64.tar.gz https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz') + append_line('Download complete.') -- Extract the downloaded archive - append_line("Extracting the downloaded archive...") - os.execute("tar xzvf nvim-linux64.tar.gz") - append_line("Extraction complete.") + append_line('Extracting the downloaded archive...') + os.execute('tar xzvf nvim-linux64.tar.gz') + append_line('Extraction complete.') -- Replace the existing Neovim installation with the new version - append_line("Replacing the existing Neovim installation...") - os.execute("rm -rf $HOME/nvim") - os.execute("mv nvim-linux64 $HOME/nvim") - append_line("Update complete.") + append_line('Replacing the existing Neovim installation...') + os.execute('rm -rf $HOME/nvim') + os.execute('mv nvim-linux64 $HOME/nvim') + append_line('Update complete.') -- Clean up the downloaded file - append_line("Cleaning up the downloaded file...") - os.execute("rm nvim-linux64.tar.gz") - append_line("Cleanup complete.") + append_line('Cleaning up the downloaded file...') + os.execute('rm nvim-linux64.tar.gz') + append_line('Cleanup complete.') -- Close the floating window after a delay vim.defer_fn(function() @@ -441,8 +461,356 @@ function M.Update_neovim() end -- Bind a keymap to the update_neovim function (optional) -vim.api.nvim_set_keymap('n', '<leader>U', '<cmd> lua require("user.mods").Update_neovim()<CR>', - { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '<leader>U', '<cmd> lua require("user.mods").Update_neovim()<CR>', { noremap = true, silent = true }) + +-------------------------------------------------- + +-- Fix or suppress closing nvim error message (/src/unix/core.c:147: uv_close: Assertion `!uv__is_closing(handle)' failed.) +vim.api.nvim_create_autocmd({ 'VimLeave' }, { + callback = function() + vim.fn.jobstart('!notify-send 2>/dev/null &', { detach = true }) + end, +}) + +-------------------------------------------------- + +-- Rooter +--vim.cmd([[autocmd BufEnter * lua vim.cmd('Rooter')]]) + +-------------------------------------------------- + +-- Nvim-tree +local modifiedBufs = function(bufs) -- nvim-tree is also there in modified buffers so this function filter it out + local t = 0 + for k, v in pairs(bufs) do + if v.name:match('NvimTree_') == nil then + t = t + 1 + end + end + return t +end + +-- Deleting current file opened behaviour +function M.DeleteCurrentBuffer() + local cbn = vim.api.nvim_get_current_buf() + local buffers = vim.fn.getbufinfo({ buflisted = true }) + local size = #buffers + local idx = 0 + + for n, e in ipairs(buffers) do + if e.bufnr == cbn then + idx = n + break -- Exit loop as soon as we find the buffer + end + end + + if idx == 0 then + return + end + + if idx == size then + vim.cmd('bprevious') + else + vim.cmd('bnext') + end + + vim.cmd('silent! bdelete ' .. cbn) + + -- Open a new blank window + vim.cmd('silent! enew') -- Opens a new vertical split + -- OR + -- vim.cmd("new") -- Opens a new horizontal split + -- Delay before opening a new split + --vim.defer_fn(function() + -- vim.cmd("enew") -- Opens a new vertical split + --end, 100) -- Adjust the delay as needed (in milliseconds) + -- Delay before closing the nvim-tree window +end + +vim.cmd([[autocmd FileType NvimTree lua require("user.mods").DeleteCurrentBuffer()]]) + +-- On :bd nvim-tree should behave as if it wasn't opened +vim.api.nvim_create_autocmd('BufEnter', { + nested = true, + callback = function() + -- Only 1 window with nvim-tree left: we probably closed a file buffer + if #vim.api.nvim_list_wins() == 1 and require('nvim-tree.utils').is_nvim_tree_buf() then + local api = require('nvim-tree.api') + -- Required to let the close event complete. An error is thrown without this. + vim.defer_fn(function() + -- close nvim-tree: will go to the last buffer used before closing + api.tree.toggle({ find_file = true, focus = true }) + -- re-open nivm-tree + api.tree.toggle({ find_file = true, focus = true }) + -- nvim-tree is still the active window. Go to the previous window. + vim.cmd('wincmd p') + end, 0) + end + end, +}) + +-- Dismiss notifications when opening nvim-tree window +local function isNvimTreeOpen() + local win = vim.fn.win_findbuf(vim.fn.bufnr('NvimTree')) + return vim.fn.empty(win) == 0 +end + +function M.DisableNotify() + if isNvimTreeOpen() then + require('notify').dismiss() + end +end + +vim.cmd([[ + autocmd! WinEnter,WinLeave * lua require('user.mods').DisableNotify() +]]) + +-------------------------------------------------- +-- Toggle Dashboard +function M.toggle_dashboard() + if vim.bo.filetype == 'dashboard' then + vim.cmd('bdelete') + else + vim.cmd('Dashboard') + end +end + +-------------------------------------------------- + +-- Helper function to suppress errors +local function silent_execute(cmd) + vim.fn['serverlist']() -- Required to prevent 'Press ENTER' prompt + local result = vim.fn.system(cmd .. ' 2>/dev/null') + vim.fn['serverlist']() + return result +end + +-------------------------------------------------- + +-- Toggle Codi +-- Define a global variable to track Codi's state +local is_codi_open = false + +function M.toggleCodi() + if is_codi_open then + -- Close Codi + vim.cmd('Codi!') + is_codi_open = false + else + -- Open Codi + vim.cmd('Codi') + is_codi_open = true + end +end + +-------------------------------------------------- + +---- Function to create or toggle a scratch buffer +local scratch_buf = nil -- Store the scratch buffer globally +local scratch_win = nil -- Store the scratch window globally +local scratch_date = os.date('%Y-%m-%d') +local scratch_dir = vim.fn.expand('~/notes/private') +local scratch_file = 'scratch-' .. scratch_date .. '.md' + +function M.Scratch(Split_direction) + -- Check if the directory exists, and create it if it doesn't + if vim.fn.isdirectory(scratch_dir) == 0 then + vim.fn.mkdir(scratch_dir, 'p') + end + + -- Determine the window type based on Split_direction + local current_window_type = 'float' + if Split_direction == 'float' then + current_window_type = 'float' + elseif Split_direction == 'vertical' then + current_window_type = 'vertical' + elseif Split_direction == 'horizontal' then + current_window_type = 'horizontal' + end + + local file_path = scratch_dir .. '/' .. scratch_file + + if scratch_win and vim.api.nvim_win_is_valid(scratch_win) then + -- Window exists, save buffer to file and close it + WriteScratchBufferToFile(scratch_buf, file_path) + vim.cmd(':w!') + vim.api.nvim_win_close(scratch_win, true) + scratch_win = nil + else + if scratch_buf and vim.api.nvim_buf_is_valid(scratch_buf) then + -- Buffer exists, reuse it + OpenScratchWindow(scratch_buf, current_window_type) + else + -- Buffer doesn't exist, create it and load the file if it exists + scratch_buf = OpenScratchBuffer(file_path) + OpenScratchWindow(scratch_buf, current_window_type) + end + end +end + +function WriteScratchBufferToFile(buf, file_path) + local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false) + local content = table.concat(lines, '\n') + local escaped_file_path = vim.fn.fnameescape(file_path) + + -- Write the buffer content to the file + local file = io.open(escaped_file_path, 'w') + if file then + file:write(content) + file:close() + end +end + +function OpenScratchBuffer(file_path) + local buf = vim.api.nvim_create_buf(true, false) + + -- Set the file name for the buffer + local escaped_file_path = vim.fn.fnameescape(file_path) + vim.api.nvim_buf_set_name(buf, escaped_file_path) + + -- Check if the file exists and load it if it does + if vim.fn.filereadable(file_path) == 1 then + local file_contents = vim.fn.readfile(file_path) + vim.api.nvim_buf_set_lines(buf, 0, -1, true, file_contents) + else + -- Insert initial content + vim.api.nvim_buf_set_lines(buf, 0, -1, true, { + '# Quick Notes - ' .. scratch_date, + '--------------------------', + '', + }) + + -- Save the initial content to the file + vim.cmd(':w') + end + + return buf +end + +function OpenScratchWindow(buf, current_window_type) + if current_window_type == 'float' then + local opts = { + relative = 'win', + width = 120, + height = 10, + border = 'single', + row = 20, + col = 20, + } + scratch_win = vim.api.nvim_open_win(buf, true, opts) + -- Go to the last line of the buffer + vim.api.nvim_win_set_cursor(0, { vim.api.nvim_buf_line_count(buf), 1 }) + elseif current_window_type == 'vertical' then + vim.cmd('vsplit') + vim.api.nvim_win_set_buf(0, buf) + scratch_win = 0 + elseif current_window_type == 'horizontal' then + vim.cmd('split') + vim.api.nvim_win_set_buf(0, buf) + scratch_win = 0 + end +end + +-------------------------------------------------- + +-- Intercept file open +local augroup = vim.api.nvim_create_augroup('user-autocmds', { clear = true }) +local intercept_file_open = true +vim.api.nvim_create_user_command('InterceptToggle', function() + intercept_file_open = not intercept_file_open + local intercept_state = '`Enabled`' + if not intercept_file_open then + intercept_state = '`Disabled`' + end + vim.notify('Intercept file open set to ' .. intercept_state, vim.log.levels.INFO, { + title = 'Intercept File Open', + ---@param win integer The window handle + on_open = function(win) + vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), 'filetype', 'markdown') + end, + }) +end, { desc = 'Toggles intercepting BufNew to open files in custom programs' }) + +-- NOTE: Add "BufReadPre" to the autocmd events to also intercept files given on the command line, e.g. +-- `nvim myfile.txt` +vim.api.nvim_create_autocmd({ 'BufNew' }, { + group = augroup, + callback = function(args) + ---@type string + local path = args.match + ---@type integer + local bufnr = args.buf + + ---@type string? The file extension if detected + local extension = vim.fn.fnamemodify(path, ':e') + ---@type string? The filename if detected + local filename = vim.fn.fnamemodify(path, ':t') + + ---Open a given file path in a given program and remove the buffer for the file. + ---@param buf integer The buffer handle for the opening buffer + ---@param fpath string The file path given to the program + ---@param fname string The file name used in notifications + ---@param prog string The program to execute against the file path + local function open_in_prog(buf, fpath, fname, prog) + vim.notify(string.format('Opening `%s` in `%s`', fname, prog), vim.log.levels.INFO, { + title = 'Open File in External Program', + ---@param win integer The window handle + on_open = function(win) + vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), 'filetype', 'markdown') + end, + }) + local mods = require('user.mods') + local nvim_ver = mods.get_nvim_version() + + local version_major, version_minor = string.match(nvim_ver, '(%d+)%.(%d+)') + version_major = tonumber(version_major) + version_minor = tonumber(version_minor) + + if version_major > 0 or (version_major == 0 and version_minor >= 10) then + vim.system({ prog, fpath }, { detach = true }) + else + vim.fn.jobstart({ prog, fpath }, { detach = true }) + end + vim.api.nvim_buf_delete(buf, { force = true }) + end + + local extension_callbacks = { + ['pdf'] = function(buf, fpath, fname) + open_in_prog(buf, fpath, fname, 'zathura') + end, + ['png'] = function(buf, fpath, fname) + open_in_prog(buf, fpath, fname, 'feh') + end, + ['jpg'] = 'png', + ['mp4'] = function(buf, fpath, fname) + open_in_prog(buf, fpath, fname, 'mpv') + end, + ['gif'] = 'mp4', + } + + ---Get the extension callback for a given extension. Will do a recursive lookup if an extension callback is actually + ---of type string to get the correct extension + ---@param ext string A file extension. Example: `png`. + ---@return fun(bufnr: integer, path: string, filename: string?) extension_callback The extension callback to invoke, expects a buffer handle, file path, and filename. + local function extension_lookup(ext) + local callback = extension_callbacks[ext] + if type(callback) == 'string' then + callback = extension_lookup(callback) + end + return callback + end + + if extension ~= nil and not extension:match('^%s*$') and intercept_file_open then + local callback = extension_lookup(extension) + if type(callback) == 'function' then + callback(bufnr, path, filename) + end + end + end, +}) + +-------------------------------------------------- +-- ... return M diff --git a/.config/nvim/lua/user/opts.lua b/.config/nvim/lua/user/opts.lua index bb7f36c..c724710 100644 --- a/.config/nvim/lua/user/opts.lua +++ b/.config/nvim/lua/user/opts.lua @@ -1,74 +1,40 @@ --[[ opts.lua ]] --- " Load indent files, to automatically do language-dependent indenting. ---vim.cmd([[ --- "filetype plugin indent on ---]]) - --- Let clipboard register be + -vim.cmd([[ - let g:clipbrdDefaultReg = '+' -]]) - ---vim.cmd([[ --- "autocmd BufEnter * :syntax sync fromstart --- "syntax enable --- "set nocompatible --- "autocmd FileType lua set comments=s1:---,m:--,ex:-- ---]]) - --- Fast macros without lazyredraw -vim.cmd([[ - set re=0 - nnoremap @ <cmd>execute "noautocmd norm! " . v:count1 . "@" . getcharstr()<cr> - xnoremap @ :<C-U>execute "noautocmd '<,'>norm! " . v:count1 . "@" . getcharstr()<cr> -]]) - --- Stop annoying auto commenting on new lines -vim.cmd [[ - augroup annoying - au! - au BufEnter * set fo-=c fo-=r fo-=o - augroup end -]] -- Environment --vim.opt.shell = "zsh" -- vim.o.updatetime = 250 -vim.o.shell = "/bin/zsh" -vim.scriptencoding = "utf-8" -- -vim.opt.encoding = "utf-8" -- -vim.opt.fileencoding = "utf-8" -- -vim.g.python3_host_prog = "/usr/bin/python3" -- +vim.o.shell = '/bin/zsh' +vim.scriptencoding = 'utf-8' -- +vim.opt.encoding = 'utf-8' -- +vim.opt.fileencoding = 'utf-8' -- +vim.g.python3_host_prog = '/usr/bin/python3' -- vim.g.loaded_python3_provider = 1 -- vim.g.sh_noisk = 1 -- iskeyword word boundaries when editing a 'sh' file vim.o.autochdir = true --vim.o.writeany= true --- Colors -vim.opt.termguicolors = true - -- Clipboard -vim.opt.clipboard:append({ "unnamedplus" }) -- Install xclip or this will slowdown startup +vim.opt.clipboard:append({ 'unnamedplus' }) -- Install xclip or this will slowdown startup -- Behaviour -vim.opt.backspace = { "start", "eol", "indent" } -- Make backspace work as you would expect. +vim.opt.backspace = { 'start', 'eol', 'indent' } -- Make backspace work as you would expect. vim.opt.hidden = true -- Switch between buffers without having to save first. vim.opt.splitbelow = true -- make split put the new buffer below the current buffer vim.opt.splitright = true -- make vsplit put the new buffer on the right of the current buffer vim.opt.scrolloff = 8 -- vim.opt.sidescrolloff = 8 -- how many lines to scroll when using the scrollbar vim.opt.autoread = true -- reload files if changed externally -vim.opt.display = "lastline" -- Show as much as possible of the last line. -vim.opt.inccommand = "split" -- +vim.opt.display = 'lastline' -- Show as much as possible of the last line. +vim.opt.inccommand = 'split' -- vim.opt.ttyfast = true -- Faster redrawing. vim.opt.lazyredraw = false -- Only redraw when necessary -vim.opt.keywordprg = ":help" -- :help options +vim.opt.keywordprg = ':help' -- :help options vim.opt.ruler = true -- vim.opt.errorbells = false -- vim.opt.list = true -- Show non-printable characters. vim.opt.showmatch = true -- vim.opt.matchtime = 3 -- -vim.opt.showbreak = "↪ " -- +vim.opt.showbreak = '↪ ' -- vim.opt.linebreak = true -- vim.opt.exrc = true -- --vim.opt.autochdir = true -- or use this to use <:e> to create a file in current directory @@ -96,7 +62,7 @@ vim.opt.smartindent = true -- smart indent vim.opt.number = true -- vim.opt.title = true -- --vim.opt.colorcolumn = "+1" -- -vim.opt.signcolumn = "yes:1" -- always show the sign column +vim.opt.signcolumn = 'yes:1' -- always show the sign column --vim.opt.signcolumn = "yes:" .. vim.o.numberwidth --vim.opt.signcolumn = "number" --vim.opt.signcolumn = "no" -- @@ -124,15 +90,15 @@ vim.opt.report = 0 -- Always report changed lines. --vim.opt.stl = " " -- Backup/undo/swap -local prefix = vim.env.XDG_CONFIG_HOME or vim.fn.expand("~/.config") +local prefix = vim.env.XDG_CONFIG_HOME or vim.fn.expand('~/.config') --vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" -vim.opt.undodir = { prefix .. "/nvim/tmp/.undo//" } -vim.opt.backupdir = { prefix .. "/nvim/tmp/.backup//" } -vim.opt.directory = { prefix .. "/nvim/tmp/.swp//" } -vim.opt.backup = false -- ---vim.opt.undofile = false -- +vim.opt.undodir = { prefix .. '/nvim/tmp/.undo//' } +vim.opt.directory = { prefix .. '/nvim/tmp/.swp//' } +vim.opt.backupdir = { prefix .. '/nvim/tmp/.backup//' } vim.opt.undofile = true -- -vim.opt.swapfile = true -- +vim.opt.swapfile = true -- +vim.opt.backup = true -- +--vim.opt.backupcopy = -- Add timestamp as extension for backup files vim.api.nvim_create_autocmd('BufWritePre', { group = vim.api.nvim_create_augroup('timestamp_backupext', { clear = true }), @@ -145,55 +111,73 @@ vim.api.nvim_create_autocmd('BufWritePre', { -- Format --vim.opt.textwidth = 80 -- -vim.opt.isfname:append("@-@") +vim.opt.isfname:append('@-@') vim.cmd([[let &t_Cs = "\e[4:3m"]]) -- Undercurl vim.cmd([[let &t_Ce = "\e[4:0m"]]) -- -vim.opt.path:append({ "**" }) -- Finding files - Search down into subfolder -vim.cmd("set whichwrap+=<,>,[,],h,l") -- +vim.opt.path:append({ '**' }) -- Finding files - Search down into subfolder +vim.cmd('set whichwrap+=<,>,[,],h,l') -- vim.cmd([[set iskeyword+=-]]) -- --vim.cmd([[set formatoptions-=cro]]) -- TODO: this doesn't seem to work vim.opt.formatoptions = vim.opt.formatoptions - - "t" -- wrap with text width - + "c" -- wrap comments - + "r" -- insert comment after enter - - "o" -- insert comment after o/O - - "q" -- allow formatting of comments with gq - - "a" -- format paragraphs - + "n" -- recognized numbered lists - - "2" -- use indent of second line for paragraph - + "l" -- long lines are not broken - + "j" -- remove comment when joining lines + - 't' -- wrap with text width + + 'c' -- wrap comments + + 'r' -- insert comment after enter + - 'o' -- insert comment after o/O + - 'q' -- allow formatting of comments with gq + - 'a' -- format paragraphs + + 'n' -- recognized numbered lists + - '2' -- use indent of second line for paragraph + + 'l' -- long lines are not broken + + 'j' -- remove comment when joining lines vim.opt.wrapscan = true -- " Searches wrap around end-of-file. --vim.wo.number = true -- --vim.opt.wrap = false -- No Wrap lines --vim.opt.foldmethod = 'manual' -- --vim.opt.foldmethod = "expr" -- -vim.opt.foldmethod = "manual" +vim.opt.foldmethod = 'manual' vim.opt.foldlevel = 3 vim.opt.confirm = false -vim.opt.shortmess:append("sI") +--vim.opt.shortmess:append("sI") --vim.opt.shortmess = "a" --vim.opt.shortmess = "sI" --vim.o.shortmess = vim.o.shortmess:gsub('s', '') +vim.opt.shortmess = table.concat({ -- Use abbreviations and short messages in command menu line. + 'f', -- Use "(3 of 5)" instead of "(file 3 of 5)". + 'i', -- Use "[noeol]" instead of "[Incomplete last line]". + 'l', -- Use "999L, 888C" instead of "999 lines, 888 characters". + 'm', -- Use "[+]" instead of "[Modified]". + 'n', -- Use "[New]" instead of "[New File]". + 'r', -- Use "[RO]" instead of "[readonly]". + 'w', -- Use "[w]", "[a]" instead of "written", "appended". + 'x', -- Use "[dos]", "[unix]", "[mac]" instead of "[dos format]", "[unix format]", "[mac format]". + 'o', -- Overwrite message for writing a file with subsequent message. + 'O', -- Message for reading a file overwrites any previous message. + 's', -- Disable "search hit BOTTOM, continuing at TOP" such messages. + 't', -- Truncate file message at the start if it is too long. + 'T', -- Truncate other messages in the middle if they are too long. + 'I', -- Don't give the :intro message when starting. + 'c', -- Don't give ins-completion-menu messages. + 'F', -- Don't give the file info when editing a file. +}) vim.opt.fillchars = { - horiz = "─", - horizup = "┴", - horizdown = "┬", - vert = "│", - vertleft = "┤", - vertright = "├", - verthoriz = "┼", - foldopen = "", - foldsep = "│", - foldclose = "", - fold = "─", - eob = " ", + horiz = '─', + horizup = '┴', + horizdown = '┬', + vert = '│', + vertleft = '┤', + vertright = '├', + verthoriz = '┼', + foldopen = '', + foldsep = '│', + foldclose = '', + fold = '─', + eob = ' ', --diff = "┃", - diff = "░", - msgsep = "━", + diff = '░', + msgsep = '━', --msgsep = "‾", } -vim.opt.listchars = { tab = "▸ ", trail = "·" } -- +vim.opt.listchars = { tab = '▸ ', trail = '·' } -- --vim.opt.fillchars:append({ eob = " " }) -- remove the ~ from end of buffer vim.opt.modeline = true -- vim.opt.modelines = 3 -- modelines (comments that set vim options on a per-file basis) @@ -210,14 +194,14 @@ vim.opt.smartcase = true -- smart case vim.opt.synmaxcol = 200 -- Only highlight the first 200 columns. vim.opt.winblend = 30 --vim.opt.winblend = 5 -vim.opt.wildoptions = "pum" -- +vim.opt.wildoptions = 'pum' -- --vim.opt.pumblend = 5 -- vim.opt.pumblend = 12 -- --vim.opt.pumblend=15 vim.opt.pumheight = 10 -- pop up menu height -- Better Completion -vim.opt.complete = { ".", "w", "b", "u", "t" } -- +vim.opt.complete = { '.', 'w', 'b', 'u', 't' } -- --vim.opt.completeopt = { "longest,menuone,preview" } -- vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } --vim.opt.completeopt = { "menuone", "noselect" } -- mostly just for cmp @@ -225,25 +209,25 @@ vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } -- Wildmenu completion -- vim.opt.wildmenu = true -- -vim.opt.wildmode = { "list:longest" } -- -vim.opt.wildignore:append({ ".hg", ".git", ".svn" }) -- Version control -vim.opt.wildignore:append({ "*.aux", "*.out", "*.toc" }) -- LaTeX intermediate files -vim.opt.wildignore:append({ "*.jpg", "*.bmp", "*.gif", "*.png", "*.jpeg" }) -- binary images -vim.opt.wildignore:append({ "*.o", "*.obj", "*.exe", "*.dll", "*.manifest" }) -- compiled object files -vim.opt.wildignore:append({ "*.spl" }) -- compiled spelling word lists -vim.opt.wildignore:append({ "*.sw?" }) -- Vim swap files -vim.opt.wildignore:append({ "*.DS_Store" }) -- OSX bullshit -vim.opt.wildignore:append({ "*.luac" }) -- Lua byte code -vim.opt.wildignore:append({ "migrations" }) -- Django migrations -vim.opt.wildignore:append({ "*.pyc" }) -- Python byte code -vim.opt.wildignore:append({ "*.orig" }) -- Merge resolution files -vim.opt.wildignore:append({ "*/node_modules/*" }) -- +vim.opt.wildmode = { 'list:longest' } -- +vim.opt.wildignore:append({ '.hg', '.git', '.svn' }) -- Version control +vim.opt.wildignore:append({ '*.aux', '*.out', '*.toc' }) -- LaTeX intermediate files +vim.opt.wildignore:append({ '*.jpg', '*.bmp', '*.gif', '*.png', '*.jpeg' }) -- binary images +vim.opt.wildignore:append({ '*.o', '*.obj', '*.exe', '*.dll', '*.manifest' }) -- compiled object files +vim.opt.wildignore:append({ '*.spl' }) -- compiled spelling word lists +vim.opt.wildignore:append({ '*.sw?' }) -- Vim swap files +vim.opt.wildignore:append({ '*.DS_Store' }) -- OSX bullshit +vim.opt.wildignore:append({ '*.luac' }) -- Lua byte code +vim.opt.wildignore:append({ 'migrations' }) -- Django migrations +vim.opt.wildignore:append({ '*.pyc' }) -- Python byte code +vim.opt.wildignore:append({ '*.orig' }) -- Merge resolution files +vim.opt.wildignore:append({ '*/node_modules/*' }) -- -- Shada vim.opt.shada = "!,'1000,f1,<1000,s100,:1000,/1000,h" -- Sessions -vim.opt.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal" +vim.opt.sessionoptions = 'blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal' --vim.opt.sessionoptions = "curdir,folds,help,options,tabpages,winsize,winpos,terminal,globals" -- --vim.opt.sessionoptions = "buffers,curdir,folds,help,tabpages,winsize,winpos,terminal" --vim.opt.sessionoptions:remove({ "blank", "buffers", "globals" }) @@ -253,6 +237,40 @@ vim.g.netrw_browse_split = 0 vim.g.netrw_banner = 0 vim.g.netrw_winsize = 25 +-- " Load indent files, to automatically do language-dependent indenting. +--vim.cmd([[ +-- "filetype plugin indent on +--]]) +vim.cmd('filetype plugin on') +vim.cmd('filetype indent off') + +-- Let clipboard register be + +vim.cmd([[ + let g:clipbrdDefaultReg = '+' +]]) + +--vim.cmd([[ +-- "autocmd BufEnter * :syntax sync fromstart +-- "syntax enable +-- "set nocompatible +-- "autocmd FileType lua set comments=s1:---,m:--,ex:-- +--]]) + +-- Fast macros without lazyredraw +vim.cmd([[ + set re=0 + nnoremap @ <cmd>execute "noautocmd norm! " . v:count1 . "@" . getcharstr()<cr> + xnoremap @ :<C-U>execute "noautocmd '<,'>norm! " . v:count1 . "@" . getcharstr()<cr> +]]) + +-- Stop annoying auto commenting on new lines +vim.cmd([[ + augroup annoying + au! + au BufEnter * set fo-=c fo-=r fo-=o + augroup end +]]) + -- Cursorline vim.cmd([[ " Only show cursorline in the current window and in normal mode augroup cline @@ -262,7 +280,7 @@ vim.cmd([[ " Only show cursorline in the augroup END ]]) vim.opt.cursorline = true -- -vim.opt.guicursor = "i:ver100,r:hor100" -- +vim.opt.guicursor = 'i:ver100,r:hor100' -- -- Trailing whitespace vim.cmd([[ " Only show in insert mode diff --git a/.config/nvim/lua/user/pack.lua b/.config/nvim/lua/user/pack.lua index 177f8d8..2f3e1e8 100644 --- a/.config/nvim/lua/user/pack.lua +++ b/.config/nvim/lua/user/pack.lua @@ -3,17 +3,17 @@ local fn = vim.fn -------------------------------------------------- -- Automatically install packer -local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" +local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then PACKER_BOOTSTRAP = fn.system({ - "git", - "clone", - "--depth", - "1", - "https://github.com/wbthomason/packer.nvim", + 'git', + 'clone', + '--depth', + '1', + 'https://github.com/wbthomason/packer.nvim', install_path, }) - print("Installing packer, please close and reopen Neovim...") + print('Installing packer, please close and reopen Neovim...') vim.cmd([[packadd packer.nvim]]) end @@ -30,7 +30,7 @@ vim.cmd([[ -------------------------------------------------- -- Use a protected call so don't error out on first use -local status_ok, packer = pcall(require, "packer") +local status_ok, packer = pcall(require, 'packer') if not status_ok then return end @@ -43,7 +43,7 @@ packer.init({ --max_jobs = 90, display = { open_fn = function() - return require("packer.util").float({ border = "rounded" }) + return require('packer.util').float({ border = 'rounded' }) end, }, }) @@ -53,33 +53,33 @@ packer.init({ -- Install plugins here return packer.startup(function(use) -- Defaults - use("wbthomason/packer.nvim") -- Have packer manage itself (package manager) - use("nvim-lua/plenary.nvim") -- Useful lua functions used by lots of plugins - use("lewis6991/impatient.nvim") -- Faster loading/startup times + use('wbthomason/packer.nvim') -- Have packer manage itself (package manager) + use('nvim-lua/plenary.nvim') -- Useful lua functions used by lots of plugins + use('lewis6991/impatient.nvim') -- Faster loading/startup times -- Tree-sitter - use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" }) -- For language parsing, examples: highlighting, folding, jumping, refactoring... - use("nvim-treesitter/nvim-treesitter-refactor") -- Refactor module for nvim-treesitter + use({ 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }) -- For language parsing, examples: highlighting, folding, jumping, refactoring... + use('nvim-treesitter/nvim-treesitter-refactor') -- Refactor module for nvim-treesitter -- lsp - use("williamboman/mason.nvim") -- Package manager to install and manage LSP servers, DAP servers, linters and formatters - use("neovim/nvim-lspconfig") -- Collection of LSP configs - use("williamboman/mason-lspconfig.nvim") -- Bridges mason.nvim with nvim-lspconfig to help use them together + use('williamboman/mason.nvim') -- Package manager to install and manage LSP servers, DAP servers, linters and formatters + use('neovim/nvim-lspconfig') -- Collection of LSP configs + use('williamboman/mason-lspconfig.nvim') -- Bridges mason.nvim with nvim-lspconfig to help use them together use({ - "https://git.sr.ht/~whynothugo/lsp_lines.nvim", + 'https://git.sr.ht/~whynothugo/lsp_lines.nvim', config = function() - require("lsp_lines").setup() + require('lsp_lines').setup() end, }) - use("rmagatti/goto-preview") + use('rmagatti/goto-preview') -- Debugger - use("mfussenegger/nvim-dap") -- Debug Adapter Protocol client implementation for Neovim - use("rcarriga/nvim-dap-ui") -- UI for nvim-dap + use('mfussenegger/nvim-dap') -- Debug Adapter Protocol client implementation for Neovim + use('rcarriga/nvim-dap-ui') -- UI for nvim-dap --use { "rcarriga/nvim-dap-ui", requires = {"mfussenegger/nvim-dap"} } - use("theHamsta/nvim-dap-virtual-text") - use("gabrielpoca/replacer.nvim") - use("jayp0521/mason-nvim-dap.nvim") + use('theHamsta/nvim-dap-virtual-text') + use('gabrielpoca/replacer.nvim') + use('jayp0521/mason-nvim-dap.nvim') --use({ -- "jayp0521/mason-nvim-dap.nvim", -- config = function() @@ -92,7 +92,7 @@ return packer.startup(function(use) -- Linters/Formatters use('mhartington/formatter.nvim') - use("jay-babu/mason-null-ls.nvim") + use('jay-babu/mason-null-ls.nvim') --use({"jayp0521/mason-null-ls.nvim", -- config = function() -- require('mason-null-ls.nvim').setup({ @@ -101,37 +101,37 @@ return packer.startup(function(use) -- end --}) use({ - "jose-elias-alvarez/null-ls.nvim", -- Provides LSP: linters, formatters, diagnostics, code actions and etc... - requires = { "jay-babu/mason-null-ls.nvim" }, + 'jose-elias-alvarez/null-ls.nvim', -- Provides LSP: linters, formatters, diagnostics, code actions and etc... + requires = { 'jay-babu/mason-null-ls.nvim' }, }) -- Completion - use("hrsh7th/nvim-cmp") -- Completion engine plugin - use("hrsh7th/cmp-nvim-lsp") -- Completion source for nvim-lsp - use("hrsh7th/cmp-buffer") -- Completion source for content of current buffer - use("hrsh7th/cmp-path") -- Completion source for paths - use("hrsh7th/cmp-cmdline") -- Completion source for command-line - use("petertriho/cmp-git") -- Completion source for git - use("tamago324/cmp-zsh") -- Completion source for zsh - use("f3fora/cmp-spell") -- Completion source for spell-checking - use("hrsh7th/cmp-calc") -- Completion source for math calculation - use("saadparwaiz1/cmp_luasnip") -- Completion source for snippets, specifically for luasnip - use("hrsh7th/cmp-nvim-lsp-signature-help") -- Completion source for displaying function signatures with the current parameter emphasized - use("rcarriga/cmp-dap") + use('hrsh7th/nvim-cmp') -- Completion engine plugin + use('hrsh7th/cmp-nvim-lsp') -- Completion source for nvim-lsp + use('hrsh7th/cmp-buffer') -- Completion source for content of current buffer + use('hrsh7th/cmp-path') -- Completion source for paths + use('hrsh7th/cmp-cmdline') -- Completion source for command-line + use('petertriho/cmp-git') -- Completion source for git + use('tamago324/cmp-zsh') -- Completion source for zsh + use('f3fora/cmp-spell') -- Completion source for spell-checking + use('hrsh7th/cmp-calc') -- Completion source for math calculation + use('saadparwaiz1/cmp_luasnip') -- Completion source for snippets, specifically for luasnip + use('hrsh7th/cmp-nvim-lsp-signature-help') -- Completion source for displaying function signatures with the current parameter emphasized + use('rcarriga/cmp-dap') -- Snippets - use("L3MON4D3/LuaSnip") -- Snippet engine - use("rafamadriz/friendly-snippets") -- Collection of snippets to use + use('L3MON4D3/LuaSnip') -- Snippet engine + use('rafamadriz/friendly-snippets') -- Collection of snippets to use -- Git - use("tpope/vim-fugitive") -- + use('tpope/vim-fugitive') -- --use("dinhhuy258/git.nvim") -- For git blame & browse - use("kdheepak/lazygit.nvim") -- Terminal UI for git commands - use("lewis6991/gitsigns.nvim") -- Git decorations + use('kdheepak/lazygit.nvim') -- Terminal UI for git commands + use('lewis6991/gitsigns.nvim') -- Git decorations -- File explorer/fuzzy finder - use("kyazdani42/nvim-tree.lua") -- File explorer - use('ibhagwan/fzf-lua') -- Fuzzy finder + use('kyazdani42/nvim-tree.lua') -- File explorer + use('ibhagwan/fzf-lua') -- Fuzzy finder use('ThePrimeagen/harpoon') --use("nvim-telescope/telescope.nvim") -- Fuzzy finder with lots of features/extendabilities use({ @@ -145,41 +145,46 @@ return packer.startup(function(use) 'nvim-telescope/telescope-live-grep-args.nvim', 'nvim-telescope/telescope-file-browser.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }, - } + }, }) - use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }) -- Support fzf syntax/algorithm - use("nvim-telescope/telescope-ui-select.nvim") -- - use("nvim-telescope/telescope-project.nvim") -- - use("nvim-telescope/telescope-media-files.nvim") -- - use("nvim-telescope/telescope-file-browser.nvim") -- - use({ "nvim-telescope/telescope-symbols.nvim", after = "telescope.nvim" }) -- Search emoji(s) and other symbols - use("nvim-telescope/telescope-dap.nvim") - use("axkirillov/telescope-changed-files") -- + use({ 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }) -- Support fzf syntax/algorithm + use('nvim-telescope/telescope-ui-select.nvim') -- + use('nvim-telescope/telescope-project.nvim') -- + use('nvim-telescope/telescope-media-files.nvim') -- + use('nvim-telescope/telescope-file-browser.nvim') -- + use({ 'nvim-telescope/telescope-symbols.nvim', after = 'telescope.nvim' }) -- Search emoji(s) and other symbols + use('nvim-telescope/telescope-dap.nvim') + use('axkirillov/telescope-changed-files') -- + use('smartpde/telescope-recent-files') + use('rmagatti/auto-session') + use('rmagatti/session-lens') -- UX - use("folke/neodev.nvim") + use('folke/neodev.nvim') use({ 'numToStr/Navigator.nvim', -- Navigate between Tmux and Nvim config = function() require('Navigator').setup() end, }) - use({ "tpope/vim-eunuch", cmd = { "Rename", "Delete" } }) -- Handy unix commands inside Vim (Rename, Move etc.) + use({ 'tpope/vim-eunuch', cmd = { 'Rename', 'Delete', 'Mkdir' } }) -- Handy unix commands inside Vim (Rename, Move etc.) --use("tpope/vim-surround") -- --use("tpope/vim-obsession") -- - use("tpope/vim-unimpaired") -- + use('tpope/vim-unimpaired') -- --use("vimpostor/vim-tpipeline") -- --use("nathom/filetype.nvim") -- - use("mbbill/undotree") - use({ "myusuf3/numbers.vim", -- - vim.cmd("let g:numbers_exclude = ['dashboard']") + use('mbbill/undotree') + use({ + 'myusuf3/numbers.vim', -- + vim.cmd("let g:numbers_exclude = ['dashboard']"), }) - use("windwp/nvim-autopairs") -- - use("numToStr/Comment.nvim") -- - use("akinsho/toggleterm.nvim") -- - use("tweekmonster/startuptime.vim") -- + use('windwp/nvim-autopairs') -- + use('numToStr/Comment.nvim') -- + use('akinsho/toggleterm.nvim') -- + use('tweekmonster/startuptime.vim') -- + use('qpkorr/vim-bufkill') use({ - "ggandor/leap.nvim", -- + 'ggandor/leap.nvim', -- config = function() require('leap').add_default_mappings() --require("leap").set_default_keymaps() @@ -188,24 +193,25 @@ return packer.startup(function(use) end, }) use({ - "ggandor/flit.nvim", -- + 'ggandor/flit.nvim', -- config = function() - require("flit").setup() + require('flit').setup() end, }) - use("folke/which-key.nvim") -- - use("folke/zen-mode.nvim") -- - use("romainl/vim-cool") -- - use("antoinemadec/FixCursorHold.nvim") -- + use('folke/which-key.nvim') -- + use('folke/zen-mode.nvim') -- + use('romainl/vim-cool') -- + use('antoinemadec/FixCursorHold.nvim') -- use({ - "folke/trouble.nvim", - requires = "nvim-tree/nvim-web-devicons", + 'folke/trouble.nvim', + requires = 'nvim-tree/nvim-web-devicons', }) - use({ "airblade/vim-rooter", -- + use({ + 'airblade/vim-rooter', -- --vim.cmd("let g:rooter_change_directory_for_non_project_files = ''"), --vim.cmd("let g:rooter_change_directory_for_non_project_files = 'current'") }) - + use({ 'michaelb/sniprun', run = 'bash ./install.sh' }) --use("vim-test/vim-test") -- --use({ -- "rcarriga/vim-ultest", -- @@ -221,31 +227,23 @@ return packer.startup(function(use) --end, --}) use({ - "nvim-neotest/neotest", + 'nvim-neotest/neotest', requires = { { - "nvim-neotest/neotest-python", - "nvim-neotest/neotest-plenary", - "nvim-neotest/neotest-vim-test", + 'nvim-neotest/neotest-python', + 'nvim-neotest/neotest-plenary', + 'nvim-neotest/neotest-vim-test', }, - } - }) - use({ - 'rmagatti/session-lens', - requires = { 'rmagatti/auto-session', 'nvim-telescope/telescope.nvim' }, - config = function() - require('session-lens').setup({ --[[your custom config--]] }) - vim.keymap.set('n', '<leader>s', require('session-lens').search_session) -- <-- this sets it to `Ctrl + s` - end + }, }) -- Colorschemes - use("bluz71/vim-nightfly-guicolors") - use("ayu-theme/ayu-vim") - use("joshdick/onedark.vim") - use("NTBBloodbath/doom-one.nvim") - use("nyngwang/nvimgelion") - use("projekt0n/github-nvim-theme") + use('bluz71/vim-nightfly-guicolors') + use('ayu-theme/ayu-vim') + use('joshdick/onedark.vim') + use('NTBBloodbath/doom-one.nvim') + use('nyngwang/nvimgelion') + use('projekt0n/github-nvim-theme') use({ 'folke/tokyonight.nvim', config = function() @@ -253,34 +251,34 @@ return packer.startup(function(use) transparent = true, dim_inactive = false, }) - end + end, }) -- UI - use("kyazdani42/nvim-web-devicons") -- - use("onsails/lspkind-nvim") -- + use('kyazdani42/nvim-web-devicons') -- + use('onsails/lspkind-nvim') -- use({ 'kevinhwang91/nvim-ufo', requires = 'kevinhwang91/promise-async' }) -- Fold code use({ - "luukvbaal/statuscol.nvim", + 'luukvbaal/statuscol.nvim', config = function() - local builtin = require "statuscol.builtin" - require("statuscol").setup { + local builtin = require('statuscol.builtin') + require('statuscol').setup({ relculright = true, segments = { - { text = { builtin.foldfunc }, click = "v:lua.ScFa" }, - { text = { "%s" }, click = "v:lua.ScSa" }, - { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" }, + { text = { builtin.foldfunc }, click = 'v:lua.ScFa' }, + { text = { '%s' }, click = 'v:lua.ScSa' }, + { text = { builtin.lnumfunc, ' ' }, click = 'v:lua.ScLa' }, }, - } - end + }) + end, }) use({ 'glepnir/dashboard-nvim', --event = 'VimEnter', - requires = { 'nvim-tree/nvim-web-devicons' } + requires = { 'nvim-tree/nvim-web-devicons' }, }) - use("rcarriga/nvim-notify") -- Notification plugin - use("karb94/neoscroll.nvim") -- Faster/smooth scrolling + use('rcarriga/nvim-notify') -- Notification plugin + use('karb94/neoscroll.nvim') -- Faster/smooth scrolling --use("MunifTanjim/prettier.nvim") -- Prettier plugin for Neovim's built-in LSP client use({ 'norcalli/nvim-colorizer.lua', -- colorize hexa and rgb strings @@ -298,25 +296,28 @@ return packer.startup(function(use) mode = 'foreground', }, }) - end + end, }) - use({"j-hui/fidget.nvim", + use({ + 'j-hui/fidget.nvim', tag = 'legacy', - }) -- UI to show nvim-lsp progress - use({ "simrat39/symbols-outline.nvim", -- + }) -- UI to show nvim-lsp progress + use('metakirby5/codi.vim') + use({ + 'simrat39/symbols-outline.nvim', -- config = function() - require("symbols-outline").setup({ + require('symbols-outline').setup({ auto_close = true, }) - end + end, }) use({ - "kosayoda/nvim-lightbulb", -- - requires = "antoinemadec/FixCursorHold.nvim", + 'kosayoda/nvim-lightbulb', -- + requires = 'antoinemadec/FixCursorHold.nvim', }) use({ - "SmiteshP/nvim-navic", -- Statusline/Winbar component that uses LSP to show current code context - requires = "neovim/nvim-lspconfig" + 'SmiteshP/nvim-navic', -- Statusline/Winbar component that uses LSP to show current code context + requires = 'neovim/nvim-lspconfig', }) use({ 'rebelot/heirline.nvim', -- Statusline that is highly configurable @@ -325,19 +326,19 @@ return packer.startup(function(use) }) -- Language specific tools - use("simrat39/rust-tools.nvim") -- Rust tooling ecosystem + use('simrat39/rust-tools.nvim') -- Rust tooling ecosystem use({ - "saecki/crates.nvim", -- - requires = { "nvim-lua/plenary.nvim" }, + 'saecki/crates.nvim', -- + requires = { 'nvim-lua/plenary.nvim' }, config = function() - require("crates").setup() + require('crates').setup() end, }) use({ - "akinsho/flutter-tools.nvim", + 'akinsho/flutter-tools.nvim', requires = { - "nvim-lua/plenary.nvim", - "stevearc/dressing.nvim", -- optional for vim.ui.select + 'nvim-lua/plenary.nvim', + 'stevearc/dressing.nvim', -- optional for vim.ui.select }, config = function() require('flutter-tools').setup({ @@ -349,16 +350,19 @@ return packer.startup(function(use) end, }) use({ - "iamcco/markdown-preview.nvim", -- Markdown Preview - run = function() vim.fn["mkdp#util#install"]() end, + 'iamcco/markdown-preview.nvim', -- Markdown Preview + run = function() + vim.fn['mkdp#util#install']() + end, + vim.cmd("let g:mkdp_auto_close = 0"), }) use({ - "ellisonleao/glow.nvim", -- Markdown Preview + 'ellisonleao/glow.nvim', -- Markdown Preview config = function() - require("glow").setup({ - style = "dark", + require('glow').setup({ + style = 'dark', }) - end + end, }) -------------------------------------------------- @@ -366,6 +370,6 @@ return packer.startup(function(use) -- Automatically set up your configuration after cloning packer.nvim -- Put this at the end after all plugins if PACKER_BOOTSTRAP then - require("packer").sync() + require('packer').sync() end end) |
