Giter Site home page Giter Site logo

arshlib.nvim's Introduction

Arshlib.nvim

GitHub tag (latest by date) License

Common library for using in Neovim plugins.

  1. Requirements
  2. Installation
  3. Quick
  4. Util
  5. Tables
  6. Colour
  7. Strings
  8. FS
  9. LSP
  10. License

Requirements

This library supports Neovim v0.7.0 and newer.

Update

Some functionalities such as creating augroup and autocmd have been provided by newer version of Neovim and are removed from this library. If you rely on these functionalities please pin this library to 86a8bbb commit, or use the Neovim's equivalent.

Installation

This library depends are the following libraries. Please make sure to add them as dependencies in your package manager:

Use your favourite package manager to install this library.

Packer

use({
  "arsham/arshlib.nvim",
  requires = {
    "MunifTanjim/nui.nvim",
    "nvim-lua/plenary.nvim",
  },
})

Lazy

{
  "arsham/arshlib.nvim",
  dependencies = {
    "MunifTanjim/nui.nvim",
    "nvim-lua/plenary.nvim",
  }
}

Quick

arshlib.quick provides quick shortcuts for commonly used Neovim functions.

Method Notes
normal(mode, motion) Execute a command in normal mode
call_and_centre(fn) Centre the cursor after calling fn
cmd_and_centre(cmd) Centre the cursor after executing Ex command
command(name, comand, opts) Shortcut for nvim_create_user_command
buffer_command(name, comand, opts) Shortcut for nvim_buf_create_user_command
selection_contents() Returns the contents of the visually selected region

Normal

Executes a normal command. For example:

quick.normal("n", "y2k")

See :h feedkeys() for values of the mode.

Util

In the following examples we assume the util is:

local util = require("arshlib.util")

User Input

This launches a popup buffer for the input:

util.user_input({
  prompt = "Message: ",
  on_submit = function(value)
    print("Thank you for your note: " .. value)
  end,
})

Tables

arshlib.colour module augments the internal table with new methods that can be chained. A _t is injected in the global space that can be used to create new Tables or convert a normal table to the type of Table. Methods that require a Table instance, if they receive a table instance, they will convert them automatically.

If a return value is of Table type, the returned value is always a new instance.

Method Notes
filter(fn)
map(fn)
values()
slice(f, l, s) Slice with step
merge(other)
find_first(fn)
contains_fn(fn)
contains(string)
reverse()
shuffle()
shunk(size) Returns chunks of tables
unique(fn)
sort(fn)
exec(fn) Execute on the whole table
when(bool) Returns an empty Table if v is false
map_length() includes the key-value pairs

Colour

arshlib.colour module provides functionalities around colours.

Method Notes
hex_to_rgb(hex)
rgb_to_hsv(r, g, b)
hsv_to_rgb(h, s, v)
rgb_to_hex(r, g, b)
andi_colour(colour, text) Used for terminal colouring

Strings

arshlib.strings injects some methods into the string std module.

Method
title_case(str)

FS

arshlib.fs provides some file-system functionalities.

Method Notes
file_module(filename) Returns module name and the filepath

LSP

arshlib.lsp provides useful tools for interacting with LSP.

Method Notes
is_lsp_attached()
has_lsp_capability(capability) True if at least one of the LSP servers has the given capability.
get_diagnostics_count(severity)
diagnostics_exist(severity)
diagnostic_errors() Count
diagnostic_warnings() Count
diagnostic_hints() Count
diagnostic_info() Count
go_mod_tidy(bufnr,filename) Executes go.mod tidy.
go_mod_check_upgrades(filename) Checks for dependency updates and adds to the quickfix list.

License

Licensed under the MIT License. Check the LICENSE file for details.

arshlib.nvim's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.