From 624b821251a0858b6aa0e171186a88b6036f7d78 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Thu, 4 Aug 2022 22:40:32 +0930 Subject: [PATCH] Thu 04 Aug 2022 22:40:32 ACST --- .config/nvim/init.lua | 9 + .config/nvim/lua/config/barbar.lua | 5 + .config/nvim/lua/config/cmp.lua | 120 ++++++++++ .config/nvim/lua/config/general/autocmd.lua | 52 +++++ .../nvim/lua/config/general/colorscheme.lua | 3 + .config/nvim/lua/config/general/init.lua | 6 + .config/nvim/lua/config/general/options.lua | 28 +++ .config/nvim/lua/config/general/remaps.lua | 41 ++++ .config/nvim/lua/config/gitsigns.lua | 41 ++++ .config/nvim/lua/config/go.lua | 1 + .config/nvim/lua/config/lsp/init.lua | 52 +++++ .config/nvim/lua/config/lsp/installer.lua | 26 +++ .config/nvim/lua/config/lsp/keymaps.lua | 37 ++++ .config/nvim/lua/config/lualine.lua | 40 ++++ .config/nvim/lua/config/luasnip.lua | 14 ++ .config/nvim/lua/config/nvim-neo-tree.lua | 205 ++++++++++++++++++ .config/nvim/lua/config/php-doc.lua | 7 + .config/nvim/lua/config/telescope.lua | 71 ++++++ .config/nvim/lua/config/tmux.lua | 17 ++ .config/nvim/lua/config/treesitter.lua | 25 +++ .config/nvim/lua/helper/toggle-tab-width.lua | 19 ++ .config/nvim/lua/packer-plugins.lua | 143 ++++++++++++ .config/nvim/lua/utils/init.lua | 37 ++++ 23 files changed, 999 insertions(+) create mode 100644 .config/nvim/init.lua create mode 100644 .config/nvim/lua/config/barbar.lua create mode 100644 .config/nvim/lua/config/cmp.lua create mode 100644 .config/nvim/lua/config/general/autocmd.lua create mode 100644 .config/nvim/lua/config/general/colorscheme.lua create mode 100644 .config/nvim/lua/config/general/init.lua create mode 100644 .config/nvim/lua/config/general/options.lua create mode 100644 .config/nvim/lua/config/general/remaps.lua create mode 100644 .config/nvim/lua/config/gitsigns.lua create mode 100644 .config/nvim/lua/config/go.lua create mode 100644 .config/nvim/lua/config/lsp/init.lua create mode 100644 .config/nvim/lua/config/lsp/installer.lua create mode 100644 .config/nvim/lua/config/lsp/keymaps.lua create mode 100644 .config/nvim/lua/config/lualine.lua create mode 100644 .config/nvim/lua/config/luasnip.lua create mode 100644 .config/nvim/lua/config/nvim-neo-tree.lua create mode 100644 .config/nvim/lua/config/php-doc.lua create mode 100644 .config/nvim/lua/config/telescope.lua create mode 100644 .config/nvim/lua/config/tmux.lua create mode 100644 .config/nvim/lua/config/treesitter.lua create mode 100644 .config/nvim/lua/helper/toggle-tab-width.lua create mode 100644 .config/nvim/lua/packer-plugins.lua create mode 100644 .config/nvim/lua/utils/init.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..8a3e3ea --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,9 @@ + +-- General options and remaps +require('config.general') + +-- Helper functions +require('helper.toggle-tab-width') + +-- Plugins +require('packer-plugins') diff --git a/.config/nvim/lua/config/barbar.lua b/.config/nvim/lua/config/barbar.lua new file mode 100644 index 0000000..35fe2c1 --- /dev/null +++ b/.config/nvim/lua/config/barbar.lua @@ -0,0 +1,5 @@ +-- Set barbar's options +require'bufferline'.setup { + -- Enable/disable auto-hiding the tab bar when there is a single buffer + auto_hide = true, +} diff --git a/.config/nvim/lua/config/cmp.lua b/.config/nvim/lua/config/cmp.lua new file mode 100644 index 0000000..f81e25e --- /dev/null +++ b/.config/nvim/lua/config/cmp.lua @@ -0,0 +1,120 @@ +local M = {} + +function M.setup() + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil + end + + local luasnip = require("luasnip") + local cmp = require("cmp") + + cmp.setup { + completion = { completeopt = "menu,menuone,noinsert", keyword_length = 1 }, + experimental = { native_menu = false, ghost_text = false }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + formatting = { + format = function(entry, vim_item) + vim_item.menu = ({ + nvim_lsp = "[LSP]", + buffer = "[Buffer]", + luasnip = "[Snip]", + nvim_lua = "[Lua]", + treesitter = "[Treesitter]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + mapping = { + [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.mapping { i = cmp.mapping.close(), c = cmp.mapping.close() }, + [""] = cmp.mapping { + i = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }, + c = function(fallback) + if cmp.visible() then + cmp.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false } + else + fallback() + end + end, + }, + [""] = cmp.mapping( + function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { + "i", + "s", + "c", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + "c", + }), + + }, + sources = { + { name = "nvim_lsp" }, + { name = "treesitter" }, + { name = "buffer" }, + { name = "luasnip" }, + { name = "nvim_lua" }, + { name = "path" }, + -- { name = "spell" }, + -- { name = "emoji" }, + -- { name = "calc" }, + }, + window = { + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + winhighlight = "NormalFloat:NormalFloat,FloatBorder:TelescopeBorder", + }, + }, + } + + -- Use buffer source for `/` + cmp.setup.cmdline("/", { + enabled = false + -- mapping = cmp.mapping.preset.cmdline(), + -- sources = { + -- { name = "buffer" }, + -- }, + }) + + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + +end + +return M diff --git a/.config/nvim/lua/config/general/autocmd.lua b/.config/nvim/lua/config/general/autocmd.lua new file mode 100644 index 0000000..0fdbddf --- /dev/null +++ b/.config/nvim/lua/config/general/autocmd.lua @@ -0,0 +1,52 @@ + +local aucmd_dict = { + FileType = { + { + pattern = "dart,vue,js", + callback = function() + vim.opt_local.tabstop = 2 + vim.opt_local.softtabstop = 2 + vim.opt_local.shiftwidth = 2 + end, + }, + }, + BufWritePre = { + { + command = [[%s/\s\+$//e]], + }, + { + pattern = '*.go', + callback = function () require('go.format').gofmt() end, + }, + }, + BufRead = { + { + command = [[if @% !~# '\.git[\/\\]COMMIT_EDITMSG$' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif]] + }, + { + pattern = { '*.docker' }, + callback = function() + vim.opt_local.syntax = 'dockerfile' + end + } + }, + BufNewFile = { + { + pattern = { '*.docker' }, + callback = function() + vim.opt_local.syntax = 'dockerfile' + end + } + }, + VimLeave = { + { + command = [[mksession! ~/.cache/nvim/session/shutdown_session.vim]] + }, + }, +} + +for event, opt_tbls in pairs(aucmd_dict) do + for _, opt_tbl in pairs(opt_tbls) do + vim.api.nvim_create_autocmd(event, opt_tbl) + end +end diff --git a/.config/nvim/lua/config/general/colorscheme.lua b/.config/nvim/lua/config/general/colorscheme.lua new file mode 100644 index 0000000..b5eff4c --- /dev/null +++ b/.config/nvim/lua/config/general/colorscheme.lua @@ -0,0 +1,3 @@ + +vim.cmd [[colorscheme moonfly]] + diff --git a/.config/nvim/lua/config/general/init.lua b/.config/nvim/lua/config/general/init.lua new file mode 100644 index 0000000..5e5adc5 --- /dev/null +++ b/.config/nvim/lua/config/general/init.lua @@ -0,0 +1,6 @@ + +require('config.general.options') +require('config.general.remaps') +require('config.general.autocmd') + +require('config.general.colorscheme') diff --git a/.config/nvim/lua/config/general/options.lua b/.config/nvim/lua/config/general/options.lua new file mode 100644 index 0000000..c527aa0 --- /dev/null +++ b/.config/nvim/lua/config/general/options.lua @@ -0,0 +1,28 @@ +vim.g.mapleader = ',' + +vim.o.clipboard = 'unnamedplus' + +vim.o.nohlsearch = true +vim.o.incsearch = true +vim.o.ignorecase = true + +vim.o.mouse = 'a' +vim.o.smartcase = true +vim.o.linebreak = true + +vim.o.noswapfile = true +vim.o.nobackup = true +vim.o.undodir = vim.fn.expand('~/.cache/nvim/undodir') +vim.o.undofile = true + +vim.o.encoding = 'utf-8' +vim.o.number = true +vim.o.relativenumber = true + +vim.o.tabstop = 4 +vim.o.softtabstop = 4 +vim.o.expandtab = true +vim.o.shiftwidth = 4 +vim.o.smarttab = true + +vim.o.formatoptions = 'tqj' diff --git a/.config/nvim/lua/config/general/remaps.lua b/.config/nvim/lua/config/general/remaps.lua new file mode 100644 index 0000000..f455a74 --- /dev/null +++ b/.config/nvim/lua/config/general/remaps.lua @@ -0,0 +1,41 @@ +local options = { noremap = true } + +vim.api.nvim_set_keymap('n', 'c', '"_c', options) + +-- Easily open splits +vim.api.nvim_set_keymap('n', 'hs', 'split', options) +vim.api.nvim_set_keymap('n', 'vs', 'vsplit', options) + +-- Copy the entire file +vim.api.nvim_set_keymap('n', 'y', 'ggyG', options) + +-- Manually store session +vim.api.nvim_set_keymap('n', '', 'mksession! ~/.cache//nvim/session/manual_session.vim', options) +-- Restore manually stored session +vim.api.nvim_set_keymap('n', '', 'source ~/.cache/nvim/session/manual_session.vim', options) +-- Restore auto saved session created on exit +vim.api.nvim_set_keymap('n', '', 'source ~/.cache/nvim/session/shutdown_session.vim', options) + +-- Replace all is aliased to S. +vim.api.nvim_set_keymap('n', '', '%s//g', options) + +-- Navigating with guides +vim.api.nvim_set_keymap('n', '', '/<++>"_c4l', options) +vim.api.nvim_set_keymap('i', '', '/<++>"_c4l', options) +vim.api.nvim_set_keymap('v', '', '/<++>"_c4l', options) + +-- Spell-check +vim.api.nvim_set_keymap('n', 'o', 'setlocal spell! spelllang=en_au', options) + +vim.api.nvim_set_keymap('n', '', 'BufferMovePrevious', options) +vim.api.nvim_set_keymap('n', '>', 'BufferMoveNext', options) + +vim.api.nvim_set_keymap('n', '', 'BufferGoto 1', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 2', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 3', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 4', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 5', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 6', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 7', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 8', options) +vim.api.nvim_set_keymap('n', '', 'BufferGoto 9', options) diff --git a/.config/nvim/lua/config/gitsigns.lua b/.config/nvim/lua/config/gitsigns.lua new file mode 100644 index 0000000..1de3fce --- /dev/null +++ b/.config/nvim/lua/config/gitsigns.lua @@ -0,0 +1,41 @@ +require('gitsigns').setup { + signs = { + add = {hl = 'GitSignsAdd' , text = '│', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'}, + change = {hl = 'GitSignsChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, + delete = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, + topdelete = {hl = 'GitSignsDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, + changedelete = {hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true + }, + attach_to_untracked = true, + current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter = ', - ', + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, -- Disable if file is longer than this (in lines) + preview_config = { + -- Options passed to nvim_open_win + border = 'single', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + yadm = { + enable = false + }, +} diff --git a/.config/nvim/lua/config/go.lua b/.config/nvim/lua/config/go.lua new file mode 100644 index 0000000..e26b510 --- /dev/null +++ b/.config/nvim/lua/config/go.lua @@ -0,0 +1 @@ +require('go').setup() diff --git a/.config/nvim/lua/config/lsp/init.lua b/.config/nvim/lua/config/lsp/init.lua new file mode 100644 index 0000000..984c87a --- /dev/null +++ b/.config/nvim/lua/config/lsp/init.lua @@ -0,0 +1,52 @@ +local M = {} + +local servers = { + gopls = {}, + html = {}, + jsonls = {}, + pyright = {}, + tsserver = {}, + vimls = {}, + dartls = {}, + dockerls = {}, + intelephense = {}, + sqlls = {}, + volar = {}, +} + +local function on_attach(client, bufnr) + -- Enable completion triggered by + -- See `:help omnifunc` and `:help ins-completion` for more information. + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") + + -- Use LSP as the handler for formatexpr. + -- See `:help formatexpr` for more information. + vim.api.nvim_buf_set_option(0, "formatexpr", "v:lua.vim.lsp.formatexpr()") + + -- Configure key mappings + require("config.lsp.keymaps").setup(client, bufnr) +end + +local lsp_signature = require "lsp_signature" +lsp_signature.setup { + bind = true, + handler_opts = { + border = "rounded", + }, +} + +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + +local opts = { + on_attach = on_attach, + capabilities = cababilities, + flags = { + debounce_text_changes = 150, + }, +} + +function M.setup() + require("config.lsp.installer").setup(servers, opts) +end + +return M diff --git a/.config/nvim/lua/config/lsp/installer.lua b/.config/nvim/lua/config/lsp/installer.lua new file mode 100644 index 0000000..012eb69 --- /dev/null +++ b/.config/nvim/lua/config/lsp/installer.lua @@ -0,0 +1,26 @@ +local lsp_installer_servers = require "nvim-lsp-installer.servers" +local utils = require "utils" + +local M = {} + +function M.setup(servers, options) + for server_name, _ in pairs(servers) do + local server_available, server = lsp_installer_servers.get_server(server_name) + + if server_available then + server:on_ready(function() + local opts = vim.tbl_deep_extend("force", options, servers[server.name] or {}) + server:setup(opts) + end) + + if not server:is_installed() then + utils.info("Installing " .. server.name) + server:install() + end + else + utils.error(server) + end + end +end + +return M diff --git a/.config/nvim/lua/config/lsp/keymaps.lua b/.config/nvim/lua/config/lsp/keymaps.lua new file mode 100644 index 0000000..8d6d06c --- /dev/null +++ b/.config/nvim/lua/config/lsp/keymaps.lua @@ -0,0 +1,37 @@ +local M = {} + +local keymap = vim.api.nvim_set_keymap +local buf_keymap = vim.api.nvim_buf_set_keymap + +local function keymappings(client, bufnr) + local opts = { noremap = true, silent = true } + + -- Key mappings + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) + vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) + vim.keymap.set("n", "[e", function () vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR}) end, opts) + vim.keymap.set("n", "]e", function () vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR}) end, opts) + + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set("n", "K", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "of", vim.diagnostic.open_float, opts) + + -- if client.resolved_capabilities.document_formatting then + -- vim.keymap.set("n", "ff", vim.lsp.buf.formatting, opts) + -- end + + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + -- vim.keymap.set("n", "gr", function() vim.lsp.buf.references({ includeDeclaration = false }) end, opts) + vim.keymap.set("n", "gh", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, opts) + +end + +function M.setup(client, bufnr) + keymappings(client, bufnr) +end + +return M diff --git a/.config/nvim/lua/config/lualine.lua b/.config/nvim/lua/config/lualine.lua new file mode 100644 index 0000000..9780045 --- /dev/null +++ b/.config/nvim/lua/config/lualine.lua @@ -0,0 +1,40 @@ +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'moonfly', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} +} diff --git a/.config/nvim/lua/config/luasnip.lua b/.config/nvim/lua/config/luasnip.lua new file mode 100644 index 0000000..10ecf74 --- /dev/null +++ b/.config/nvim/lua/config/luasnip.lua @@ -0,0 +1,14 @@ +local M = {} + +function M.setup() + local luasnip = require "luasnip" + + luasnip.config.set_config { + history = false, + updateevents = "TextChanged,TextChangedI", + } + + require("luasnip/loaders/from_vscode").load() +end + +return M diff --git a/.config/nvim/lua/config/nvim-neo-tree.lua b/.config/nvim/lua/config/nvim-neo-tree.lua new file mode 100644 index 0000000..7160b8e --- /dev/null +++ b/.config/nvim/lua/config/nvim-neo-tree.lua @@ -0,0 +1,205 @@ + +-- Unless you are still migrating, remove the deprecated commands from v1.x +vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) + +-- If you want icons for diagnostic errors, you'll need to define them somewhere: +vim.fn.sign_define("DiagnosticSignError", + {text = " ", texthl = "DiagnosticSignError"}) +vim.fn.sign_define("DiagnosticSignWarn", + {text = " ", texthl = "DiagnosticSignWarn"}) +vim.fn.sign_define("DiagnosticSignInfo", + {text = " ", texthl = "DiagnosticSignInfo"}) +vim.fn.sign_define("DiagnosticSignHint", + {text = "", texthl = "DiagnosticSignHint"}) +-- NOTE: this is changed from v1.x, which used the old style of highlight groups +-- in the form "LspDiagnosticsSignWarning" + +require("neo-tree").setup({ + close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab + popup_border_style = "rounded", + enable_git_status = true, + enable_diagnostics = true, + sort_case_insensitive = false, -- used when sorting files and directories in the tree + sort_function = nil , -- use a custom function for sorting files and directories in the tree + -- sort_function = function (a,b) + -- if a.type == b.type then + -- return a.path > b.path + -- else + -- return a.type > b.type + -- end + -- end , -- this sorts files and directories descendantly + default_component_configs = { + container = { + enable_character_fade = true + }, + indent = { + indent_size = 2, + padding = 1, -- extra padding on left hand side + -- indent guides + with_markers = true, + indent_marker = "│", + last_indent_marker = "└", + highlight = "NeoTreeIndentMarker", + -- expander config, needed for nesting files + with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", + }, + icon = { + folder_closed = "", + folder_open = "", + folder_empty = "ﰊ", + -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there + -- then these will never be used. + default = "*", + highlight = "NeoTreeFileIcon" + }, + modified = { + symbol = "[+]", + highlight = "NeoTreeModified", + }, + name = { + trailing_slash = false, + use_git_status_colors = true, + highlight = "NeoTreeFileName", + }, + git_status = { + symbols = { + -- Change type + added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name + modified = "", -- or "", but this is redundant info if you use git_status_colors on the name + deleted = "✖",-- this can only be used in the git_status source + renamed = "",-- this can only be used in the git_status source + -- Status type + untracked = "", + ignored = "", + unstaged = "", + staged = "", + conflict = "", + } + }, + }, + window = { + position = "left", + width = 40, + mapping_options = { + noremap = true, + nowait = true, + }, + mappings = { + [""] = { + "toggle_node", + nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use + }, + ["<2-LeftMouse>"] = "open", + [""] = "open", + ["S"] = "open_split", + ["s"] = "open_vsplit", + -- ["S"] = "split_with_window_picker", + -- ["s"] = "vsplit_with_window_picker", + ["t"] = "open_tabnew", + ["w"] = "open_with_window_picker", + ["C"] = "close_node", + ["z"] = "close_all_nodes", + --["Z"] = "expand_all_nodes", + ["a"] = { + "add", + -- some commands may take optional config options, see `:h neo-tree-mappings` for details + config = { + show_path = "none" -- "none", "relative", "absolute" + } + }, + ["A"] = "add_directory", -- also accepts the optional config.show_path option like "add". + ["d"] = "delete", + ["r"] = "rename", + ["y"] = "copy_to_clipboard", + ["x"] = "cut_to_clipboard", + ["p"] = "paste_from_clipboard", + ["c"] = "copy", -- takes text input for destination, also accepts the optional config.show_path option like "add": + -- ["c"] = { + -- "copy", + -- config = { + -- show_path = "none" -- "none", "relative", "absolute" + -- } + --} + ["m"] = "move", -- takes text input for destination, also accepts the optional config.show_path option like "add". + ["q"] = "close_window", + ["R"] = "refresh", + ["?"] = "show_help", + ["<"] = "prev_source", + [">"] = "next_source", + } + }, + nesting_rules = {}, + filesystem = { + filtered_items = { + visible = false, -- when true, they will just be displayed differently than normal items + hide_dotfiles = true, + hide_gitignored = true, + hide_hidden = true, -- only works on Windows for hidden files/directories + hide_by_name = { + --"node_modules" + }, + hide_by_pattern = { -- uses glob style patterns + --"*.meta" + }, + never_show = { -- remains hidden even if visible is toggled to true + --".DS_Store", + --"thumbs.db" + }, + }, + follow_current_file = false, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = false, -- when true, empty folders will be grouped together + hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree + -- in whatever position is specified in window.position + -- "open_current", -- netrw disabled, opening a directory opens within the + -- window like netrw would, regardless of window.position + -- "disabled", -- netrw left alone, neo-tree does not handle opening dirs + use_libuv_file_watcher = false, -- This will use the OS level file watchers to detect changes + -- instead of relying on nvim autocmd events. + window = { + mappings = { + [""] = "navigate_up", + ["."] = "set_root", + ["H"] = "toggle_hidden", + ["/"] = "fuzzy_finder", + ["D"] = "fuzzy_finder_directory", + ["f"] = "filter_on_submit", + [""] = "clear_filter", + ["[g"] = "prev_git_modified", + ["]g"] = "next_git_modified", + } + } + }, + buffers = { + follow_current_file = true, -- This will find and focus the file in the active buffer every + -- time the current file is changed while the tree is open. + group_empty_dirs = true, -- when true, empty folders will be grouped together + show_unloaded = true, + window = { + mappings = { + ["bd"] = "buffer_delete", + [""] = "navigate_up", + ["."] = "set_root", + } + }, + }, + git_status = { + window = { + position = "float", + mappings = { + ["A"] = "git_add_all", + ["gu"] = "git_unstage_file", + ["ga"] = "git_add_file", + ["gr"] = "git_revert_file", + ["gc"] = "git_commit", + ["gp"] = "git_push", + ["gg"] = "git_commit_and_push", + } + } + } +}) + +vim.api.nvim_set_keymap('n', '', 'Neotree toggle', { noremap = true }) diff --git a/.config/nvim/lua/config/php-doc.lua b/.config/nvim/lua/config/php-doc.lua new file mode 100644 index 0000000..7bfee69 --- /dev/null +++ b/.config/nvim/lua/config/php-doc.lua @@ -0,0 +1,7 @@ +vim.keymap.set('n', '', function () + if vim.bo.filetype ~= 'php' then + return + end + + vim.api.nvim_call_function("PhpDocSingle", {}) +end, options) diff --git a/.config/nvim/lua/config/telescope.lua b/.config/nvim/lua/config/telescope.lua new file mode 100644 index 0000000..c196e97 --- /dev/null +++ b/.config/nvim/lua/config/telescope.lua @@ -0,0 +1,71 @@ +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local previewers = require("telescope.previewers") +local action_state = require("telescope.actions.state") +local conf = require("telescope.config").values +local actions = require("telescope.actions") + +require("telescope").setup({ + defaults = { + file_sorter = require("telescope.sorters").get_fzy_sorter, + prompt_prefix = " >", + color_devicons = true, + + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + + mappings = { + i = { + [""] = false, + [""] = actions.send_to_qflist, + }, + }, + }, +}) + +local M = {} + +function git_branches () + require("telescope.builtin").git_branches({ + attach_mappings = function(_, map) + map("i", "", actions.git_delete_branch) + map("n", "", actions.git_delete_branch) + return true + end, + }) +end + +local options = { noremap = true } + +-- vim.keymap.set('n', '', function() +-- local term = vim.fn.input("Grep For > ") +-- if term == '' then +-- return +-- end +-- require('telescope.builtin').grep_string({ search = term }) +-- end, options) + +vim.keymap.set('n', '', require('telescope.builtin').live_grep, options) + +vim.keymap.set('n', '', function() + local ran, errorMessage = pcall(function() + require('telescope.builtin').git_files({ show_untracked = true }) + end) + if not ran then + require('telescope.builtin').find_files() + end +end, options) + +-- vim.keymap.set('n', '', function() +-- end, options) + +vim.keymap.set('n', 'fb', require('telescope.builtin').buffers, options) +vim.keymap.set('n', 'fo', require('telescope.builtin').oldfiles, options) +vim.keymap.set('n', 'gr', require('telescope.builtin').lsp_references, options) + +vim.keymap.set('n', 'm', require('telescope.builtin').marks, options) +vim.keymap.set('n', 'ch', require('telescope.builtin').command_history, options) + +vim.keymap.set('n', 'gb', git_branches, options) +vim.keymap.set('n', 'gs', require('telescope.builtin').git_status, options) diff --git a/.config/nvim/lua/config/tmux.lua b/.config/nvim/lua/config/tmux.lua new file mode 100644 index 0000000..da0ec7e --- /dev/null +++ b/.config/nvim/lua/config/tmux.lua @@ -0,0 +1,17 @@ +require("tmux").setup({ + -- overwrite default configuration + -- here, e.g. to enable default bindings + copy_sync = { + -- enables copy sync and overwrites all register actions to + -- sync registers *, +, unnamed, and 0 till 9 from tmux in advance + enable = true, + }, + navigation = { + -- enables default keybindings (C-hjkl) for normal mode + enable_default_keybindings = true, + }, + resize = { + -- enables default keybindings (A-hjkl) for normal mode + enable_default_keybindings = true, + } + }) diff --git a/.config/nvim/lua/config/treesitter.lua b/.config/nvim/lua/config/treesitter.lua new file mode 100644 index 0000000..2ebecc2 --- /dev/null +++ b/.config/nvim/lua/config/treesitter.lua @@ -0,0 +1,25 @@ +require('nvim-treesitter.configs').setup { + -- A list of parser names, or "all" + ensure_installed = { 'go', 'dart', 'php', 'javascript' }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + auto_install = true, + + indent = { + enable = true, + }, + + highlight = { + -- `false` will disable the whole extension + enable = true, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +} diff --git a/.config/nvim/lua/helper/toggle-tab-width.lua b/.config/nvim/lua/helper/toggle-tab-width.lua new file mode 100644 index 0000000..ff702a9 --- /dev/null +++ b/.config/nvim/lua/helper/toggle-tab-width.lua @@ -0,0 +1,19 @@ +local tabWidth = 4 + +function ToggleTabWidth() + if tabWidth == 2 then + vim.o.tabstop = 4 + vim.o.softtabstop = 4 + vim.o.shiftwidth = 4 + tabWidth = 4 + print('Set tab width to 4') + return + end + vim.o.tabstop = 2 + vim.o.softtabstop = 2 + vim.o.shiftwidth = 2 + tabWidth = 2 + print('Set tab width to 2') +end + +vim.keymap.set('n', 't', ToggleTabWidth, { noremap = true}) diff --git a/.config/nvim/lua/packer-plugins.lua b/.config/nvim/lua/packer-plugins.lua new file mode 100644 index 0000000..b486d9a --- /dev/null +++ b/.config/nvim/lua/packer-plugins.lua @@ -0,0 +1,143 @@ +return require('packer').startup(function() + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + -- colorschemes + use 'gruvbox-community/gruvbox' + use 'bluz71/vim-moonfly-colors' + + use { 'neoclide/coc.nvim', run = 'yarn install', disable = true } + + use { "williamboman/nvim-lsp-installer" } + + use { 'SirVer/ultisnips' } + + use { + "neovim/nvim-lspconfig", + event = "BufReadPre", + wants = { "cmp-nvim-lsp", "nvim-lsp-installer", "lsp_signature.nvim" }, + config = function() + require("config.lsp").setup() + end, + requires = { + "williamboman/nvim-lsp-installer", + "ray-x/lsp_signature.nvim", + }, + } + + use { + "ray-x/lsp_signature.nvim", + } + + use { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + requires = { + { "hrsh7th/cmp-nvim-lsp", after = "nvim-cmp" }, + { "f3fora/cmp-spell", after = "nvim-cmp" }, + { "hrsh7th/cmp-path", after = "nvim-cmp" }, + { "hrsh7th/cmp-buffer", after = "nvim-cmp" }, + { "hrsh7th/cmp-calc", after = "nvim-cmp" }, + { "quangnguyen30192/cmp-nvim-ultisnips", after = "nvim-cmp" }, + { + "L3MON4D3/LuaSnip", + -- after = 'nvim-cmp', + wants = "friendly-snippets", + requires = { + { "rafamadriz/friendly-snippets", after = 'nvim-cmp' }, + }, + config = function() + require("config.luasnip").setup() + end, + }, + + }, + config = function() + require("config.cmp").setup() + end, + disable = false, + } + + use 'nvim-lua/popup.nvim' + use 'nvim-lua/plenary.nvim' + use { + 'nvim-telescope/telescope.nvim', + config = function() + require('config.telescope') + end + } + use 'nvim-telescope/telescope-fzy-native.nvim' + + use { + 'Rican7/php-doc-modded', + config = function() + require('config.php-doc') + end + } + + use 'dart-lang/dart-vim-plugin' + + use { 'nvim-treesitter/nvim-treesitter' } + + use { + 'romgrk/barbar.nvim', + requires = {'kyazdani42/nvim-web-devicons'}, + config = function() + require('config.barbar') + end + } + + use { + 'lewis6991/gitsigns.nvim', + config = function() + require('config.gitsigns') + end + } + + use { + 'nvim-lualine/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons', opt = true }, + config = function() + require('config.lualine') + end + } + + use { + 'ray-x/go.nvim', + config = function() + require('config.go') + end + } + use {'ray-x/guihua.lua', run = 'cd lua/fzy && make'} + + use { + 'aserowy/tmux.nvim', + config = function () + require('config.tmux') + end + } + + use { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + requires = { + "nvim-lua/plenary.nvim", + "kyazdani42/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + config = function () + require('config.nvim-neo-tree') + end + } + + use { + "startup-nvim/startup.nvim", + requires = {"nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"}, + config = function() + require"startup".setup() + end + } + + -- Local nvim plugin development + -- use '~/Software/nvim-phpdoc/phpdoc.nvim' +end) diff --git a/.config/nvim/lua/utils/init.lua b/.config/nvim/lua/utils/init.lua new file mode 100644 index 0000000..03897f8 --- /dev/null +++ b/.config/nvim/lua/utils/init.lua @@ -0,0 +1,37 @@ +_G.dump = function(...) + print(vim.inspect(...)) +end + +_G.prequire = function(...) + local status, lib = pcall(require, ...) + if status then + return lib + end + return nil +end + +local M = {} + +function M.t(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +function M.log(msg, hl, name) + name = name or "Neovim" + hl = hl or "Todo" + vim.api.nvim_echo({ { name .. ": ", hl }, { msg } }, true, {}) +end + +function M.warn(msg, name) + vim.notify(msg, vim.log.levels.WARN, { title = name }) +end + +function M.error(msg, name) + vim.notify(msg, vim.log.levels.ERROR, { title = name }) +end + +function M.info(msg, name) + vim.notify(msg, vim.log.levels.INFO, { title = name }) +end + +return M