-
Notifications
You must be signed in to change notification settings - Fork 0
TW `keep_cursor_position` Feature
The keep_cursor_position
feature in Typewriter.nvim ensures that the cursor remains in the same position relative to the text when the view moves. This feature is particularly useful when navigating through code, as it keeps your focus on the current line or block without shifting the cursor's position.
To enable the keep_cursor_position
feature, include it in the configuration when setting up Typewriter.nvim. Here’s how you can enable it:
-- ~/.config/nvim/init.lua
require('typewriter').setup {
keep_cursor_position = true,
}
When keep_cursor_position
is enabled, the view is centered around the cursor using the zz
command, but the cursor itself does not move. This behavior is maintained during normal, insert, and visual modes. The feature is implemented using autocommands that trigger the centering action whenever the cursor moves.
By default, keep_cursor_position
is set to true
. You can customize this behavior by modifying the configuration as follows:
-- ~/.config/nvim/init.lua
require('typewriter').setup {
keep_cursor_position = true, -- Keep the cursor in the same position relative to the text
}
Typewriter.nvim provides several commands and functions to control typewriter mode and centering behavior:
- TWEnable: Enables typewriter mode.
- TWDisable: Disables typewriter mode.
- TWToggle: Toggles typewriter mode on and off.
- TWCenter: Centers the view around the current code block or function.
These commands can be used directly in Neovim or mapped to keys for easier access.
You can create key mappings for these commands to quickly enable, disable, or toggle typewriter mode and to center the view:
-- ~/.config/nvim/init.lua
vim.api.nvim_set_keymap('n', '<leader>te', ':TWEnable<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>td', ':TWDisable<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>tt', ':TWToggle<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>tc', ':TWCenter<CR>', { noremap = true, silent = true })
The keep_cursor_position
feature is especially beneficial when you want to maintain focus on a particular line or block of code while navigating. It prevents the cursor from jumping to different positions, which can be distracting and disrupt your workflow.
The keep_cursor_position
feature in Typewriter.nvim enhances your coding experience by keeping the cursor steady while the view is centered. This feature, combined with the commands provided by Typewriter.nvim, allows for a more focused and efficient workflow in Neovim. Enable this feature to enjoy a distraction-free coding environment.
For more information on configuring and using Typewriter.nvim, refer to the official documentation and explore additional customization options to tailor the plugin to your needs.
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.