{"id":13509816,"url":"https://github.com/dm1try/nvim","last_synced_at":"2025-03-22T07:32:06.429Z","repository":{"id":44139372,"uuid":"66451354","full_name":"dm1try/nvim","owner":"dm1try","description":"write plugins for Neovim using Elixir","archived":false,"fork":false,"pushed_at":"2022-04-03T19:12:58.000Z","size":58,"stargazers_count":27,"open_issues_count":5,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-22T09:46:40.207Z","etag":null,"topics":["elixir","neovim"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dm1try.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-24T09:36:16.000Z","updated_at":"2024-07-20T18:26:41.000Z","dependencies_parsed_at":"2022-09-11T23:21:31.453Z","dependency_job_id":null,"html_url":"https://github.com/dm1try/nvim","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm1try%2Fnvim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm1try%2Fnvim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm1try%2Fnvim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dm1try%2Fnvim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dm1try","download_url":"https://codeload.github.com/dm1try/nvim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244925175,"owners_count":20532873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","neovim"],"created_at":"2024-08-01T02:01:13.696Z","updated_at":"2025-03-22T07:32:06.136Z","avatar_url":"https://github.com/dm1try.png","language":"Elixir","funding_links":[],"categories":["Editors"],"sub_categories":[],"readme":"# Neovim Elixir host [![Build Status](https://travis-ci.org/dm1try/nvim.svg?branch=master)](https://travis-ci.org/dm1try/nvim)\n\nImplements support for Neovim remote plugins written in Elixir.\n## Requirements\n  - Neovim \u003e= 1.6-dev\n  - Elixir \u003e= 1.3\n\n## Installation\n\nInstall the host archive, we will use it to build the host locally.\n\n```\nmix archive.install https://github.com/dm1try/nvim/releases/download/v0.4.2/nvim.ez\n```\n\nBuild and install the host by running `nvim.install` and providing the path to nvim config(`~/.config/nvim` by default on linux systems)\n\n```\nmix nvim.install /path/to/nvim/config\n```\n## Upgrade\nSame as the install step but if you have any problem try to remove the host at first:\n```\nmix nvim.remove /path/to/nvim/config\nmix nvim.install /path/to/nvim/config\n```\n\n## Usage\n\nCurrently, each time you somehow update remote plugins you should run `:UpdateElixirPlugins` nvim command.\n\nSee `:h remote-plugin-manifest` for the clarification why the manifest is needed(generally, it saves the neovim startup time if remote plugins are installed).\n\n# Plugin Development (Developers only)\n\n```elixir\n                   +--------------------------+\n+--------+ MsgPack |              +---------+ |\n|        |   RPC   | +------+     |         | |\n| Neovim \u003c---------\u003e | Host \u003c-----\u003e Plugins | |\n|        |         | +------+     |         | |\n+--------+         |              +---------+ |\n                   +--------------------------+\n```\n## Structure\n\nHost supports two types of plugins:\n  1. Scripts (an elixir script that usually contains simple logic and does not depend on other libs/does not need the versioning/etc).\n\n  2. Applications (an OTP application that is implemented as part of host umbrella project). You can find more information about umbrella projects [here](http://elixir-lang.org/getting-started/mix-otp/dependencies-and-umbrella-apps.html).\n\nHost with plugins lives in `rplugin/elixir` neovim config directory.\nScript plugin name must have postfix `plugin` in his name.\n\u003e Example `my_plugin.exs`\n\nTypical files tree for such dir:\n```bash\n~/.config/nvim/rplugin/elixir\n\n├── scripts \u003c~ scripts\n├── apps \u003c~ applications AKA \"precompiled plugins\"\n└── mix.exs\n```\n\n### Plugin DSL\n#### Events\n`on_event`(better known as `autocmd` for vim users) defines the callback that triggered by editor when some event\nhappened. Run `:h autocmd-events` for the list of events.\n\n```elixir\non_event :vim_enter do\n  Logger.info(\"the editor is ready\")\nend\n```\n#### Functions\n`function` defines the vim function\n```elixir\nfunction wrong_sum(left, right) do\n  left - right\nend\n```\nuse it in the editor `:echo WrongSum(1,2)`\n\n#### Commands\n`command` defines the command.\n\n```elixir\ncommand just_echo do\n  NVim.Session.nvim_command(\"echo 'from remote plugin'\")\nend\n```\nuse it in the editor `:JustEcho`\n\nOnly single param can be defined for a command.\nThis param holds an array of strings provided on the command call.\nElixir `OptionParser` is good choice here.\n\n### Session\nIn the latest example we used `nvim_command` method which is part of Neovim remote API.\nIn the examples below we asume that we import `NVim.Session` in context of plugin.\n\n### State\nEach plugin is [GenServer](http://elixir-lang.org/docs/stable/elixir/GenServer.html).\nSo you can share the state between all actions while the plugin is running:\n```elixir\ndef init(_args) do\n  {:ok, %{move_count: 0}}\nend\n\non_event :cursor_moved do\n  state = %{state | move_count: state.move_count + 1}\nend\n\ncommand show_moves_count do\n  moves_info = \"Current moves: #{state.move_count}\"\n  nvim_command(\"echo '#{moves_info}'\")\nend\n```\n\u003e NOTE: you cannot assing the state in inner scopes(`if/case/with/etc`). You should return the value from the scope and then assing it to the state in root scope.\n\n### Pre-evaluated values\nAny vim value can be pre-evaluated before the action will be triggered:\n```elixir\non_event :cursor_hold_i,\n  pre_evaluate: %{\n    \"expand('cWORD')\" =\u003e word_under_cursor\n  }\ndo\n  if word_under_cursor == \"Elixir\" do\n    something()\n  end\nend\n```\n\n## Basic scripts\n\"Hello\" from plug:\n```elixir\n# ~/.config/nvim/rplugin/elixir/scripts/my_plugin.exs\ndefmodule MyPlug do\n  use NVim.Plugin\n\n  command hello_from_plug do\n    NVim.Session.nvim_command \"echo 'hello'\"\n  end\nend\n```\n## Debugging scripts.\n`ElixirHostLog` opens the host log.\n Log severety level can be changed in the host config.\n \u003e `~/.config/nvim/rplugin/elixir/apps/host/config/config.exs` is default path on linux\n\n `ElixirReloadScript` reloads running script.\n \u003e This works only for the reloading an implementation of already defined command/function/event.\n \u003e This means if you add/remove some definition or change its option(`pre_evaluate` for example) you should restart the editor.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdm1try%2Fnvim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdm1try%2Fnvim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdm1try%2Fnvim/lists"}