├── stylua.toml ├── lua └── emoji_picker │ ├── emojis.lua │ └── init.lua ├── LICENSE └── README.md /stylua.toml: -------------------------------------------------------------------------------- 1 | indent_type = "Spaces" 2 | indent_width = 2 3 | -------------------------------------------------------------------------------- /lua/emoji_picker/emojis.lua: -------------------------------------------------------------------------------- 1 | return { 2 | "😀😃😄😁😆😅😂🤣😊💀", 3 | "😉😌😍🥰😘😗😙😚😋😛", 4 | "🧐🤓😎🤩🥳😏😒😞😔🙏", 5 | "😣😖😫😩🥺😢😭😤😠😡", 6 | "🥶😱😨😰😥😓🤗🤔🤭🤫", 7 | "😬🙄😯😦😧😮😲🥱😴🤤", 8 | "🤢🤮🤧😷🤒🤕🤑🤠😈👿", 9 | "👋🤚✋🖖👌🤏✌️🤞🤟🤘", 10 | } 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Wilson Oh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lua/emoji_picker/init.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | local config = { 4 | window = { 5 | relative = "cursor", 6 | row = 1, 7 | col = 1, 8 | width = 20, 9 | height = 6, 10 | anchor = "SW", 11 | style = "minimal", 12 | border = "rounded", 13 | }, 14 | emoji_list = require("emoji_picker.emojis"), 15 | } 16 | 17 | local get_char_at_cursor = function() 18 | return vim.fn.strcharpart(vim.fn.strpart(vim.fn.getline("."), vim.fn.col(".") - 1), 0, 1) 19 | end 20 | 21 | local close_win = function(winnr, bufnr, set_insert) 22 | vim.api.nvim_win_close(winnr, false) 23 | vim.api.nvim_buf_delete(bufnr, {}) 24 | if set_insert then 25 | vim.cmd("startinsert") 26 | end 27 | end 28 | 29 | local set_close_keys = function(keys, winnr, bufnr) 30 | for _, key in ipairs(keys) do 31 | vim.keymap.set("n", key, function() 32 | close_win(winnr, bufnr) 33 | end, { buffer = bufnr }) 34 | end 35 | end 36 | 37 | local set_win_opts = function(winnr, bufnr) 38 | vim.api.nvim_buf_set_option(bufnr, "modifiable", false) 39 | local set_insert = vim.api.nvim_get_mode().mode == "i" 40 | 41 | vim.cmd("stopinsert") 42 | 43 | vim.keymap.set("n", "", function() 44 | local char = get_char_at_cursor() 45 | close_win(winnr, bufnr, set_insert) 46 | vim.api.nvim_put({ char }, "c", true, true) 47 | end, { buffer = bufnr }) 48 | 49 | vim.keymap.set("n", "", "l", { buffer = bufnr }) 50 | vim.keymap.set("n", "", "h", { buffer = bufnr }) 51 | 52 | set_close_keys({ "q", "" }, winnr, bufnr) 53 | end 54 | 55 | M.open_win = function() 56 | local bufnr = vim.api.nvim_create_buf(false, true) 57 | local winnr = vim.api.nvim_open_win(bufnr, true, config.window) 58 | vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, config.emoji_list) 59 | set_win_opts(winnr, bufnr) 60 | end 61 | 62 | M.setup = function(user_config) 63 | if user_config then 64 | config = vim.tbl_deep_extend("force", config, user_config) 65 | end 66 | vim.api.nvim_create_user_command("EmojiPicker", M.open_win, {}) 67 | end 68 | 69 | return M 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # emoji_picker-nvim 2 | 3 | ## Demo 4 | https://user-images.githubusercontent.com/87934749/185742547-6f7c73d9-1998-47a2-ac83-64233ec252c4.mp4 5 | 6 | ## *But why??* 7 | There are already many other emoji/icon picker plugins such as [telescope-emoji.nvim](https://github.com/xiyaowong/telescope-emoji.nvim), [icon-picker.nvim](https://github.com/ziontee113/icon-picker.nvim) or even [cmp-emoji](https://github.com/hrsh7th/cmp-emoji) which offers way more features like fuzzy searching. 8 | However, I just wanted a quick and dirty way to have the emojis displayed in a grid and select one, similar to phone keyboards. 9 | 10 | ## Installation 11 | ### Using [packer](https://github.com/wbthomason/packer.nvim) 12 | ```lua 13 | use({ 14 | "WilsonOh/emoji_picker-nvim", 15 | config = function() 16 | require("emoji_picker").setup() 17 | end, 18 | }) 19 | ``` 20 | 21 | ## Usage 22 | ### Invocation 23 | This plugin does not set any keymaps. The plugin can be called using the `EmojiPicker` ex-command or `require("emoji_picker").open_win()` in lua. 24 | ### Navigation and selecting 25 | Within the emoji picker window, press `q` or `esc` to close out of the window. Use the usual navigation keys to move around in the window (`Tab` and `Shift-Tab` are set to move right and left in the window) and press `Enter` to select an emoji. 26 | ### Keymap used in demo 27 | ```lua 28 | vim.keymap.set("i", "", "EmojiPicker") 29 | ``` 30 | 31 | ## Configuration 32 | ### Default configuration 33 | ```lua 34 | local config = { 35 | window = { 36 | relative = "cursor", 37 | row = 1, 38 | col = 1, 39 | width = 20, 40 | height = 6, 41 | anchor = "SW", 42 | style = "minimal", 43 | border = "rounded", 44 | }, 45 | emoji_list = require("emoji_picker.emojis"), 46 | } 47 | ``` 48 | The default list of emojis is very limited as I didn't want to add too many, but a custom list of emojis can be passed into the setup function. All the arguments required for `vim.api.open_win` can also be modified through the `window` key in the setup function. 49 | e.g. 50 | ```lua 51 | require("emoji_picker").setup({ 52 | window = { 53 | width = 25, 54 | height = 10, 55 | }, 56 | emoji_list = { 57 | "*my custom*", 58 | "*lines of emojis*", 59 | }, 60 | }) 61 | ``` 62 | --------------------------------------------------------------------------------