Skip to content

Commit

Permalink
Switch from vroom -> hop.nvim.
Browse files Browse the repository at this point in the history
  • Loading branch information
hadronized committed Feb 7, 2021
1 parent 61d31a6 commit 96087cb
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 108 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
_ __
| | / / _____ ____ ____ ____ ___
| | / / / ___/ / __ \ / __ \ / __ `__ \
| |/ / / / / /_/ // /_/ / / / / / / /
|___/ /_/ \____/ \____/ /_/ /_/ /_/
__
/ /_ ____ ____
/ __ \/ __ \/ __ \
/ / / / /_/ / /_/ /
/_/ /_/\____/ .___/
/_/
· Neovim motions on speed! ·

**Vroom** is an [EasyMotion]-like plugin allowing you to jump anywhere in a
**Hop** is an [EasyMotion]-like plugin allowing you to jump anywhere in a
document with as few keystrokes as possible. It does so by annotating text in
your buffer with hints, short string sequences for which each character
represents a key to type to jump to the annotated text. Most of the time,
those sequences’ lengths will be between 1 to 3 characters, making every jump
target in your document reachable in a few keystrokes.

**Vroom** is a complete from-scratch rewrite of [EasyMotion], a famous plugin to
**Hop** is a complete from-scratch rewrite of [EasyMotion], a famous plugin to
enhance the native motions of Vim. Even though [EasyMotion] is usable in
Neovim, it suffers from a few drawbacks making it not comfortable to use with
Neovim version >0.5 – at least at the time of writing these lines:
Expand All @@ -29,7 +30,7 @@ Neovim version >0.5 – at least at the time of writing these lines:
LSP server will receive a buffer with the jump target annotations… not
ideal.

**Vroom** is a modern take implementing this concept for the latest versions of
**Hop** is a modern take implementing this concept for the latest versions of
Neovim.

<!-- vim-markdown-toc GFM -->
Expand All @@ -53,7 +54,7 @@ Neovim.

# Getting started

This section will guide you through the list of steps you must take to be able to get started with **Vroom**.
This section will guide you through the list of steps you must take to be able to get started with **Hop**.

This plugin was written against Neovim 0.5, which is currently a nightly version. However, Neovim 0.4 should work
too. If you are still on Neovim 0.4, feel free to reach out and tell me how is your experience going.
Expand All @@ -69,7 +70,7 @@ it has reached a usable state, it still has some remaining issues to fix. You ca
embedded help, if you are curious:

```vim
:help vroom-limitations-issues
:help hop-limitations-issues
```

If you are encountering any of these issues, **you do not have to open an issue as it is already being actively worked
Expand All @@ -80,29 +81,29 @@ on.** However, PRs are greatly appreciated.
Using [vim-plug](https://github.com/junegunn/vim-plug):

```vim
Plug 'phaazon/vroom'
Plug 'phaazon/hop.nvim'
```

# Usage

A simple vim command is available to test with the default options: `:VroomWord`. If you would rather use the Lua API,
A simple vim command is available to test with the default options: `:HopWord`. If you would rather use the Lua API,
you can test it via the command prompt:

```vim
:lua require'vroom'.jump_words()
:lua require'hop'.jump_words()
```

If you want to create a key binding (<kbd>$</kbd> in this example) from within Lua:

```lua
-- place this in one of your configuration file(s)
vim.api.nvim_set_keymap('n', '$', "<cmd>lua require'vroom'.jump_words()<cr>", {})
vim.api.nvim_set_keymap('n', '$', "<cmd>lua require'hop'.jump_words()<cr>", {})
```

For a more complete user guide and help pages:

```vim
:help vroom
:help hop
```

More functions and commands to come soon.
Expand Down
144 changes: 72 additions & 72 deletions doc/vroom.txt → doc/hop.txt

Large diffs are not rendered by default.

File renamed without changes.
4 changes: 2 additions & 2 deletions lua/vroom/hint.lua → lua/hop/hint.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local defaults = require'vroom.defaults'
local perm = require'vroom.perm'
local defaults = require'hop.defaults'
local perm = require'hop.perm'

local M = {}

Expand Down
24 changes: 12 additions & 12 deletions lua/vroom/init.lua → lua/hop/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local defaults = require'vroom.defaults'
local hint = require'vroom.hint'
local keymap = require'vroom.keymap'
local defaults = require'hop.defaults'
local hint = require'hop.hint'
local keymap = require'hop.keymap'

local M = {}

Expand All @@ -17,18 +17,18 @@ local function update_hint_buffer(buf_handle, buf_width, buf_height, hints)
local hint_len = #w.hint

if hint_len == 1 then
vim.api.nvim_buf_add_highlight(buf_handle, -1, 'VroomNextKey', w.line - 1, w.col - 1, w.col)
vim.api.nvim_buf_add_highlight(buf_handle, -1, 'HopNextKey', w.line - 1, w.col - 1, w.col)
else
vim.api.nvim_buf_add_highlight(buf_handle, -1, 'VroomNextKey1', w.line - 1, w.col - 1, w.col)
vim.api.nvim_buf_add_highlight(buf_handle, -1, 'VroomNextKey2', w.line - 1, w.col, w.col + #w.hint - 1)
vim.api.nvim_buf_add_highlight(buf_handle, -1, 'HopNextKey1', w.line - 1, w.col - 1, w.col)
vim.api.nvim_buf_add_highlight(buf_handle, -1, 'HopNextKey2', w.line - 1, w.col, w.col + #w.hint - 1)
end
end
end
end

function M.jump_words(opts)
-- abort if we’re already in a vroom buffer
if vim.b['vroom#marked'] then
-- abort if we’re already in a hop buffer
if vim.b['hop#marked'] then
local teasing = nil
if opts and opts.teasing ~= nil then
teasing = opts.teasing
Expand All @@ -37,7 +37,7 @@ function M.jump_words(opts)
end

if teasing then
vim.cmd('echohl Error|echo "eh, don’t open vroom from within vroom, that’s super dangerous!"')
vim.cmd('echohl Error|echo "eh, don’t open hop from within hop, that’s super dangerous!"')
end

return
Expand All @@ -61,10 +61,10 @@ function M.jump_words(opts)

local hints = hint.create_hints(hint.by_word_start, buf_height, cursor_pos, win_lines, opts)

-- create a new buffer to contain the hints and mark it as ours with b:vroom#marked; this will allow us to know
-- whether we try to call vroom again from within such a buffer (and actually prevent it)
-- create a new buffer to contain the hints and mark it as ours with b:hop#marked; this will allow us to know
-- whether we try to call hop again from within such a buffer (and actually prevent it)
local hint_buf_handle = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_var(hint_buf_handle, 'vroom#marked', true)
vim.api.nvim_buf_set_var(hint_buf_handle, 'hop#marked', true)

-- fill the hint buffer
update_hint_buffer(hint_buf_handle, buf_width, buf_height, hints)
Expand Down
4 changes: 2 additions & 2 deletions lua/vroom/keymap.lua → lua/hop/keymap.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local defaults = require'vroom.defaults'
local defaults = require'hop.defaults'

local M = {}

Expand All @@ -14,7 +14,7 @@ function M.create_jump_keymap(buf_handle, opts)
-- remap all the jump keys
for i = 1, #keys do
local key = keys:sub(i, i)
vim.api.nvim_buf_set_keymap(buf_handle, '', key, "<cmd>lua require'vroom'.refine_hints(0, '" .. key .. "')<cr>", { nowait = true })
vim.api.nvim_buf_set_keymap(buf_handle, '', key, "<cmd>lua require'hop'.refine_hints(0, '" .. key .. "')<cr>", { nowait = true })
end

vim.api.nvim_buf_set_keymap(buf_handle, '', '<esc>', '<cmd>q<cr>', {})
Expand Down
2 changes: 1 addition & 1 deletion lua/vroom/perm.lua → lua/hop/perm.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local defaults = require'vroom.defaults'
local defaults = require'hop.defaults'

local M = {}

Expand Down
8 changes: 4 additions & 4 deletions plugin/vroom.vim → plugin/hop.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ if !has('nvim')
endif

" The jump-to-word command.
command! VroomWord lua require'vroom'.jump_words()
command! HopWord lua require'hop'.jump_words()

" Highlight used for the mono-sequence keys (i.e. sequence of 1).
highlight default VroomNextKey guifg=#ff007c gui=bold blend=0
highlight default HopNextKey guifg=#ff007c gui=bold blend=0

" Highlight used for the first key in a sequence.
highlight default VroomNextKey1 guifg=#00dfff gui=bold blend=0
highlight default HopNextKey1 guifg=#00dfff gui=bold blend=0

" Highlight used for the second and remaining keys in a sequence.
highlight default VroomNextKey2 guifg=#2b8db3 blend=0
highlight default HopNextKey2 guifg=#2b8db3 blend=0

0 comments on commit 96087cb

Please sign in to comment.