essentials.nvim icon indicating copy to clipboard operation
essentials.nvim copied to clipboard

Some tiny functions which i use regularly in neovim. Not a plugin per se.

essentials.nvim

Some tiny utility functions which i use locally.

Not actually meant for external use because there are no config options.
Instead you could fork the repo or copy paste the functions to your config.

Requires nvim version: 0.7.

The functions included are:

Go to url under the cursor

Will also work for stuff like folke/tokyonight.nvim or [link](https://github.com)

uses xdg-open in linux.
use go_to_url("start") for windows. #untested

go_to_url_2

nnoremap gx :lua require("essentials").go_to_url()<CR>

Go to the last place when opening a buffer

autocmd BufReadPost * lua require("essentials").last_place()

Run different files

Run files according to filetypes and commands.

run_file_2

nnoremap <leader>r :lua require("essentials").run_file()<CR>

Open terminal

Open a terminal with minimal options.
Args:

  • cmd: the command to run in the terminal
  • direction: 'h': horizontal, 'v': vertical, 't': tab
  • close_on_exit: boolean TODO: add a pic
nnoremap <leader>lg :lua require("essentials").open_term('lazygit', 't', true)<CR>

VSCode like floating rename window.

Uses vim.lsp.buf.rename()

rename

nnoremap <F2> :lua require("essentials").rename()<CR>

Simple Commenting function

A 20LOC function for commenting. (No multi-line comments).

toggle_comment

nnoremap <C-_> :lua require("essentials").toggle_comment()<CR>
vnoremap <C-_> :lua require("essentials").toggle_comment(true)<CR>

A smol fold function.

Simple fold function. Example:

simple_fold

vim.opt.foldtext = 'v:lua.require("essentials").simple_fold()'

Swap Booleans

A function to swap bools.

(true->false and false->true)

swap_bool

nnoremap <leader>s :lua require("essentials").swap_bool()<CR>

Search results from cht.sh

Search programming doubts inside neovim with cheat.sh

Gets current filetype and searches accordingly.

cheat_sheet

nnoremap <leader>cs :lua require("essentials").cheat_sh()<CR>

Util Functions

  • ui_input - emulation for vim.ui.input in a floating window

vim.ui.input = require("essentials").ui_input
  • ui_select - emulation for vim.ui.select in a float

vim.ui.select = require("essentials").ui_select
  • ui_picker - wrapper util telescope function. Example:

ui_picker({'1', '2', '3'}, {}, function(item) print("Selected: "..item) end)