diff --git a/README.md b/README.md index a5f29f3..6334370 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,71 @@ +# nvim-config + ## Introduction -This project is a fork of [dam9000/kickstart-modular.nvim](https://github.com/dam9000/kickstart-modular.nvim.git) +*This is a fork of [dam9000/kickstart-modular.nvim](https://github.com/dam9000/kickstart-modular.nvim) that represents my personal configuration of Neovim.* +## Installation -### Installation (Windows Only) +### Install Neovim + +Kickstart.nvim targets *only* the latest +['stable'](https://github.com/neovim/neovim/releases/tag/stable) and latest +['nightly'](https://github.com/neovim/neovim/releases/tag/nightly) of Neovim. +If you are experiencing issues, please make sure you have the latest versions. + +### Install External Dependencies > **NOTE** > [Backup](#FAQ) your previous configuration (if any exists) -Neovim's configurations are located under the following path: +External Requirements: +- Basic utils: `git`, `make`, `unzip`, C Compiler (`gcc`) +- [ripgrep](https://github.com/BurntSushi/ripgrep#installation) +- A [Nerd Font](https://www.nerdfonts.com/): optional, provides various icons + - if you have it set `vim.g.have_nerd_font` in `init.lua` to true +- Language Setup: + - If want to write Typescript, you need `npm` + - If want to write Golang, you will need `go` + - etc. -| Shell | PATH | +> **NOTE** +> See [Windows Installation](#Windows-Installation) to double check any additional Windows notes + +Neovim's configurations are located under the following paths, depending on your OS: + +| OS | PATH | | :- | :--- | -| cmd | `%userprofile%\AppData\Local\nvim\` | -| powershell | `$env:USERPROFILE\AppData\Local\nvim\` | +| Linux, MacOS | `$XDG_CONFIG_HOME/nvim`, `~/.config/nvim` | +| Windows (cmd)| `%userprofile%\AppData\Local\nvim\` | +| Windows (powershell)| `$env:USERPROFILE\AppData\Local\nvim\` | -- Download and install: - - [ripgrep](https://github.com/BurntSushi/ripgrep#installation) - - [MinGW](https://www.mingw-w64.org/) - > **NOTE** - > In this case, using [chocolatey](https://chocolatey.org/) is quick and easy - - [CMake](https://cmake.org/) - > **NOTE** - > Make sure to select 'add to PATH' during installation - - [MSBuild-Tools](https://github.com/bycloudai/InstallVSBuildToolsWindows) -- Clone this repository: - - on Windows (cmd) - ``` - git clone https://github.com/Baipyrus/nvim-config.git %userprofile%\AppData\Local\nvim\ - ``` +### Install this Configuration - - on Windows (powershell) - ``` - git clone https://github.com/Baipyrus/nvim-config.git $env:USERPROFILE\AppData\Local\nvim\ - ``` +Clone it from GitHub: +
Linux and Mac + +```sh +git clone https://github.com/dam9000/kickstart-modular.nvim.git "${XDG_CONFIG_HOME:-$HOME/.config}"/nvim +``` + +
+ +
Windows + +If you're using `cmd.exe`: + +```bat +git clone https://github.com/Baipyrus/nvim-config.git %userprofile%\AppData\Local\nvim\ +``` + +If you're using `powershell.exe` + +```pwsh +git clone https://github.com/Baipyrus/nvim-config.git $env:USERPROFILE\AppData\Local\nvim\ +``` + +
### Post Installation @@ -44,32 +75,43 @@ Start Neovim nvim ``` -The `Lazy` plugin manager will start automatically on the first run and install the configured plugins. After the installation is complete you can press `q` to close the `Lazy` UI and **you are ready to go**! Next time you run nvim `Lazy` will no longer show up. - -If you would prefer to hide this step and run the plugin sync from the command line, you can use: - -```sh -nvim --headless "+Lazy! sync" +qa -``` - +That's it! Lazy will install all the plugins you have. Use `:Lazy` to view +current plugin status. ### FAQ * What should I do if I already have a pre-existing neovim configuration? * You should back it up, then delete all files associated with it. - * This includes your existing init.lua and the neovim files in `%userprofile%\AppData\Local\nvim-data\` (CMD) or `$env:USERPROFILE\AppData\Local\nvim-data\` (Powershell) which should be deleted afterwards. - * You may also want to look at the [migration guide for lazy.nvim](https://github.com/folke/lazy.nvim#-migration-guide) + * This includes your existing init.lua and the neovim files in `~/.local` which can be deleted with `rm -rf ~/.local/share/nvim/` or their windows counterparts in `AppData\Local\nvim-data` +* Can I keep my existing configuration in parallel to kickstart? + * Yes! You can use [NVIM_APPNAME](https://neovim.io/doc/user/starting.html#%24NVIM_APPNAME)`=nvim-NAME` to maintain multiple configurations. For example you can install the kickstart configuration in `~/.config/nvim-kickstart` and create an alias: + ```sh + alias nvim-kickstart='NVIM_APPNAME="nvim-kickstart" nvim' + ``` + When you run Neovim using `nvim-kickstart` alias it will use the alternative config directory and the matching local directory `~/.local/share/nvim-kickstart`. + You could also run your configuration inline, for example in Windows Powershell: + ```pwsh + $env:NVIM_APPNAME = 'nvim-kickstart'; nvim + ``` * What if I want to "uninstall" this configuration: * See [lazy.nvim uninstall](https://github.com/folke/lazy.nvim#-uninstalling) information -* Why is the kickstart `init.lua` a single file? Wouldn't it make sense to split it into multiple files? - * The main purpose of kickstart is to serve as a teaching tool and a reference - configuration that someone can easily `git clone` as a basis for their own. - As you progress in learning Neovim and Lua, you might consider splitting `init.lua` - into smaller parts. *This is the fork of the original project that splits the configuration into smaller parts.* - The original repo that maintains the exact - same functionality in a single `init.lua` file is available here: - * [kickstart.nvim](https://github.com/dam9000/kickstart-modular.nvim) - * Discussions on this topic can be found here: - * [Restructure the configuration](https://github.com/nvim-lua/kickstart.nvim/issues/218) - * [Reorganize init.lua into a multi-file setup](https://github.com/nvim-lua/kickstart.nvim/pull/473) +### Windows Installation + +Installation requires gcc and make, for which you don't need to change the config, +the easiest way is to use choco: + +1. install [chocolatey](https://chocolatey.org/install) +either follow the instructions on the page or use winget, +run in cmd as **admin**: +``` +winget install --accept-source-agreements chocolatey.chocolatey +``` + +2. install all requirements using choco, exit previous cmd and +open a new one so that choco path is set, run in cmd as **admin**: +``` +choco install -y neovim git ripgrep wget fd unzip gzip mingw make +``` + +Then continue with the [Install Kickstart](#Install-this-Configuration) step. diff --git a/init.lua b/init.lua index c92a770..3ed4ea3 100644 --- a/init.lua +++ b/init.lua @@ -3,6 +3,9 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' +-- Set to true if you have a Nerd Font installed +vim.g.have_nerd_font = true + -- [[ Setting options ]] require 'options' diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 4112b1c..7658267 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -12,13 +12,11 @@ vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagn vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier --- for people to discover. Otherwise, you normally need to press , which --- is not what someone will guess without a bit more experience. --- --- 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' }) +-- Open terminal in current window +vim.keymap.set({ 'n', 'v' }, 'to', 'term', { desc = '[T]erminal [O]pen' }) + -- Disable arrow keys in normal mode vim.keymap.set({ 'n', 'v' }, '', 'echo "Use h to move!!"') vim.keymap.set({ 'n', 'v' }, '', 'echo "Use l to move!!"') @@ -42,11 +40,11 @@ vim.keymap.set('v', 'pny', '"_dP', { desc = '[P]aste [N]o [Y]ank' }) -- Populate CMD to prepare for change directory vim.keymap.set('n', 'cd', ':cd ', { desc = 'Prepare CMD for [C]hange [D]irectory' }) --- Open git window from fugitive in full screen -vim.keymap.set({ 'n', 'v' }, 'go', ':Gito', { desc = '[G]it [O]pen' }) +-- Switch in fugitive.vim status window with the current one +vim.keymap.set('n', 'gs', 'Gedit :', { desc = '[G]it [S]tatus' }) -- [[ Basic Autocommands ]] --- See :help lua-guide-autocommands +-- See `:help lua-guide-autocommands` -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode diff --git a/lua/kickstart/health.lua b/lua/kickstart/health.lua index ee375bb..04df77b 100644 --- a/lua/kickstart/health.lua +++ b/lua/kickstart/health.lua @@ -6,21 +6,22 @@ --]] local check_version = function() + local verstr = string.format('%s.%s.%s', vim.version().major, vim.version().minor, vim.version().patch) if not vim.version.cmp then - vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", tostring(vim.version()))) + vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) return end if vim.version.cmp(vim.version(), { 0, 9, 4 }) >= 0 then - vim.health.ok(string.format("Neovim version is: '%s'", tostring(vim.version()))) + vim.health.ok(string.format("Neovim version is: '%s'", verstr)) else - vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", tostring(vim.version()))) + vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) end end local check_external_reqs = function() -- Basic utils: `git`, `make`, `unzip` - for _, exe in ipairs { 'git', 'cmake', 'rg' } do + for _, exe in ipairs { 'git', 'make', 'unzip', 'rg' } do local is_executable = vim.fn.executable(exe) == 1 if is_executable then vim.health.ok(string.format("Found executable: '%s'", exe)) diff --git a/lua/kickstart/plugins/cmp.lua b/lua/kickstart/plugins/cmp.lua index 10433a8..e3c26f1 100644 --- a/lua/kickstart/plugins/cmp.lua +++ b/lua/kickstart/plugins/cmp.lua @@ -10,10 +10,10 @@ return { -- Build Step is needed for regex support in snippets -- This step is not supported in many windows environments -- Remove the below condition to re-enable on windows - if vim.fn.has 'win32' == 1 or vim.fn.executable 'cmake' == 0 then + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then return end - return 'cmake install_jsregexp' + return 'make install_jsregexp' end)(), }, 'saadparwaiz1/cmp_luasnip', diff --git a/lua/kickstart/plugins/lspconfig.lua b/lua/kickstart/plugins/lspconfig.lua index fedccd7..441ab6d 100644 --- a/lua/kickstart/plugins/lspconfig.lua +++ b/lua/kickstart/plugins/lspconfig.lua @@ -35,7 +35,7 @@ return { -- Neovim. This is where `mason` and related plugins come into play. -- -- If you're wondering about lsp vs treesitter, you can check out the wonderfully - -- and elegantly composed help section, :help lsp-vs-treesitter + -- and elegantly composed help section, `:help lsp-vs-treesitter` -- This function gets run when an LSP attaches to a particular buffer. -- That is to say, every time a new file is opened that is associated with @@ -165,6 +165,9 @@ return { -- library = { vim.env.VIMRUNTIME }, }, telemetry = { enable = false }, + completion = { + callSnippet = 'Replace', + }, -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings -- diagnostics = { disable = { 'missing-fields' } }, }, @@ -196,15 +199,11 @@ return { handlers = { function(server_name) local server = servers[server_name] or {} - require('lspconfig')[server_name].setup { - cmd = server.cmd, - settings = server.settings, - filetypes = server.filetypes, - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for tsserver) - capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}), - } + -- This handles overriding only values explicitly passed + -- by the server configuration above. Useful when disabling + -- certain features of an LSP (for example, turning off formatting for tsserver) + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + require('lspconfig')[server_name].setup(server) end, }, } diff --git a/lua/kickstart/plugins/mini.lua b/lua/kickstart/plugins/mini.lua index 87a312a..3e924a8 100644 --- a/lua/kickstart/plugins/mini.lua +++ b/lua/kickstart/plugins/mini.lua @@ -5,7 +5,7 @@ return { -- Better Around/Inside textobjects -- -- Examples: - -- - va) - [V]isually select [A]round [)]parenthen + -- - va) - [V]isually select [A]round [)]paren -- - yinq - [Y]ank [I]nside [N]ext [']quote -- - ci' - [C]hange [I]nside [']quote require('mini.ai').setup { n_lines = 500 } @@ -20,8 +20,15 @@ return { -- Simple and easy statusline. -- You could remove this setup call if you don't like it, -- and try some other statusline plugin - require('mini.statusline').setup() - MiniStatusline.section_location = function() + local statusline = require 'mini.statusline' + -- set use_icons to true if you have a Nerd Font + statusline.setup { use_icons = vim.g.have_nerd_font } + + -- You can configure sections in the statusline by overriding their + -- default behavior. For example, here we set the section for + -- cursor location to LINE:COLUMN + ---@diagnostic disable-next-line: duplicate-set-field + statusline.section_location = function() return '%2l:%-2v' end diff --git a/lua/kickstart/plugins/telescope.lua b/lua/kickstart/plugins/telescope.lua index 9e1c8dc..b187eb9 100644 --- a/lua/kickstart/plugins/telescope.lua +++ b/lua/kickstart/plugins/telescope.lua @@ -8,7 +8,7 @@ return { { -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', - event = 'VeryLazy', + event = 'VimEnter', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', @@ -17,20 +17,18 @@ return { -- `build` is used to run some command when the plugin is installed/updated. -- This is only run then, not every time Neovim starts up. - build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release; cmake --build build --config Release; cmake --install build --prefix build', + build = 'make', -- `cond` is a condition used to determine whether this plugin should be -- installed and loaded. cond = function() - return vim.fn.executable 'cmake' == 1 + return vim.fn.executable 'make' == 1 end, }, { 'nvim-telescope/telescope-ui-select.nvim' }, - -- Useful for getting pretty icons, but requires special font. - -- If you already have a Nerd Font, or terminal set up with fallback fonts - -- you can enable this - { 'nvim-tree/nvim-web-devicons' }, + -- Useful for getting pretty icons, but requires a 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 diff --git a/lua/kickstart/plugins/todo-comments.lua b/lua/kickstart/plugins/todo-comments.lua index c4c7764..407e821 100644 --- a/lua/kickstart/plugins/todo-comments.lua +++ b/lua/kickstart/plugins/todo-comments.lua @@ -1,5 +1,5 @@ -- Highlight todo, notes, etc in comments return { - { 'folke/todo-comments.nvim', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, + { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, } -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/kickstart/plugins/tokyonight.lua b/lua/kickstart/plugins/tokyonight.lua index 4ce6fe7..cc5192a 100644 --- a/lua/kickstart/plugins/tokyonight.lua +++ b/lua/kickstart/plugins/tokyonight.lua @@ -8,7 +8,9 @@ return { lazy = false, -- make sure we load this during startup if it is your main colorscheme priority = 1000, -- make sure to load this before all the other start plugins config = function() - -- Load the colorscheme here + -- Load the colorscheme here. + -- Like many other themes, this one has different styles, and you could load + -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. vim.cmd.colorscheme 'tokyonight-night' -- You can configure highlights by doing something like diff --git a/lua/kickstart/plugins/treesitter.lua b/lua/kickstart/plugins/treesitter.lua index 9118f1e..0798fe4 100644 --- a/lua/kickstart/plugins/treesitter.lua +++ b/lua/kickstart/plugins/treesitter.lua @@ -3,6 +3,7 @@ return { { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', dependencies = { + 'windwp/nvim-ts-autotag', 'nvim-treesitter/nvim-treesitter-context', 'nvim-treesitter/nvim-treesitter-textobjects', }, @@ -15,6 +16,11 @@ return { ensure_installed = { 'lua', 'python', 'rust', 'javascript', 'typescript', 'vimdoc', 'vim', 'svelte', 'c_sharp' }, -- Autoinstall languages that are not installed auto_install = false, + -- Enable autotags and -rename + autotag = { + enable = true, + enable_autocmd = true, + }, -- Install languages synchronously (only applied to `ensure_installed`) sync_install = false, highlight = { enable = true }, diff --git a/lua/kickstart/plugins/which-key.lua b/lua/kickstart/plugins/which-key.lua index 38a1337..a0e9d82 100644 --- a/lua/kickstart/plugins/which-key.lua +++ b/lua/kickstart/plugins/which-key.lua @@ -4,10 +4,10 @@ -- lazy loading plugins that don't need to be loaded immediately at startup. -- -- For example, in the following configuration, we use: --- event = 'VeryLazy' +-- event = 'VimEnter' -- --- which loads which-key after all the UI elements are loaded. Events can be --- normal autocommands events (:help autocomd-events). +-- which loads which-key before all the UI elements are loaded. Events can be +-- normal autocommands events (`:help autocmd-events`). -- -- Then, because we use the `config` key, the configuration only runs -- after the plugin has been loaded: @@ -16,7 +16,7 @@ return { { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', - event = 'VeryLazy', -- Sets the loading event to 'VeryLazy' + event = 'VimEnter', -- Sets the loading event to 'VimEnter' config = function() -- This is the function that runs, AFTER loading require('which-key').setup() diff --git a/lua/lazy-plugins.lua b/lua/lazy-plugins.lua index d03ab98..d8df4b3 100644 --- a/lua/lazy-plugins.lua +++ b/lua/lazy-plugins.lua @@ -9,8 +9,7 @@ -- :Lazy update -- -- NOTE: Here is where you install your plugins. -require('lazy').setup { - +require('lazy').setup({ -- [[ Plugin Specs list ]] -- NOTE: First, some plugins that don't require any configuration @@ -27,6 +26,34 @@ require('lazy').setup { -- Processing-Java 'sophacles/vim-processing', + -- Smooth scroll plugin and keymaps + { + 'karb94/neoscroll.nvim', + config = function() + require('neoscroll').setup { + hide_cursor = false, + easing_function = nil, + respect_scrolloff = true, + } + + require('neoscroll.config').set_mappings { + -- Scroll normally + [''] = { 'scroll', { '-vim.wo.scroll', 'true', '50' } }, + [''] = { 'scroll', { 'vim.wo.scroll', 'true', '50' } }, + -- Scroll entire page height + [''] = { 'scroll', { '-vim.api.nvim_win_get_height(0)', 'true', '80' } }, + [''] = { 'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '80' } }, + -- Scroll 10% at a time + [''] = { 'scroll', { '-0.10', 'false', '25' } }, + [''] = { 'scroll', { '0.10', 'false', '25' } }, + -- Jump to top, bottom and center + ['zt'] = { 'zt', { '40' } }, + ['zz'] = { 'zz', { '50' } }, + ['zb'] = { 'zb', { '40' } }, + } + end, + }, + -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically @@ -84,8 +111,28 @@ require('lazy').setup { -- 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 + -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` { import = 'custom.plugins' }, -} +}, { + ui = { + -- If you have a Nerd Font, set icons to an empty table which will use the + -- default lazy.nvim defined Nerd Font icons otherwise define a unicode icons table + icons = vim.g.have_nerd_font and {} or { + cmd = 'โŒ˜', + config = '๐Ÿ› ', + event = '๐Ÿ“…', + ft = '๐Ÿ“‚', + init = 'โš™', + keys = '๐Ÿ—', + plugin = '๐Ÿ”Œ', + runtime = '๐Ÿ’ป', + require = '๐ŸŒ™', + source = '๐Ÿ“„', + start = '๐Ÿš€', + task = '๐Ÿ“Œ', + lazy = '๐Ÿ’ค ', + }, + }, +}) -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/options.lua b/lua/options.lua index 8149d80..e70dd0d 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -62,8 +62,8 @@ vim.opt.splitright = true vim.opt.splitbelow = true -- Sets how neovim will display certain whitespace in the editor. --- See :help 'list' --- and :help 'listchars' +-- See `:help 'list'` +-- and `:help 'listchars'` vim.opt.list = true vim.opt.listchars = { tab = 'ยป ', @@ -77,7 +77,8 @@ vim.opt.inccommand = 'split' -- Show which line your cursor is on vim.opt.cursorline = true --- Minimal number of screen lines to keep above and below the cursor. +-- Minimal spacing to keep around the cursor. vim.opt.scrolloff = 8 +vim.opt.sidescrolloff = 12 -- vim: ts=2 sts=2 sw=2 et