Skip to content

Commands

Josh Peterson edited this page Jul 7, 2024 · 1 revision

Overview

Typewriter.nvim provides several commands to control the typewriter mode, allowing you to enable, disable, toggle the mode, and manipulate the view of code blocks as needed. These commands can be used directly in Neovim or integrated into your key mappings for quick access.

:TWEnable

The :TWEnable command enables the typewriter mode, centering the cursor on the screen to create a focused writing experience.

Example Usage:

:TWEnable

:TWDisable

The :TWDisable command disables the typewriter mode, returning the cursor behavior to its default state.

Example Usage:

:TWDisable

:TWToggle

The :TWToggle command toggles the typewriter mode on and off. If the mode is currently enabled, this command will disable it, and vice versa.

Example Usage:

:TWToggle

:TWCenter

The :TWCenter command centers the view around the current code block or function using Tree-sitter. This helps in focusing on the context of the code you are working on by placing the active code block at the center of the screen.

Key Features:

  • Centers the view around significant code blocks, such as functions, loops, classes, and more.
  • Utilizes Tree-sitter for intelligent code block detection, ensuring accuracy across various programming languages.
  • Enhances readability and focus by keeping the relevant code block in the middle of the screen.

Example Usage:

:TWCenter

Use the :TWCenter command whenever you want to bring the current code block or function into focus. This command is particularly useful in long files where the context can be lost as you scroll through the code.

:TWTop

The :TWTop command moves the view so that the top of the current code block or function is at the top of the screen. This is useful when you want to see the beginning of a code block and the following content.

Key Features:

  • Aligns the top of significant code blocks with the top of the screen.
  • Maintains cursor position relative to the code block if configured.

Example Usage:

:TWTop

:TWBottom

The :TWBottom command moves the view so that the bottom of the current code block or function is at the bottom of the screen. This is helpful when you want to see the end of a code block and the preceding content.

Key Features:

  • Aligns the bottom of significant code blocks with the bottom of the screen.
  • Maintains cursor position relative to the code block if configured.

Example Usage:

:TWBottom

Example Key Mappings

You can create custom key mappings in your Neovim configuration to quickly access these commands. Here are some examples of how to set up key mappings for all the Typewriter.nvim commands:

-- 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 Code Block
vim.api.nvim_set_keymap('n', '<Leader>tc', ':TWCenter<CR>', { noremap = true, silent = true })

-- Move Code Block to Top
vim.api.nvim_set_keymap('n', '<Leader>tT', ':TWTop<CR>', { noremap = true, silent = true })

-- Move Code Block to Bottom
vim.api.nvim_set_keymap('n', '<Leader>tB', ':TWBottom<CR>', { noremap = true, silent = true })

In this example:

  • Pressing <Leader>te will enable typewriter mode.
  • Pressing <Leader>td will disable typewriter mode.
  • Pressing <Leader>tt will toggle typewriter mode on and off.
  • Pressing <Leader>tc will center the current code block or function.
  • Pressing <Leader>tT will move the top of the current code block to the top of the screen.
  • Pressing <Leader>tB will move the bottom of the current code block to the bottom of the screen.

By integrating these commands into your workflow, you can easily control when to use the typewriter mode and how to view your code blocks. Whether you're writing long-form content or coding, these commands help you maintain a focused and distraction-free environment while providing flexible ways to navigate and view your code structure.