omega.nvim

March 13, 2025 ยท View on GitHub

Lua development utilities for Neovim.

All functions are lazy load.

More neovim plugins

Install

  • lazy.nvim
{"niuiic/omega.nvim", build = "cd rs && cargo build --release"}

Dev

Run current lua file with require("omega").dofile(vim.api.nvim_buf_get_name(0)). This function would unload deps of the file before running it, thus you can check the real-time update of the file without restart neovim.

It's recommended to do unit test with this function and builtin assert. Check lua/omega/exist_in_file.test.lua for an example.

Functions

nametypedesc
dofilefun(file_path: string)dofile without cache
exist_in_filefun(text: string, path: string): booleancheck if text exists in file
get_selected_areafun(): omega.Areaget selected area
get_selectionfun(): string[] | nilget selected text, get cursor expr in normal mode
to_normal_modefun()enter normal mode
get_timestampfun(time?: string): numberget a millisecond-level timestamp, time format should be like '2022-01-01 00:00:00'
get_human_readable_durationfun(start_time: number, end_time: number): stringget a human-readable duration between two millisecond-level timestamps
get_charsfun(str: string): string[]get chars from a string, work for any transformation format
diff_textfun(old_text: string, new_text: string, callback: fun(text_edits: omega.TextEdit[]))calculate text edits between two texts
get_line_endingfun(bufnr: number): stringget buffer specific line_ending character
get_offset_encodingfun(): stringget offset encoding
asyncfun(fn: fun())convert a synchronous function to an asynchronous one
awaitfun(fn: fun(resolve: fun(...: any[]))): any, any, ...wait for a asynchronous function
Channelomega.Channelspawn a process and enable bidirectional communication through stdin/stdout, check omega/channel.test.lua for examples

Useful Neovim Builtin Functions

nameusage
vim.fn.isdirectorycheck if path is a directory
vim.uv.fs_statcheck if path exist
vim.fs.rootfind root directory
vim.systemspawn a command
vim.iterlua list operation
vim.fs.joinpathconcat path