2022-04-24 15:34:00 +00:00
# nvim-libmodal
2020-04-29 19:01:59 +00:00
2022-04-24 15:34:00 +00:00
This is a rewrite of [vim-libmodal ](https://github.com/Iron-E/vim-libmodal ) using Neovim's Lua API. This project aims to be cross-compatable with `vim-libmodal` — with a few notable exceptions (see the [FAQ ](#FAQ )).
2020-04-29 19:01:59 +00:00
2023-02-17 20:04:34 +00:00
## Installation
Either use `packadd` or any package manager. I recommend using [lazy.nvim ](https://github.com/folke/lazy.nvim ).
### Requirements
2020-05-15 21:45:37 +00:00
2022-04-24 15:34:00 +00:00
* Neovim 0.7+.
* `vim-libmodal` is _not_ installed.
2020-04-29 19:01:59 +00:00
2023-02-17 20:04:34 +00:00
### Examples
2020-04-29 19:01:59 +00:00
2023-02-17 20:04:34 +00:00
#### lazy.nvim
2020-11-14 01:18:27 +00:00
2022-04-24 15:34:00 +00:00
```lua
2023-02-17 20:04:34 +00:00
{'Iron-E/nvim-libmodal', lazy = true},
```
2022-04-24 15:34:00 +00:00
2023-02-17 20:04:34 +00:00
#### packer.nvim
2022-04-24 15:34:00 +00:00
2023-02-17 20:04:34 +00:00
```lua
2022-04-24 15:34:00 +00:00
return require('packer').startup {function(use)
2023-02-18 17:58:56 +00:00
use 'Iron-E/nvim-libmodal'
2022-04-24 15:34:00 +00:00
end}
```
2020-11-14 01:18:27 +00:00
2022-04-24 15:34:00 +00:00
## Usage
2020-09-11 18:41:00 +00:00
The following plugins have been constructed using `nvim-libmodal` :
2022-04-24 15:34:00 +00:00
* [`nvim-bufmode` ](https://github.com/Iron-E/nvim-bufmode )
* [`nvim-marktext` ](https://github.com/Iron-E/nvim-marktext )
2020-09-11 18:41:00 +00:00
* [`nvim-tabmode` ](https://github.com/Iron-E/nvim-tabmode )
The following samples have been constructed using `nvim-libmodal` :
* [`mode-codedoc` ](https://gitlab.com/Iron_E/dotfiles/-/blob/master/.config/nvim/lua/mode-codedoc.lua )
* [The Official Lua Examples ](https://github.com/Iron-E/nvim-libmodal/tree/master/examples/lua )
* [The Official Vimscript Examples ](https://github.com/Iron-E/nvim-libmodal/tree/master/examples )
2022-04-24 15:34:00 +00:00
See [docs ](./doc ) for more information.
### Statusline
2023-02-17 18:34:42 +00:00
You can add `libmodal` modes to your status line. Here are a few examples of how to integrate with existing plugins.
#### feline.nvim
2023-02-17 19:16:17 +00:00
See my configuration for `feline.nvim` [here ](https://gitlab.com/Iron_E/dotfiles/-/blob/78e17b41cadd1660f8d3506ffce093437eb80aae/.config/nvim/lua/plugin/feline.lua#L134-160 )
2023-02-17 18:34:42 +00:00
#### galaxyline.nvim
See my configuration for `galaxyline.nvim` [here ](https://gitlab.com/Iron_E/dotfiles/-/blob/edf3e1c9779bbc81002832bb03ec875dc86cc16b/.config/nvim/lua/plugin/galaxyline.lua#L140-163 ).
2023-02-18 17:58:33 +00:00
#### heirline.nvim
< details >
< summary > An example config< / summary >
< pre lang = "lua" >
-- Defined in https://github.com/Iron-E/nvim-highlite
local BLACK = '#202020'
local BLUE = '#7766ff'
local CYAN = '#33dbc3'
local GRAY_DARK = '#353535'
local GRAY_LIGHT = '#c0c0c0'
local GREEN = '#22ff22'
local GREEN_LIGHT = '#99ff99'
local ICE = '#95c5ff'
local ORANGE = '#ff8900'
local ORANGE_LIGHT = '#f0af00'
local PINK = '#ffa6ff'
local PINK_LIGHT = '#ffb7b7'
local PURPLE = '#cf55f0'
local PURPLE_LIGHT = '#af60af'
local RED = '#ee4a59'
local RED_DARK = '#a80000'
local RED_LIGHT = '#ff4090'
local TAN = '#f4c069'
local TEAL = '#60afff'
local TURQOISE = '#2bff99'
local YELLOW = '#f0df33'
require('heirline').setup({statusline =
{
{
hl = function(self)
vim.api.nvim_set_hl(0, self.group, {bold = true, fg = self.color})
return self.group
end,
init = function(self)
if vim.g.libmodalActiveModeName then
self.name = vim.g.libmodalActiveModeName
self.color = self.modes[self.name]
else
local current_mode = self.modes[vim.api.nvim_get_mode().mode]
self.name = current_mode[1]
self.color = current_mode[2]
end
if not self.once then
vim.api.nvim_create_autocmd('ModeChanged', {command = 'redrawstatus', pattern = '*:*o'})
self.once = true
end
end,
provider = function(self) return '▊ ' .. self.name .. ' ' end,
static =
{ -- {{{
group = 'HeirlineViMode',
modes =
{
['c'] = {'COMMAND-LINE', RED},
['ce'] = {'NORMAL EX', RED_DARK},
['cv'] = {'EX', RED_LIGHT},
['i'] = {'INSERT', GREEN},
['ic'] = {'INS-COMPLETE', GREEN_LIGHT},
['n'] = {'NORMAL', PURPLE_LIGHT},
['no'] = {'OPERATOR-PENDING', PURPLE},
['r'] = {'HIT-ENTER', CYAN},
['r?'] = {':CONFIRM', CYAN},
['rm'] = {'--MORE', ICE},
['R'] = {'REPLACE', PINK},
['Rv'] = {'VIRTUAL', PINK_LIGHT},
['s'] = {'SELECT', TURQOISE},
['S'] = {'SELECT', TURQOISE},
2023-02-19 04:09:15 +00:00
[' '] = {'SELECT', TURQOISE},
2023-02-18 17:58:33 +00:00
['t'] = {'TERMINAL', ORANGE},
['v'] = {'VISUAL', BLUE},
['V'] = {'VISUAL LINE', BLUE},
2023-02-19 04:09:15 +00:00
[' '] = {'VISUAL BLOCK', BLUE},
2023-02-18 17:58:33 +00:00
['!'] = {'SHELL', YELLOW},
-- libmodal
['BUFFERS'] = TEAL,
['TABLES'] = ORANGE_LIGHT,
['TABS'] = TAN,
}
}, -- }}}
update = 'ModeChanged',
},
}})
< / pre >
< / details >
2023-02-17 18:34:42 +00:00
#### lualine.nvim
< details >
2023-02-18 17:58:56 +00:00
< summary > An example config< / summary >
< pre lang = "lua" >
2023-02-17 18:37:39 +00:00
-- Defined in https://github.com/Iron-E/nvim-highlite
local BLUE = '#7766ff'
local CYAN = '#33dbc3'
local GREEN = '#22ff22'
local GREEN_LIGHT = '#99ff99'
local ICE = '#95c5ff'
local ORANGE = '#ff8900'
local ORANGE_LIGHT = '#f0af00'
local PINK = '#ffa6ff'
local PINK_LIGHT = '#ffb7b7'
local PURPLE = '#cf55f0'
local PURPLE_LIGHT = '#af60af'
local RED = '#ee4a59'
local RED_DARK = '#a80000'
local RED_LIGHT = '#ff4090'
local TAN = '#f4c069'
local TEAL = '#60afff'
local TURQOISE = '#2bff99'
local YELLOW = '#f0df33'
local MODES =
{ -- {{{
2023-02-18 17:58:56 +00:00
['c'] = {'COMMAND-LINE', RED},
['ce'] = {'NORMAL EX', RED_DARK},
['cv'] = {'EX', RED_LIGHT},
['i'] = {'INSERT', GREEN},
['ic'] = {'INS-COMPLETE', GREEN_LIGHT},
['n'] = {'NORMAL', PURPLE_LIGHT},
['no'] = {'OPERATOR-PENDING', PURPLE},
['r'] = {'HIT-ENTER', CYAN},
['r?'] = {':CONFIRM', CYAN},
['rm'] = {'--MORE', ICE},
['R'] = {'REPLACE', PINK},
['Rv'] = {'VIRTUAL', PINK_LIGHT},
['s'] = {'SELECT', TURQOISE},
['S'] = {'SELECT', TURQOISE},
2023-02-19 04:09:15 +00:00
[' '] = {'SELECT', TURQOISE},
2023-02-18 17:58:56 +00:00
['t'] = {'TERMINAL', ORANGE},
['v'] = {'VISUAL', BLUE},
['V'] = {'VISUAL LINE', BLUE},
2023-02-19 04:09:15 +00:00
[' '] = {'VISUAL BLOCK', BLUE},
2023-02-18 17:58:56 +00:00
['!'] = {'SHELL', YELLOW},
2023-02-17 18:37:39 +00:00
2023-02-18 17:58:56 +00:00
-- libmodal
['BUFFERS'] = TEAL,
['TABLES'] = ORANGE_LIGHT,
['TABS'] = TAN,
2023-02-17 18:37:39 +00:00
} -- }}}
local MODE_HL_GROUP = 'LualineViMode'
--[[/* FELINE CONFIG */]]
2023-02-17 20:32:20 +00:00
vim.api.nvim_create_autocmd('ModeChanged', {callback = function()
2023-02-18 17:58:56 +00:00
require('lualine').refresh {scope = 'window', place = {'statusline'}}
2023-02-17 20:32:20 +00:00
end})
2023-02-17 18:37:39 +00:00
require('lualine').setup {sections = {lualine_a = {{
2023-02-18 17:58:56 +00:00
function() -- auto change color according the vim mode
local mode_color, mode_name
2023-02-17 18:37:39 +00:00
2023-02-18 17:58:56 +00:00
if vim.g.libmodalActiveModeName then
mode_name = vim.g.libmodalActiveModeName
mode_color = MODES[mode_name]
else
local current_mode = MODES[vim.api.nvim_get_mode().mode]
2023-02-17 18:37:39 +00:00
2023-02-18 17:58:56 +00:00
mode_name = current_mode[1]
mode_color = current_mode[2]
end
2023-02-17 18:37:39 +00:00
2023-02-18 17:58:56 +00:00
vim.api.nvim_set_hl(0, MODE_HL_GROUP, {fg = mode_color, bold = true})
2023-02-17 18:37:39 +00:00
2023-02-18 17:58:56 +00:00
return mode_name..' '
end,
icon = {'▊', align = 'left'},
color = MODE_HL_GROUP,
padding = 0,
2023-02-17 18:37:39 +00:00
}}}}
2023-02-18 17:58:56 +00:00
< / pre >
2023-02-17 18:34:42 +00:00
< / details >
2022-04-24 15:34:00 +00:00
2023-02-17 19:12:03 +00:00
#### staline.nvim
< details >
2023-02-18 17:58:56 +00:00
< summary > An example config< / summary >
< pre lang = "lua" >
2023-02-17 19:12:03 +00:00
--[[/* CONSTANTS */]]
-- Defined in https://github.com/Iron-E/nvim-highlite
local BLUE = '#7766ff'
local CYAN = '#33dbc3'
local GREEN = '#22ff22'
local GREEN_LIGHT = '#99ff99'
local ICE = '#95c5ff'
local ORANGE = '#ff8900'
local ORANGE_LIGHT = '#f0af00'
local PINK = '#ffa6ff'
local PINK_LIGHT = '#ffb7b7'
local PURPLE = '#cf55f0'
local PURPLE_LIGHT = '#af60af'
local RED = '#ee4a59'
local RED_DARK = '#a80000'
local RED_LIGHT = '#ff4090'
local TAN = '#f4c069'
local TEAL = '#60afff'
local TURQOISE = '#2bff99'
local YELLOW = '#f0df33'
local MODES =
{ -- {{{
2023-02-18 17:58:56 +00:00
['c'] = {'COMMAND-LINE', RED},
['ce'] = {'NORMAL EX', RED_DARK},
['cv'] = {'EX', RED_LIGHT},
['i'] = {'INSERT', GREEN},
['ic'] = {'INS-COMPLETE', GREEN_LIGHT},
['n'] = {'NORMAL', PURPLE_LIGHT},
['no'] = {'OPERATOR-PENDING', PURPLE},
['r'] = {'HIT-ENTER', CYAN},
['r?'] = {':CONFIRM', CYAN},
['rm'] = {'--MORE', ICE},
['R'] = {'REPLACE', PINK},
['Rv'] = {'VIRTUAL', PINK_LIGHT},
['s'] = {'SELECT', TURQOISE},
['S'] = {'SELECT', TURQOISE},
2023-02-19 04:09:15 +00:00
[' '] = {'SELECT', TURQOISE},
2023-02-18 17:58:56 +00:00
['t'] = {'TERMINAL', ORANGE},
['v'] = {'VISUAL', BLUE},
['V'] = {'VISUAL LINE', BLUE},
2023-02-19 04:09:15 +00:00
[' '] = {'VISUAL BLOCK', BLUE},
2023-02-18 17:58:56 +00:00
['!'] = {'SHELL', YELLOW},
2023-02-17 19:12:03 +00:00
2023-02-18 17:58:56 +00:00
-- libmodal
['BUFFERS'] = TEAL,
['TABLES'] = ORANGE_LIGHT,
['TABS'] = TAN,
2023-02-17 19:12:03 +00:00
} -- }}}
local MODE_HL_GROUP = 'StalineViMode'
--[[/* FELINE CONFIG */]]
vim.api.nvim_set_hl(0, MODE_HL_GROUP, {})
require('staline').setup(
{
2023-02-18 17:58:56 +00:00
mode_colors = {},
mode_icons = {},
sections = {left =
{
function()
local mode_color, mode_name
2023-02-17 19:12:03 +00:00
2023-02-18 17:58:56 +00:00
if vim.g.libmodalActiveModeName then
mode_name = vim.g.libmodalActiveModeName
mode_color = MODES[mode_name]
else
local current_mode = MODES[vim.api.nvim_get_mode().mode]
2023-02-17 19:12:03 +00:00
2023-02-18 17:58:56 +00:00
mode_name = current_mode[1]
mode_color = current_mode[2]
end
2023-02-17 19:12:03 +00:00
2023-02-18 17:58:56 +00:00
vim.api.nvim_set_hl(0, MODE_HL_GROUP, {bold = true, fg = mode_color})
return {MODE_HL_GROUP, mode_name}
end,
}},
2023-02-17 19:12:03 +00:00
})
2023-02-18 17:58:56 +00:00
< / pre >
2023-02-17 19:12:03 +00:00
< / details >
2022-04-24 15:34:00 +00:00
## FAQ
### nvim-libmodal vs. vim-libmodal
The following is a list of expressions that work in `nvim-libmodal` but not `vim-libmodal` :
* `require 'libmodal'` in Lua.
2023-02-18 17:58:56 +00:00
* `vim-libmodal` does not support interacting with it through Lua, you must use the Vimscript interface.
2020-05-15 21:45:37 +00:00
2022-04-24 15:34:00 +00:00
The following is a list of expressions that work in `vim-libmodal` but not `nvim-libmodal` :
2020-04-29 19:01:59 +00:00
2022-04-24 15:34:00 +00:00
* `call libmodal#Enter('FOO', funcref('bar'), baz)` in Vimscript.
2023-02-18 17:58:56 +00:00
* Lua does not support passing `funcref` s from Vimscript. Try using the Lua interface instead.
2022-04-24 15:34:00 +00:00
* `call libmodal#Prompt('FOO', funcref('bar'), baz)` in Vimscript.
2023-02-18 17:58:56 +00:00
* Lua does not support passing `funcref` s from Vimscript. Try using the Lua interface instead.