joshuadanpeterson / typewriter.nvim

A Neovim plugin that emulates a typewriter, keeping the cursor centered on the screen for a focused writing experience.
MIT License
23 stars 0 forks source link
cursor focus-mode neovim neovim-plugin zen

Typewriter ✍️

Dotfyle Plugin License: MIT GitHub Release Version GitHub Release Date GitHub Code Size GitHub Issues GitHub Pull Requests GitHub Commits Since Latest Release GitHub Language GitHub Stars GitHub Forks GitHub Contributors GitHub Last Commit


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. πŸ“βœ¨

Features ✨

TWCenter Demo πŸŽ₯



TWTop/TWBottom Demo πŸŽ₯



Horizontal Scrolling Demo πŸŽ₯

Installation πŸ”§

Dependencies πŸ“¦

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 = {}
    },
})

Commands

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.

Supported Filetypes/Languages 🌐

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.

If you don't see your filetype supported, propose it via issue or a pull request!

ZenMode and True Zen Configuration

ZenMode 🧘

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 🧘

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.

Packer

-- ~/.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)

Lazy.nvim

-- ~/.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 = {}
    }
})

Documentation πŸ“š

Typewriter.nvim now comes with comprehensive documentation to help you make the most of its features:

Wiki πŸ“š

Inspiration πŸ’‘

This plugin was inspired by:

Credits πŸ™

Special thanks to the following for their inspiration and ideas:

License πŸ“„

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing 🀝

Feel free to open up an issue or a pull request to contribute to the project.