VIM Navigation
View SourceVIM-style keybindings for terminal buffers.
Usage
alias Raxol.Navigation.Vim
vim = Vim.new(buffer)
{:ok, vim} = Vim.handle_key("j", vim) # Move down
{:ok, vim} = Vim.handle_key("w", vim) # Next word
{:ok, vim} = Vim.handle_key("/", vim) # SearchCommands
| Key | Action | Key | Action |
|---|---|---|---|
| h/j/k/l | Left/Down/Up/Right | w/b/e | Word fwd/back/end |
| gg/G | Top/Bottom | 0/$ | Line start/end |
| / | Search forward | ? | Search backward |
| n/N | Next/Prev match | v | Visual mode |
Configuration
config = %{
wrap_horizontal: true,
wrap_vertical: false,
word_separators: " .,;:!?",
search_incremental: true
}
vim = Vim.new(buffer, config)Search
# Start search
{:ok, vim} = Vim.handle_key("/", vim)
# Type pattern, press Enter
{:ok, vim} = Vim.handle_key("Enter", vim)
# Navigate matches
{:ok, vim} = Vim.handle_key("n", vim)Visual Mode
{:ok, vim} = Vim.handle_key("v", vim) # Enter visual
{:ok, vim} = Vim.handle_key("l", vim) # Expand selection
{{x1, y1}, {x2, y2}} = Vim.get_selection(vim)Integration
def handle_input(state, key) do
{:ok, vim} = Vim.handle_key(key, state.vim)
{x, y} = vim.cursor
buffer = Buffer.set_cursor(state.buffer, x, y)
%{state | vim: vim, buffer: buffer}
endPerformance: < 1μs per movement