Skip to content

Do you often find yourself caught off guard idling in Insert mode instead of escaping to Normal mode like a true Vim user? Let this help you train yourself out of the bad habit. It also boots you out of Insert mode after certain amount of seconds of inactivity

License

Notifications You must be signed in to change notification settings

csessh/stopinsert.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro

stopinsert is a vim command (see vimdoc) that works like hitting <Esc> in Insert mode.

This plugin automatically kicks you out of Insert mode after certain amount of time of inactivity.

Installation

  1. Let your favourite package manager do the work:
-- lazy.nvim
{
    "csessh/stopinsert.nvim",
    event = { "InsertEnter" }, -- lazy load
    dependencies = {
        -- "hrsh7th/nvim-cmp",
        "saghen/blink.cmp",
    },
    opts = {
        -- Configuration options (see Configuration section below for details)
        idle_time_ms = 5000, -- Maximum time (in milliseconds) before you are forced out of Insert mode
        show_popup_msg = true, -- Enable/disable popup message
        clear_popup_ms = 5000, -- Maximum time (in milliseconds) for which the popup message hangs around
        disabled_filetypes = { -- List of filetypes to exclude the effect of this plugin.
            "TelescopePrompt",
            "checkhealth",
            "help",
            "lspinfo",
            "mason",
            "neo%-tree*",
        },
        guard_func = function() -- Optional function that returns a boolean. If true, prevents stopinsert.
          -- return require('cmp').visible_docs()
          return require("blink.cmp").is_documentation_visible()
        end,
    }
},
  1. Setup the plugin in your init.lua. This step is not needed with lazy.nvim if opts is set.
require("stopinsert").setup()

Configuration

Items Type Default Value Description
idle_time_ms number 5000 (5 seconds) Maximum time (in milliseconds) before you are forced out of Insert mode back to Normal mode.
show_popup_msg boolean true Enable/disable popup message
clear_popup_ms number 5000 Maximum time (in milliseconds) for which the popup message hangs around
disabled_filetypes list { "TelescopePrompt", "checkhealth", "help", "lspinfo", "mason", "neo%-tree*", } List of filetypes to exclude the effect of this plugin.
guard_func function nil Optional function that returns a boolean. If true, prevents stopinsert.

NOTE: By default, stopinsert.nvim excludes a list of filetypes, as shown in the table above.

If you configure this attribute in opts with your package manager, like so, your list will replace stopinsert.nvim defaults.

Filetypes can also be listed as regex, such as neo%-tree*.

User command

stopinsert.nvim is enabled by default. You can toggle its state on the fly with the following commands:

:StopInsertPlug enable
:StopInsertPlug disable
:StopInsertPlug toggle
:StopInsertPlug status

Each of them does exactly what it says on the tin. When the plugin is disabled, any pending idle timer is cleared so you won't be forced back to Normal mode.

Contribution

All contributions are most welcome! Please open a PR or create an issue.

Coding Style

  • Follow the coding style of LuaRocks.
  • Make sure you format the code with StyLua before PR.

Testing

Run the test suite with plenary.nvim installed. From the project root execute:

make test

This command uses plenary.busted to run the specs found in the tests/ directory.

About

Do you often find yourself caught off guard idling in Insert mode instead of escaping to Normal mode like a true Vim user? Let this help you train yourself out of the bad habit. It also boots you out of Insert mode after certain amount of seconds of inactivity

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •