Ever wanted to know how noice creates the cmdline or wanted your own one?
No one? Guess it's just me 🥲.
Anyway, this post is a simple tutorial for creating a basic cmdline in neovim.
| ---Utility for keymap creation. | |
| ---@param lhs string | |
| ---@param rhs string|function | |
| ---@param opts string|table | |
| ---@param mode? string|string[] | |
| local function keymap(lhs, rhs, opts, mode) | |
| opts = type(opts) == 'string' and { desc = opts } | |
| or vim.tbl_extend('error', opts --[[@as table]], { buffer = bufnr }) | |
| mode = mode or 'n' | |
| vim.keymap.set(mode, lhs, rhs, opts) |
| [colors.selection] | |
| background = "#859900" | |
| text = "CellBackground" | |
| [colors.vi_mode_cursor] | |
| cursor = "#859900" | |
| text = "CellBackground" | |
| [cursor] |
In Neovim, the . character repeats "the most recent action"; however, this is not always respected by plugin actions. Here we will explore how to build dot-repeat support directly into your plugin, bypassing the requirement of dependencies like repeat.vim.
When some buffer-modifying action is performed, Neovim implicitly remembers the operator (e.g. d), motion (e.g. iw), and some other miscellaneous information. When the dot-repeat command is called, Neovim repeats that operator-motion combination. For example, if we type ci"text<Esc>, then we replace the inner contents of some double quotes with text, i.e. "hello world" → "text". Dot-repeating from here will do the same, i.e. "more samples" → "text".
A metatable in Lua defines various extraneous behaviors for a table when indexed, modified, interacted with, etc. They are Lua's core metaprogramming feature; most well known for being useful to emulate classes much like an OOP language.
Any table (and userdata) may be assigned a metatable. You can define a metatable for a table as such:
-- Our sample table
local tab = {}
-- Our metatable
local metatable = {
-- This table is then what holds the metamethods or metafields| package main | |
| import ( | |
| "fmt" | |
| ) | |
| func fib(n int) int { | |
| fibs := make(map[int]int, n+1) | |
| fibs[0] = 0 | |
| fibs[1] = 1 |
This is a cheat sheet for how to perform various actions to ZSH, which can be tricky to find on the web as the syntax is not intuitive and it is generally not very well-documented.
| Description | Syntax |
|---|---|
| Get the length of a string | ${#VARNAME} |
| Get a single character | ${VARNAME[index]} |
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "log" | |
| "net/http" | |
| "os" | |
| "os/signal" | |
| "time" |
| # make sure you don't have any soon to be forgotten version of vim installed | |
| $ sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-gui-common | |
| # Install Deps | |
| $ sudo apt-get install build-essential cmake | |
| $ sudo apt-get install python3-dev | |
| #Optional: so vim can be uninstalled again via `dpkg -r vim` | |
| $ sudo apt-get install checkinstall |