Merge pull request #455 from NotAShelf/migrate-opts
Some checks are pending
Check for typos in the source tree / check-typos (push) Waiting to run

neovim/init: set basic options via `vim.options`
This commit is contained in:
raf 2024-12-01 18:45:55 +03:00 committed by GitHub
commit d17c010bf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 215 additions and 178 deletions

View file

@ -49,7 +49,7 @@ absence.
- Made Copilot's Node package configurable. It is recommended to keep as
default, but providing a different NodeJS version is now possible.
- Added [](#opt-vim.cursorlineOpt) for configuring Neovim's cursorlineOpt.
- Added `vim.cursorlineOpt` for configuring Neovim's `vim.o.cursorlineopt`.
- Added `filetree.nvimTreeLua.view.cursorline`, default false, to enable
cursorline in nvimtre.

View file

@ -91,6 +91,30 @@ default. This is to avoid conflicts with other modules. You can change
`maplocalleader` with `vim.globals.maplocalleader`, but it's recommended to set
it to something other than `mapleader` to avoid conflicts.
### `vim.*` changes {#sec-vim-opt-changes}
Inline with the [leader changes](#sec-leader-changes), we have removed some
options that were under `vim` as convenient shorthands for `vim.o.*` options.
::: {.warning}
As v0.7 features the addition of [](#opt-vim.options), those options are now
considered as deprecated. You should migrate to the appropriate options in the
`vim.options` submodule.
:::
The changes are, in no particular order:
- `colourTerm`, `mouseSupport`, `cmdHeight`, `updateTime`, `mapTime`,
`cursorlineOpt`, `splitBelow`, `splitRight`, `autoIndent` and `wordWrap` have
been mapped to their [](#opt-vim.options) equivalents. Please see the module
definition for the updated options.
- `tabWidth` has been **removed** as it lead to confusing behaviour. You can
replicate the same functionality by setting `shiftwidth`, `tabstop` and
`softtabstop` under `vim.options` as you see fit.
## Changelog {#sec-release-0.7-changelog}
[ItsSorae](https://github.com/ItsSorae):
@ -133,10 +157,10 @@ it to something other than `mapleader` to avoid conflicts.
recommended to go through rustacean.nvim's README to take a closer look at its
features and usage
- Add [lz.n] support and lazy-load some builtin plugins.
[lz.n]: https://github.com/mrcjkb/lz.n
- Add [lz.n] support and lazy-load some builtin plugins.
[jacekpoz](https://jacekpoz.pl):
[ocaml-lsp]: https://github.com/ocaml/ocaml-lsp
@ -300,17 +324,22 @@ it to something other than `mapleader` to avoid conflicts.
spellfiles to Neovim's runtime with ease.
- Add combined nvf configuration (`config.vim`) into the final package's
passthru as `passthru.neovimConfiguration` for easier debugging.
`passthru` as `passthru.neovimConfiguration` for easier debugging.
- Add support for [tiny-devicons-auto-colors] under
`vim.visuals.tiny-devicons-auto-colors`
- Move options that used to set `vim.o` values (e.g. `vim.wordWrap`) into
`vim.options` as default values. Some are left as they don't have a direct
equivalent, but expect a switch eventually.
[ppenguin](https://github.com/ppenguin):
- Telescope:
- Fixed `project-nvim` command and keybinding
- Added default ikeybind/command for `Telescope resume` (`<leader>fr`)
- Add `hcl` lsp/formatter (not the same as `terraform`, which is not useful for e.g. `nomad` config files).
- Add `hcl` lsp/formatter (not the same as `terraform`, which is not useful for
e.g. `nomad` config files).
[Soliprem](https://github.com/Soliprem):

View file

@ -1,65 +1,93 @@
{lib, ...}: let
inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule;
inherit (lib.lists) concatLists;
inherit (lib.nvim.config) batchRenameOptions;
renamedVimOpts = batchRenameOptions ["vim"] ["vim" "options"] {
colourTerm = "termguicolors";
mouseSupport = "mouse";
cmdHeight = "cmdheight";
updateTime = "updatetime";
mapTimeout = "tm";
cursorlineOpt = "cursorlineopt";
splitBelow = "splitbelow";
splitRight = "splitright";
autoIndent = "autoindent";
wordWrap = "wrap";
};
in {
imports = [
# 2024-06-06
(mkRemovedOptionModule ["vim" "tidal"] ''
Tidalcycles language support has been removed as of 2024-06-06 as it was long unmaintained. If
you depended on this functionality, please open an issue.
'')
imports = concatLists [
[
# 2024-06-06
(mkRemovedOptionModule ["vim" "tidal"] ''
Tidalcycles language support has been removed as of 2024-06-06 as it was long unmaintained. If
you depended on this functionality, please open an issue.
'')
# 2024-07-20
(mkRemovedOptionModule ["vim" "lsp" "nvimCodeActionMenu"] ''
nvimCodeActionMenu has been deprecated and removed upstream. As of 0.7, fastaction will be
available under `vim.ui.fastaction` as a replacement. Simply remove everything under
`vim.lsp.nvimCodeActionMenu`, and set `vim.ui.fastaction.enable` to `true`.
'')
# 2024-07-20
(mkRemovedOptionModule ["vim" "lsp" "nvimCodeActionMenu"] ''
nvimCodeActionMenu has been deprecated and removed upstream. As of 0.7, fastaction will be
available under `vim.ui.fastaction` as a replacement. Simply remove everything under
`vim.lsp.nvimCodeActionMenu`, and set `vim.ui.fastaction.enable` to `true`.
'')
(mkRemovedOptionModule ["vim" "autopairs" "enable"] ''
vim.autopairs.enable has been removed in favor of per-plugin modules.
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
'')
(mkRemovedOptionModule ["vim" "autopairs" "type"] ''
vim.autopairs.type has been removed in favor of per-plugin modules.
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "enable"] ''
vim.autocomplete.enable has been removed in favor of per-plugin modules.
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "type"] ''
vim.autocomplete.type has been removed in favor of per-plugin modules.
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "sources"] ''
vim.autocomplete.sources has been removed in favor of per-plugin modules.
You can add nvim-cmp sources with vim.autocomplete.nvim-cmp.sources
instead.
'')
(mkRemovedOptionModule ["vim" "snippets" "vsnip" "enable"] ''
vim.snippets.vsnip.enable has been removed in favor of the more modern luasnip.
'')
(mkRenamedOptionModule ["vim" "lsp" "lspkind" "mode"] ["vim" "lsp" "lspkind" "setupOpts" "mode"])
(mkRemovedOptionModule ["vim" "autopairs" "enable"] ''
vim.autopairs.enable has been removed in favor of per-plugin modules.
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
'')
(mkRemovedOptionModule ["vim" "autopairs" "type"] ''
vim.autopairs.type has been removed in favor of per-plugin modules.
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "enable"] ''
vim.autocomplete.enable has been removed in favor of per-plugin modules.
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "type"] ''
vim.autocomplete.type has been removed in favor of per-plugin modules.
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "sources"] ''
vim.autocomplete.sources has been removed in favor of per-plugin modules.
You can add nvim-cmp sources with vim.autocomplete.nvim-cmp.sources
instead.
'')
(mkRemovedOptionModule ["vim" "snippets" "vsnip" "enable"] ''
vim.snippets.vsnip.enable has been removed in favor of the more modern luasnip.
'')
(mkRenamedOptionModule ["vim" "lsp" "lspkind" "mode"] ["vim" "lsp" "lspkind" "setupOpts" "mode"])
# 2024-10-14
(mkRemovedOptionModule ["vim" "configRC"] ''
Please migrate your configRC sections to Neovim's Lua format, and
add them to `vim.luaConfigRC`.
# 2024-10-14
(mkRemovedOptionModule ["vim" "configRC"] ''
Please migrate your configRC sections to Neovim's Lua format, and
add them to `vim.luaConfigRC`.
See the v0.7 release notes for more information on why and how to
migrate your existing configurations to the new format.
'')
See the v0.7 release notes for more information on why and how to
migrate your existing configurations to the new format.
'')
(mkRemovedOptionModule ["vim" "disableDefaultRuntimePaths"] ''
Nvf now uses $NVIM_APP_NAME so there is no longer the problem of
(accidental) leaking of user configuration.
'')
(mkRemovedOptionModule ["vim" "disableDefaultRuntimePaths"] ''
Nvf now uses $NVIM_APP_NAME so there is no longer the problem of
(accidental) leaking of user configuration.
'')
(mkRemovedOptionModule ["vim" "lsp" "trouble" "mappings" "toggle"] ''
With Trouble having so many different modes, and breaking changes
upstream, it no longer makes sense, nor works, to toggle only Trouble.
'')
# 2024-11-30
(mkRenamedOptionModule ["vim" "leaderKey"] ["vim" "globals" "mapleader"])
(mkRemovedOptionModule ["vim" "lsp" "trouble" "mappings" "toggle"] ''
With Trouble having so many different modes, and breaking changes
upstream, it no longer makes sense, nor works, to toggle only Trouble.
'')
# 2024-11-30
(mkRenamedOptionModule ["vim" "leaderKey"] ["vim" "globals" "mapleader"])
(mkRemovedOptionModule ["vim" "tabWidth"] ''
Previous behaviour of this option was confusing and undocumented. Please set
`tabstop` and `shiftwidth` manually in `vim.options` or per-filetype in a
`ftplugin` directory added to your runtime path.
'')
]
# 2024-12-1
# Migrated via batchRenameOptions. Further batch renames must be below this line.
renamedVimOpts
];
}

View file

@ -3,23 +3,18 @@
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalExpression literalMD;
inherit (lib.options) mkOption mkEnableOption literalMD;
inherit (lib.strings) optionalString;
inherit (lib.types) enum bool str int either;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter;
inherit (lib.nvim.binds) pushDownDefault;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.types) luaInline;
cfg = config.vim;
in {
options.vim = {
colourTerm = mkOption {
type = bool;
default = true;
description = "Set terminal up for 256 colours";
};
disableArrows = mkOption {
type = bool;
default = false;
@ -38,12 +33,6 @@ in {
description = "Start scrolling this number of lines from the top or bottom of the page.";
};
wordWrap = mkOption {
type = bool;
default = true;
description = "Enable word wrapping.";
};
syntaxHighlighting = mkOption {
type = bool;
default = !config.vim.treesitter.highlight.enable;
@ -56,24 +45,10 @@ in {
description = "Make use of the clipboard for default yank and paste operations. Don't use * and +";
};
mouseSupport = mkOption {
type = enum ["a" "n" "v" "i" "c"];
default = "a";
description = ''
Set modes for mouse support.
* a - all
* n - normal
* v - visual
* i - insert
* c - command
'';
};
lineNumberMode = mkOption {
type = enum ["relative" "number" "relNumber" "none"];
default = "relNumber";
example = literalExpression "none";
example = "none";
description = "How line numbers are displayed.";
};
@ -83,30 +58,6 @@ in {
description = "Prevent swapfile and backupfile from being created";
};
tabWidth = mkOption {
type = int;
default = 4;
description = "Set the width of tabs";
};
autoIndent = mkOption {
type = bool;
default = true;
description = "Enable auto indent";
};
cmdHeight = mkOption {
type = int;
default = 1;
description = "Height of the command pane";
};
updateTime = mkOption {
type = int;
default = 300;
description = "The number of milliseconds till Cursor Hold event is fired";
};
showSignColumn = mkOption {
type = bool;
default = true;
@ -119,36 +70,12 @@ in {
description = "Set how bells are handled. Options: on, visual or none";
};
mapTimeout = mkOption {
type = int;
default = 500;
description = "Timeout in ms that neovim will wait for mapped action to complete";
};
splitBelow = mkOption {
type = bool;
default = true;
description = "New splits will open below instead of on top";
};
splitRight = mkOption {
type = bool;
default = true;
description = "New splits will open to the right";
};
enableEditorconfig = mkOption {
type = bool;
default = true;
description = "Follow editorconfig rules in current directory";
};
cursorlineOpt = mkOption {
type = enum ["line" "screenline" "number" "both"];
default = "line";
description = "Highlight the text line of the cursor with CursorLine hl-CursorLine";
};
searchCase = mkOption {
type = enum ["ignore" "smart" "sensitive"];
default = "sensitive";
@ -175,44 +102,35 @@ in {
};
};
config = {
vim.luaConfigRC.basic = entryAfter ["globalsScript"] ''
config.vim = {
# Set options that were previously interpolated in 'luaConfigRC.basic' as vim.options (vim.o)
# and 'vim.globals' (vim.g). Future options, if possible, should be added here instead of the
# luaConfigRC section below.
options = pushDownDefault {
encoding = "utf-8";
hidden = true;
expandtab = true;
};
globals = pushDownDefault {
editorconfig = cfg.enableEditorconfig;
};
# Options that are more difficult to set through 'vim.options'. Fear not, though
# as the Lua DAG is still as powerful as it could be.
luaConfigRC.basic = entryAfter ["globalsScript"] ''
-- Settings that are set for everything
vim.o.encoding = "utf-8"
vim.o.hidden = true
vim.opt.shortmess:append("c")
vim.o.expandtab = true
vim.o.mouse = ${toLuaObject cfg.mouseSupport}
vim.o.tabstop = ${toLuaObject cfg.tabWidth}
vim.o.shiftwidth = ${toLuaObject cfg.tabWidth}
vim.o.softtabstop = ${toLuaObject cfg.tabWidth}
vim.o.cmdheight = ${toLuaObject cfg.cmdHeight}
vim.o.updatetime = ${toLuaObject cfg.updateTime}
vim.o.tm = ${toLuaObject cfg.mapTimeout}
vim.o.cursorlineopt = ${toLuaObject cfg.cursorlineOpt}
vim.o.scrolloff = ${toLuaObject cfg.scrollOffset}
${optionalString cfg.undoFile.enable ''
vim.o.undofile = true
vim.o.undodir = ${toLuaObject cfg.undoFile.path}
''}
${optionalString cfg.splitBelow ''
vim.o.splitbelow = true
''}
${optionalString cfg.splitRight ''
vim.o.splitright = true
''}
${optionalString cfg.showSignColumn ''
vim.o.signcolumn = "yes"
''}
${optionalString cfg.autoIndent ''
vim.o.autoindent = true
''}
${optionalString cfg.preventJunkFiles ''
vim.o.swapfile = false
vim.o.backup = false
@ -253,23 +171,11 @@ in {
vim.cmd("syntax on")
''}
${optionalString (!cfg.wordWrap) ''
vim.o.wrap = false
''}
${optionalString cfg.hideSearchHighlight ''
vim.o.hlsearch = false
vim.o.incsearch = true
''}
${optionalString cfg.colourTerm ''
vim.o.termguicolors = true
''}
${optionalString (!cfg.enableEditorconfig) ''
vim.g.editorconfig = false
''}
${optionalString (cfg.searchCase == "ignore") ''
vim.o.smartcase = false
vim.o.ignorecase = true

View file

@ -5,7 +5,7 @@
}: let
inherit (lib.options) mkOption mkEnableOption literalMD literalExpression;
inherit (lib.strings) optionalString;
inherit (lib.types) str attrs lines listOf either path submodule anything;
inherit (lib.types) str bool int enum attrsOf lines listOf either path submodule anything;
inherit (lib.nvim.types) dagOf;
inherit (lib.nvim.lua) listToLuaTable;
@ -102,20 +102,22 @@ in {
globals = mkOption {
default = {};
type = submodule {
freeformType = anything;
freeformType = attrsOf anything;
options = {
mapleader = mkOption {
type = str;
default = " ";
description = "The key used for <leader> mappings";
description = "The key used for `<leader>` mappings";
};
maplocalleader = mkOption {
type = str;
default = ",";
description = "The key used for <localleader> mappings";
description = "The key used for `<localleader>` mappings";
};
};
};
example = {"some_variable" = 42;};
description = ''
An attribute set containing global variable values
@ -133,8 +135,80 @@ in {
};
options = mkOption {
type = attrs;
default = {};
type = submodule {
freeformType = attrsOf anything;
options = {
termguicolors = mkOption {
type = bool;
default = true;
description = "Set terminal up for 256 colours";
};
mouse = mkOption {
type = enum ["a" "n" "v" "i" "c"];
default = "a";
description = ''
Set modes for mouse support.
* a - all
* n - normal
* v - visual
* i - insert
* c - command
'';
};
cmdheight = mkOption {
type = int;
default = 1;
description = "Height of the command pane";
};
updatetime = mkOption {
type = int;
default = 300;
description = "The number of milliseconds till Cursor Hold event is fired";
};
tm = mkOption {
type = int;
default = 500;
description = "Timeout in ms that Neovim will wait for mapped action to complete";
};
cursorlineopt = mkOption {
type = enum ["line" "screenline" "number" "both"];
default = "line";
description = "Highlight the text line of the cursor with CursorLine hl-CursorLine";
};
splitbelow = mkOption {
type = bool;
default = true;
description = "New splits will open below instead of on top";
};
splitright = mkOption {
type = bool;
default = true;
description = "New splits will open to the right";
};
autoindent = mkOption {
type = bool;
default = true;
description = "Enable auto indent";
};
wrap = mkOption {
type = bool;
default = true;
description = "Enable word wrapping.";
};
};
};
example = {visualbell = true;};
description = ''
An attribute set containing vim options to be set