-
Notifications
You must be signed in to change notification settings - Fork 0
Typewriter.nvim API
- Introduction
- Core Functions
- Utility Functions
- Commands Module
- Configuration Module
- Center Block Configuration
- User Commands
- Events
- Sample Keymap Examples
- Further Documentation
Typewriter.nvim is a Neovim plugin that provides typewriter-style scrolling and advanced code block navigation. This API documentation outlines the core functions, utilities, and configuration options available to users and developers.
require('typewriter').setup(opts)
Initializes the Typewriter.nvim plugin with the given options. This function must be called to configure the plugin and enable its features.
-
enable_with_zen_mode
(boolean): Automatically enable typewriter mode when ZenMode is enabled. -
enable_with_true_zen
(boolean): Automatically enable typewriter mode when True Zen is enabled. -
keep_cursor_position
(boolean): Keep cursor position relative to text when centering the view or using TWTop/TWBottom. -
enable_notifications
(boolean): Enable or disable notifications for actions like enabling/disabling typewriter mode, and aligning code blocks. -
enable_horizontal_scroll
(boolean): Enable horizontal scrolling in Typewriter mode and center the cursor horizontally.
require('typewriter').setup({
enable_with_zen_mode = true,
enable_with_true_zen = true,
keep_cursor_position = true,
enable_notifications = true,
enable_horizontal_scroll = false,
})
local utils = require("typewriter.utils")
-
utils.is_typewriter_active()
: Check if Typewriter mode is currently active. -
utils.set_typewriter_active(active)
: Set the active state of Typewriter mode. -
utils.toggle_typewriter_active()
: Toggle the active state of Typewriter mode.
-
utils.notify(message)
: Display a notification if enabled in the configuration.
-
utils.center_cursor_horizontally()
: Center the cursor horizontally if horizontal scrolling is enabled.
local commands = require("typewriter.commands")
-
commands.center_cursor()
: Center the cursor on the screen. -
commands.enable_typewriter_mode()
: Enable typewriter mode. -
commands.disable_typewriter_mode()
: Disable typewriter mode. -
commands.toggle_typewriter_mode()
: Toggle typewriter mode. -
commands.center_block_and_cursor()
: Center the current code block and cursor. -
commands.move_to_top_of_block()
: Move the top of the current code block to the top of the screen. -
commands.move_to_bottom_of_block()
: Move the bottom of the current code block to the bottom of the screen.
local config = require("typewriter.config")
-
config.config_setup(user_config)
: Setup the configuration with user-provided options. -
config.get_config()
: Get the current configuration.
local center_block_config = require("typewriter.utils.center_block_config")
-
center_block_config.expand
: Table indicating which code blocks should be expanded and centered. -
center_block_config.should_expand(node_type)
: Get the expansion status for a given node type.
Typewriter.nvim provides several commands to control the typewriter mode manually:
-
:TWEnable
: Enable typewriter mode. -
:TWDisable
: Disable typewriter mode. -
:TWToggle
: Toggle typewriter mode on and off. -
:TWCenter
: Center the current code block and cursor. -
:TWTop
: Move the top of the current code block to the top of the screen. -
:TWBottom
: Move the bottom of the current code block to the bottom of the screen.
Typewriter.nvim triggers a TypewriterStateChanged
event when the state changes, which can be used for integration with other plugins or custom scripts:
vim.api.nvim_create_autocmd("User", {
pattern = "TypewriterStateChanged",
callback = function()
-- Your custom logic here
end
})
Here are some examples of how you can set up keymaps for Typewriter.nvim:
-- Enable Typewriter mode
vim.api.nvim_set_keymap('n', '<Leader>te', ':TWEnable<CR>', { noremap = true, silent = true })
-- Disable Typewriter mode
vim.api.nvim_set_keymap('n', '<Leader>td', ':TWDisable<CR>', { noremap = true, silent = true })
-- Toggle Typewriter mode
vim.api.nvim_set_keymap('n', '<Leader>tt', ':TWToggle<CR>', { noremap = true, silent = true })
-- Center the current code block and cursor
vim.api.nvim_set_keymap('n', '<Leader>tc', ':TWCenter<CR>', { noremap = true, silent = true })
-- Move the top of the current code block to the top of the screen
vim.api.nvim_set_keymap('n', '<Leader>tT', ':TWTop<CR>', { noremap = true, silent = true })
-- Move the bottom of the current code block to the bottom of the screen
vim.api.nvim_set_keymap('n', '<Leader>tB', ':TWBottom<CR>', { noremap = true, silent = true })
local utils = require("typewriter.utils")
local commands = require("typewriter.commands")
-- Toggle Typewriter mode and print status
vim.api.nvim_set_keymap('n', '<Leader>tT', '', {
noremap = true,
silent = true,
callback = function()
local new_state = utils.toggle_typewriter_active()
print("Typewriter mode is now: " .. (new_state and "active" or "inactive"))
end
})
-- Center cursor with custom notification
vim.api.nvim_set_keymap('n', '<Leader>tC', '', {
noremap = true,
silent = true,
callback = function()
commands.center_cursor()
utils.notify("Cursor centered")
end
})
-- Toggle Zen Mode and Typewriter mode together
vim.api.nvim_set_keymap('n', '<Leader>tz', '', {
noremap = true,
silent = true,
callback = function()
-- Assuming you're using the zen-mode plugin
require("zen-mode").toggle()
require("typewriter.commands").toggle_typewriter_mode()
end
})
For more detailed information about Typewriter.nvim's features, configuration options, and usage, you can access the comprehensive in-editor help documentation by running the following command in Neovim:
:help typewriter
This will open the full help file, which includes detailed explanations of all modules and their functions, a complete list of configuration options with descriptions, usage examples for each public function, information about integration with other plugins, and troubleshooting tips and best practices.
The help documentation is regularly updated to reflect the latest features and changes in Typewriter.nvim. It's an excellent resource for both new users looking to get started and experienced users seeking to maximize their use of the plugin.
Thank you for exploring the Typewriter.nvim documentation. We hope you find this plugin enhances your writing and coding experience in Neovim. If you have any questions, suggestions, or contributions, please feel free to reach out or submit an issue on our GitHub repository.
Stay Connected:
Crafted with care by Josh Peterson.