From e4c92f22b02622aa7936462e33597e9b23c52f1d Mon Sep 17 00:00:00 2001 From: Paul Murray Date: Wed, 17 Apr 2024 23:18:47 +1000 Subject: [PATCH] dart up and going --- init.lua | 120 +++++++++++++++++++++------ lua/custom/plugins/autopairs.lua | 17 ++++ lua/custom/plugins/filetree.lua | 81 ++++++++++++++++++ lua/custom/plugins/flutter-tools.lua | 9 ++ lua/custom/plugins/init.lua | 3 +- 5 files changed, 203 insertions(+), 27 deletions(-) create mode 100644 lua/custom/plugins/autopairs.lua create mode 100644 lua/custom/plugins/filetree.lua create mode 100644 lua/custom/plugins/flutter-tools.lua diff --git a/init.lua b/init.lua index 496f45b8..fb2bbd87 100644 --- a/init.lua +++ b/init.lua @@ -44,7 +44,6 @@ What is Kickstart? Kickstart Guide: TODO: The very first thing you should do is to run the command `:Tutor` in Neovim. - If you don't know what this means, type the following: - - : @@ -83,7 +82,11 @@ I hope you enjoy your Neovim journey, P.S. You can delete this when you're done too. It's your config now! :) --]] +-- Make the background inherit from the terminal +vim.opt.termguicolors = true +-- Make the line length 79 +vim.opt.textwidth = 79 -- Set as the leader key -- See `:help mapleader` -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) @@ -91,18 +94,17 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` -- NOTE: You can change these options as you wish! -- For more options, you can see `:help option-list` - -- Make line numbers default vim.opt.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' @@ -110,6 +112,7 @@ vim.opt.mouse = 'a' -- Don't show the mode, since it's already in the status line vim.opt.showmode = false + -- Sync clipboard between OS and Neovim. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` @@ -151,11 +154,16 @@ vim.opt.inccommand = 'split' -- Show which line your cursor is on vim.opt.cursorline = true +-- Make cursor block size always +vim.opt.guicursor = "" + -- Minimal number of screen lines to keep above and below the cursor. vim.opt.scrolloff = 10 -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` +vim.keymap.set('n', '+', 'w', { desc = 'Save' }) +vim.keymap.set('n', 'x', 'confirm q', { desc = 'Quit Window' }) -- Set highlight on search, but clear on pressing in normal mode vim.opt.hlsearch = true @@ -171,15 +179,39 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagn -- for people to discover. Otherwise, you normally need to press , which -- is not what someone will guess without a bit more experience. -- +-- Neo-tree keymaps +vim.keymap.set('n', 'n', 'Neotree toggle', { desc = 'open neo-tree' }) +vim.keymap.set('n', '-', function() + local reveal_file = vim.fn.expand('%:p') + if (reveal_file == '') then + reveal_file = vim.fn.getcwd() + else + local f = io.open(reveal_file, "r") + if (f) then + f.close(f) + else + reveal_file = vim.fn.getcwd() + end + end + require('neo-tree.command').execute({ + action = "focus", -- OPTIONAL, this is the default value + source = "filesystem", -- OPTIONAL, this is the default value + position = "left", -- OPTIONAL, this is the default value + reveal_file = reveal_file, -- path to file or folder to reveal + reveal_force_cwd = true, -- change cwd without asking if needed + }) + end, + { desc = "Open neo-tree at current file or working directory" } +); -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping -- or just use to exit terminal mode vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) -- TIP: Disable arrow keys in normal mode --- vim.keymap.set('n', '', 'echo "Use h to move!!"') --- vim.keymap.set('n', '', 'echo "Use l to move!!"') --- vim.keymap.set('n', '', 'echo "Use k to move!!"') --- vim.keymap.set('n', '', 'echo "Use j to move!!"') +vim.keymap.set('n', '', 'echo "Use h to move!!"') +vim.keymap.set('n', '', 'echo "Use l to move!!"') +vim.keymap.set('n', '', 'echo "Use k to move!!"') +vim.keymap.set('n', '', 'echo "Use j to move!!"') -- Keybinds to make split navigation easier. -- Use CTRL+ to switch between windows @@ -238,7 +270,7 @@ require('lazy').setup({ -- require('Comment').setup({}) -- "gc" to comment visual regions/lines - { 'numToStr/Comment.nvim', opts = {} }, + { 'numToStr/Comment.nvim', opts = {} }, -- Here is a more advanced example where we pass configuration -- options to `gitsigns.nvim`. This is equivalent to the following Lua: @@ -273,7 +305,7 @@ require('lazy').setup({ -- after the plugin has been loaded: -- config = function() ... end - { -- Useful plugin to show you pending keybinds. + { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' config = function() -- This is the function that runs, AFTER loading @@ -319,7 +351,7 @@ require('lazy').setup({ { 'nvim-telescope/telescope-ui-select.nvim' }, -- Useful for getting pretty icons, but requires a Nerd Font. - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, config = function() -- Telescope is a fuzzy finder that comes with a lot of different things that @@ -415,10 +447,38 @@ require('lazy').setup({ { 'j-hui/fidget.nvim', opts = {} }, -- `neodev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis + -- usedt:for completion, annotations and signatures of Neovim apis { 'folke/neodev.nvim', opts = {} }, }, config = function() + local lsp_config = require("lspconfig") + local capabilities = require("cmp_nvim_lsp").default_capabilities() + + lsp_config["dartls"].setup({ + capabilities = capabilities, + cmd = { + "dart", + "language-server", + "--protocol=lsp", + -- "--port=8123", + -- "--instrumentation-log-file=/Users/robertbrunhage/Desktop/lsp-log.txt", + }, + filetypes = { "dart" }, + init_options = { + onlyAnalyzeProjectsWithOpenFiles = false, + suggestFromUnimportedLibraries = true, + closingLabels = true, + outline = false, + flutterOutline = false, + }, + settings = { + dart = { + updateImportsOnRename = true, + completeFunctionCalls = true, + showTodos = true, + }, + }, + }) -- Brief aside: **What is LSP?** -- -- LSP is an initialism you've probably heard, but might not understand what it is. @@ -539,8 +599,16 @@ require('lazy').setup({ -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { -- clangd = {}, - -- gopls = {}, - -- pyright = {}, + gopls = {}, + pyright = {}, + cssls = {}, + cssmodules_ls = {}, + docker_compose_language_service = {}, + dockerls = {}, + eslint = {}, + jsonls = {}, + tailwindcss = {}, + tsserver = {}, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -624,13 +692,13 @@ require('lazy').setup({ } end, formatters_by_ft = { - lua = { 'stylua' }, + -- lua = { 'stylua' }, -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- -- You can use a sub-list to tell conform to run *until* a formatter -- is found. - -- javascript = { { "prettierd", "prettier" } }, + javascript = { { "prettierd", "prettier" } }, }, }, }, @@ -655,12 +723,12 @@ require('lazy').setup({ -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, + { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, }, }, 'saadparwaiz1/cmp_luasnip', @@ -838,16 +906,16 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', + require 'kickstart.plugins.debug', + require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.lint', -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the diff --git a/lua/custom/plugins/autopairs.lua b/lua/custom/plugins/autopairs.lua new file mode 100644 index 00000000..06126b9b --- /dev/null +++ b/lua/custom/plugins/autopairs.lua @@ -0,0 +1,17 @@ +-- File: lua/custom/plugins/autopairs.lua + +return { + "windwp/nvim-autopairs", + -- Optional dependency + dependencies = { 'hrsh7th/nvim-cmp' }, + config = function() + require("nvim-autopairs").setup {} + -- If you want to automatically add `(` after selecting a function or method + local cmp_autopairs = require('nvim-autopairs.completion.cmp') + local cmp = require('cmp') + cmp.event:on( + 'confirm_done', + cmp_autopairs.on_confirm_done() + ) + end, +} diff --git a/lua/custom/plugins/filetree.lua b/lua/custom/plugins/filetree.lua new file mode 100644 index 00000000..a75eab95 --- /dev/null +++ b/lua/custom/plugins/filetree.lua @@ -0,0 +1,81 @@ +-- File: lua/custom/plugins/filetree.lua + +return { + "nvim-neo-tree/neo-tree.nvim", + version = "*", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + config = function() + require('neo-tree').setup { 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 = "", + } + }, + mappings = { + ["nt"] = { + "toggle_node", + nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use + }, + [""] = "open", + [""] = "cancel", -- close preview or floating neo-tree window + ["P"] = { "toggle_preview", config = { use_float = true, use_image_nvim = true } }, + -- Read `# Preview Mode` for more information + ["l"] = "focus_preview", + ["S"] = "open_split", + ["s"] = "open_vsplit", + -- ["S"] = "split_with_window_picker", + -- ["s"] = "vsplit_with_window_picker", + ["t"] = "open_tabnew", + -- [""] = "open_drop", + -- ["t"] = "open_tab_drop", + ["w"] = "open_with_window_picker", + --["P"] = "toggle_preview", -- enter preview mode, which shows the current node without focusing + ["C"] = "close_node", + -- ['C'] = 'close_all_subnodes', + ["z"] = "close_all_nodes", + --["Z"] = "expand_all_nodes", + ["a"] = { + "add", + -- this command supports BASH style brace expansion ("x{a,b,c}" -> xa,xb,xc). see `:h neo-tree-file-actions` for details + -- 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". this also supports BASH style brace expansion. + ["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", + ["i"] = "show_file_details", + } + } + end, +} diff --git a/lua/custom/plugins/flutter-tools.lua b/lua/custom/plugins/flutter-tools.lua new file mode 100644 index 00000000..5b4c43c7 --- /dev/null +++ b/lua/custom/plugins/flutter-tools.lua @@ -0,0 +1,9 @@ +return { + 'akinsho/flutter-tools.nvim', + lazy = false, + dependencies = { + 'nvim-lua/plenary.nvim', + 'stevearc/dressing.nvim', -- optional for vim.ui.select + }, + config = true, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d8..3adb89b1 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,4 +2,5 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -return {} +return { +}