项目作者: notomo

项目描述 :
Mouse gesture plugin for neovim
高级语言: Lua
项目地址: git://github.com/notomo/gesture.nvim.git
创建时间: 2018-10-27T11:22:19Z
项目社区:https://github.com/notomo/gesture.nvim

开源协议:MIT License

下载


gesture.nvim

ci

gesture.nvim is a mouse gesture plugin for Neovim (nightly).

Example

  1. vim.opt.mouse = "a"
  2. vim.opt.mousemoveevent = true
  3. vim.keymap.set("n", "<LeftDrag>", [[<Cmd>lua require("gesture").draw()<CR>]], { silent = true })
  4. vim.keymap.set("n", "<LeftRelease>", [[<Cmd>lua require("gesture").finish()<CR>]], { silent = true })
  5. -- or if you would like to use right click
  6. vim.keymap.set("n", "<RightMouse>", [[<Nop>]])
  7. vim.keymap.set("n", "<RightDrag>", [[<Cmd>lua require("gesture").draw()<CR>]], { silent = true })
  8. vim.keymap.set("n", "<RightRelease>", [[<Cmd>lua require("gesture").finish()<CR>]], { silent = true })
  9. local gesture = require("gesture")
  10. gesture.register({
  11. name = "scroll to bottom",
  12. inputs = { gesture.up(), gesture.down() },
  13. action = "normal! G",
  14. })
  15. gesture.register({
  16. name = "next tab",
  17. inputs = { gesture.right() },
  18. action = "tabnext",
  19. })
  20. gesture.register({
  21. name = "previous tab",
  22. inputs = { gesture.left() },
  23. action = function(_) -- also can use callable
  24. vim.cmd.tabprevious()
  25. end,
  26. })
  27. gesture.register({
  28. name = "go back",
  29. inputs = { gesture.right(), gesture.left() },
  30. -- map to `<C-o>` keycode
  31. action = function()
  32. vim.api.nvim_feedkeys(vim.keycode("<C-o>"), "n", true)
  33. end,
  34. })
  35. gesture.register({
  36. name = "close gesture traced windows",
  37. match = function(ctx)
  38. local last_input = ctx.inputs[#ctx.inputs]
  39. return last_input and last_input.direction == "UP"
  40. end,
  41. can_match = function(ctx)
  42. local first_input = ctx.inputs[1]
  43. return first_input and first_input.direction == "RIGHT"
  44. end,
  45. action = function(ctx)
  46. table.sort(ctx.window_ids, function(a, b)
  47. return a > b
  48. end)
  49. for _, window_id in ipairs(ctx.window_ids) do
  50. if vim.api.nvim_win_is_valid(window_id) then
  51. vim.api.nvim_win_close(window_id, false)
  52. end
  53. end
  54. end,
  55. })