A Neovim plugin that emulates a typewriter, keeping the cursor centered on the screen for a focused writing experience, and provides advanced code block navigation. 📝✨
- Keeps the cursor centered on the screen while you type or navigate. 📌
- Simple commands to enable, disable, and toggle the typewriter mode. 🔄
- Integrates with ZenMode and True Zen for a seamless distraction-free environment. 🧘
:TWCenter
command to center the view around the current code block or function using Tree-sitter. 🌳:TWTop
command to move the top of the current code block to the top of the screen. ⬆️:TWBottom
command to move the bottom of the current code block to the bottom of the screen. ⬇️- Set
keep_cursor_position
totrue
in plugin config to keep cursor position relative to text when centering the view or using TWTop/TWBottom. 📌 - Set
enable_notifications
totrue
in plugin config to enable or disable notifications for actions like enabling/disabling typewriter mode, and aligning code blocks. 🔔 - Enable horizontal scrolling in Typewriter mode and center the cursor by setting
enable_horizontal_scroll
totrue
in the plugin configuration.↔️ - Robust state tracking with
is_typewriter_active()
,set_typewriter_active()
, andtoggle_typewriter_active()
functions for programmatic control. 🎛️ TypewriterStateChanged
event for reacting to Typewriter mode state changes in your own scripts or plugins. 🔄- Comprehensive in-editor help documentation accessible via
:help typewriter
. 📚
Typewriter requires the following dependencies:
nvim-treesitter: Typewriter uses Tree-sitter to determine the current code block or function for the :TWCenter
, :TWTop
, and :TWBottom
commands.
Make sure to install and configure nvim-treesitter before using Typewriter.
Using Packer
Add the following to your Packer configuration:
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate'
}
use {
'joshuadanpeterson/typewriter',
requires = 'nvim-treesitter/nvim-treesitter',
config = function()
require('typewriter').setup()
end
}
Using Lazy.nvim
Add the following to your Lazy.nvim configuration:
local lazy = require('lazy')
lazy.setup({
-- Other plugins...
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
},
{
'joshuadanpeterson/typewriter',
dependencies = {
'nvim-treesitter/nvim-treesitter',
},
config = function()
require('typewriter').setup()
end,
opts = {}
},
})
Here is a markdown table that summarizes the commands available in Typewriter.nvim:
Command | Description |
---|---|
:TWEnable |
Enable typewriter mode |
:TWDisable |
Disable typewriter mode |
:TWToggle |
Toggle typewriter mode on and off |
:TWCenter |
Center the view around the current code block or function using Tree-sitter |
: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 |
These commands allow you to control the typewriter mode in Neovim and navigate code blocks, enhancing your writing and coding experience by maintaining focus and reducing distractions. The :TWCenter
, :TWTop
, and :TWBottom
commands leverage Tree-sitter to intelligently manipulate the view of your code blocks, providing a more focused and flexible coding experience.
Typewriter.nvim supports a variety of filetypes and languages, ensuring that your code navigation and centering experience is smooth across different programming environments. Below is a list of supported filetypes and languages. If you don't see your filetype listed, we still encourage you to download the plugin, as the common significant blocks section of the center_block_config.lua file supports many filetypes by default. If you download the plugin and it doesn't work as expected even with Treesitter installed and set up as a dependency, please open up an issue.
- PHP
- Go
- Rust
- JavaScript
- Python
- HTML
- CSS
- Bash
- SQL
- YAML
- JSON
- Dart
- Swift
- C++
- C#
- C
- Zig
- OCaml
- Java
If you don't see your filetype supported, propose it via issue or a pull request!
ZenMode is a plugin for Neovim written by folke that provides a distraction-free coding environment by opening the current buffer in a new full-screen floating window. It hides various UI elements, works well with other floating windows, and integrates with plugins like Telescope and gitsigns. Typewriter integrates with ZenMode to automatically enable typewriter mode when entering ZenMode and disable it when exiting.
True Zen is another plugin for Neovim written by pocco81 that offers multiple modes to unclutter your screen, including Ataraxis (a zen mode), Minimalist, Narrow, and Focus. True Zen allows you to disable UI components, narrow a text region for better focus, and customize callbacks for each mode. Typewriter integrates with True Zen, particularly the Ataraxis mode, to automatically enable typewriter mode when entering Ataraxis and disable it when exiting.
-- ~/.config/nvim/init.lua
require('packer').startup(function()
-- Other plugins...
use {
'joshuadanpeterson/typewriter',
config = function()
require('typewriter').setup({
enable_with_zen_mode = true,
enable_with_true_zen = true,
keep_cursor_position = true,
enable_notifications = true,
enable_horizontal_scroll = true,
})
end
}
use {
'folke/zen-mode.nvim',
opts = {
on_open = function()
vim.cmd('TWEnable')
end,
on_close = function()
vim.cmd('TWDisable')
end
}
}
use {
'pocco81/true-zen.nvim',
config = function()
require("true-zen").setup {
modes = {
ataraxis = {
callbacks = {
open_pre = function()
vim.cmd('TWEnable')
end,
close_pos = function()
vim.cmd('TWDisable')
end
}
}
}
}
end
}
end)
-- ~/.config/nvim/lua/plugins/init.lua
local lazy = require('lazy')
lazy.setup({
-- Other plugins...
{
'joshuadanpeterson/typewriter',
config = function()
require('typewriter').setup({
enable_with_zen_mode = true,
enable_with_true_zen = true,
keep_cursor_position = true,
enable_notifications = true,
enable_horizontal_scroll = true,
})
end,
opts = {}
},
{
'folke/zen-mode.nvim',
opts = {
on_open = function()
vim.cmd('TWEnable')
end,
on_close = function()
vim.cmd('TWDisable')
end
}
},
{
'pocco81/true-zen.nvim',
config = function()
require("true-zen").setup {
modes = {
ataraxis = {
callbacks = {
open_pre = function()
vim.cmd('TWEnable')
end,
close_pos = function()
vim.cmd('TWDisable')
end
}
}
}
}
end,
opts = {}
}
})
Typewriter.nvim now comes with comprehensive documentation to help you make the most of its features:
- In-Editor Help: Access detailed documentation directly in Neovim by running
:help typewriter
. - API Documentation: For developers looking to integrate with Typewriter.nvim, check out our API wiki article.
- State Tracking: Learn about the new state tracking functionality in our State Tracking wiki article.
- Home: Overview
- Commands
- Demos
- Enable Notifications
- Enabling Horizontal Scrolling
- Help Documentation
- Installation Guide
- Integration Guide
- Media
- State Tracking
- Tree‐sitter Integration for :TWCenter Command
- TW
keep_cursor_position
Feature - Typewriter.nvim API
This plugin was inspired by:
Special thanks to the following for their inspiration and ideas:
- The Reddit post "Typewriter Scrolling".
- The Obsidian plugin "Typewriter Mode".
- JotterPad Typewriter Scrolling
- Scrivener Typewriter Scrolling
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to open up an issue or a pull request to contribute to the project.