Giter VIP home page Giter VIP logo

better-escape.nvim's Introduction

max397574

I am a Student.

max397574

  • ๐Ÿ”ญ I'm currently working on developing neovim plugins.

  • ๐ŸŒฑ I'm currently learning Rust.

  • ๐Ÿค Feel free to give me any tips for any of my projects.

๐Ÿ› ๏ธ Languages and Tools:

Gitย  Luaย  Vimย  Neovimย  Rustย 

๐Ÿ”ฅ My Stats:

GitHub Streak

Top Langs

better-escape.nvim's People

Contributors

antonkesy avatar danilshvalov avatar gbroques avatar max397574 avatar sam-programs avatar sduby22 avatar tamton-aquib avatar xiyaowong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

better-escape.nvim's Issues

Better escape key

Thanks for the plugin it works great!

Just wanna share as an alternative, we could use an escape key "<Esc>`^" to go to where the cursor was last time when insert mode was stopped, instead of a custom function. Because when I trigger an escape mapping at the end of the line, using the recommended escape function key, the cursor goes to the next line after escaping.

Insert Mode

Does it possible to use this awesome plugin for go to insert mode?
By default we are use JK for out from insert mode.
I thins is good idea to use JJ to goin in insert mode.
Thanks.

Save after escape

Hello @max397574 ,

This is not a request, but just an idea that I would find pretty useful:

If this plugin had an after hook config:

mappings: ...,
timeout: ...,
clear_empty_lines: ...,
key: ....,
after_escape: function(mapping, file)
 if mapping == "jk"
...
end,

it would allow for saving after escape. I bet there are other scenarios where this would be useful as well.

Thoughts?

Modified flag when escape without changes in insert

When I enter insert mode and I leave without making any changes, the buffer
is mark as modified and stacks my undo history

I don't know if this is spected behaviour, but on the ocassions when I
accidentaly enter insert mode without making changes it can be a little
annoying

This is my current config

use({
    "max397574/better-escape.nvim",
    event = "InsertEnter",
    after = "nvim-compe",
    config = function()
        require("better_escape").setup({
            mapping = { "jk" },
            timeout = 200,
            keys = "<esc>l",
        })
    end,
})

Adding a FOSS license

Hi, I love and use this plug-in every day. My keyboard's <ESC> has been very neglected since this plug-in released :)! My workplace is cautious about allowing code without a LICENSE file and it'd be a big help if this plug-in could use a FOSS license. I'm sure others in the same position and would appreciate it too. Could a FOSS license please be added if this plug-in is meant for public use? Thank you very much!

Document incompatibility with macros in readme.md

Hi, thank you for the great plugin!

As a new (Neo)vim user, this was one of the first plugins I installed.

Eventually I learned about macros, and was very confused why macros didn't behave as I expected when escaping insert mode.

I later realized it was because of this plugin when searcing the existing issues (I found #21).

Can we document this is the readme.md to inform others before they install this plugin, and hopefully avoid any future confusion for people?

Better move cursor

Hi.
Could you little update your plugin to make it better?
If we are working with arrow keys to make better of change modes, is it possible to add
"hh" and "ll" keys for move cursor to begin/end of line like $ and 0
Its really will be awesome for any who use vim.
And add it in setting like

-- lua, default settings
require("better_escape").setup {
    mapping = {"jk", "jj"}, -- a table with mappings to use
    -- Uncomment next line to enable move cursor to begin/end of line
    --move_mapping = true,
   -- Insert/visual mode after move cursor
   -- move_mode = "visual|insert"

}

Thanks.

Function value for `keys` not working as expected

(also described here)

I tried setting a function to be ran when pressing jk, but it's not working for some reason. What I'd like it to do is basically send <C-e><Esc> when a pum is visible (to close it before escaping, as instructed by coq), and only <Esc> when it's not.

My config is as follows:

require('better_escape').setup({
    mapping = { 'jk' },
    timeout = 200,
    keys = function()
        print(vim.inspect(vim.fn.pumvisible()))
        return vim.fn.pumvisible() and '<C-e><Esc>' or '<Esc>'
    end,
})

Whenever I use jk to leave insert mode, pumvisible()'s output is 0, even when the pum is actually visible (also doesn't matter if I have a completion option selected).

Besides that, in this setup, it's copying the char below the cursor to the cursor position on jk. For example, with | being the cursor in insert mode and [] in normal mode:

print|(vim.inspect(vim.fn.pumvisible()))
return vim.fn.pumvisible() and '<C-e><Esc>' or '<Esc>'

pressing jk copies the n from return

print[n](vim.inspect(vim.fn.pumvisible()))
return vim.fn.pumvisible() and '<C-e><Esc>' or '<Esc>'

Using keys = '<Esc>' works fine tho. If you'd like I can make this a GH issue.

Is it possible to map different mappings with different keys?

require("better_escape").setup {
mapping = {"jk"}, -- a table with mappings to use
timeout = vim.o.timeoutlen, -- the time in which the keys must be hit in ms. Use option timeoutlen by default
clear_empty_lines = false, -- clear line after escaping if there is only whitespace
keys = "", -- keys used for escaping, if it is a function will use the result everytime
-- example()
-- keys = function()
-- return vim.api.nvim_win_get_cursor(0)[2] > 1 and 'l' or ''
-- end,
}

This is my current config.
But I have mapped 'kj' to abort/close nvim-cmp's auto-complete popup menu, so I would be interested in having another mapping
"kj" to support that functionality.

check_characters() sometimes forgets to start_timeout()

First Case

consider the case: we have custom mapping { 'jk', 'kj' }
if we consecutivly press jjk then we won't escape as expected.

explain in detail:

first_table = { 'j', 'k' }
second_table = { 'k', 'j' }

after pressing j, j, both of them are in first_table and second_table and the match will fail.
In this case we should start_timeout() because j is in first_table but we forgot.

Second Case

consider the case: we have custom mapping { 'jk', 'kj' }
we press j, wait 1sec then press kj, we wont escape as expected.

because after we failed at check_timeout() at 'k', we forgot to start_timeout() as 'k' is in first_chars

Interference with completion plugin

If a word/snippet being completed include one of the escape mappings, better-escape will fire off and cut off the completion.
This happened to me with cmp.nvim, but I assume other completion plugins function similarly and therefore will have the same issue.

I am not sure if this is fixable, but it is annoying for Colemak users such as myself who want to keep the popular 'jk' position as an escape binding, as those keys would be bound to 'ne' , which is a common key combination in words such as "new", "clone" and many more.

disable for prompts

It's painful to post j and have results refresh then back to normal. it would be cool if this behavior disabled in prompts

Escape sequences jk & jj delete character before cursor on first use of sequence

This was experienced using AstroNvim, this is the issue and bug report I originally created for them, so all that info is included here.
If this is some sort of collision with something in Astro, I'm not aware of it. Though I was told to submit the issue here.

AstroNvim version

v2.11.8

Neovim version (>= 0.8)

NVIM v0.8.0

Operating system/version

macOS 12.5

Describe the bug

The first time the escape sequence jk is used after opening a file with Astro from the command line without typing anything in insert mode, it will delete the character to the left of the cursor. After the first time, it will work as expected and won't do this.
It won't delete a character if you open another file (eg. in a split window, or in the same window) after already opening the first file. (Eg. if you simply split the window, creating 2 windows of the same file, jk will still delete a character if used)
If you type in insert mode after opening a file and then use jk to go back to normal mode, it will work as expected, not deleting any characters.
It will delete a newline created by o and any additional newlines created by pressing <Enter> afterwards (Clarification note: it will delete ONE newline, but will still delete one if you do o<Enter><Enter>jk for example).

Steps to Reproduce

If you don't want to use a file of your own
NOTE: <SPC f n> is specific to AstroNvim, if you're just using base Neovim, just do nvim

  1. Open up a new file with nvim then <SPC f n> OR nvim nonexistentfilenamehere.txt
  2. Use o<Enter Enter (Any number of Enters as you please)>
  3. Use jk or jj escape sequence
    You should see one of the newlines created by either o or one of your <Enter>s was deleted by the sequence and you have one less newline than expected

To show this works with existing files and characters let's create a test.txt file containing

hello
world

  1. Open up the testing file from the command line with nvim test.txt
  2. You may navigate with HJKL however you may please to put your cursor on the "d" in "world"
  3. ijk or ijj to enter insert mode and use the jk or jj escape sequence
  4. You should see now the file appears as follows
hello
word

  1. You can :q! and experiment with this as you would like, if the cursor is on the "w" of "world", you'll end up with
helloworld

Expected behavior

All uses of the jk or jj escape sequences shouldn't delete any character beyond the first j which is typed from being in insert mode before the escape sequence is triggered.

Inserts char while typing

I stumbled upon this plugin and just gave it a try. I find the insertion of characters quite distracting, especially within longer lines.

Plugin:

plugin-escape

Native:

native-escape

If this is intentional (unavoidable), then feel free to close this issue. Personally I find that more distracting than any strangeness around typing jj or jk, which so rarely happens.

The plugin better-escape.vim should be given its credit.

I saw your plugin from reddit. I think the original idea is from my plugin better-escape.vim, which is implemented in vim script. I understand that a lot of people want to configure their neovim using purely lua, and I think it is a good idea to rewrite the original plugin in lua. However, the original plugin should be given its due credit. I see that the reference of better-escape.vim is remove in this commit.

I am not sure why. Is it intentional or by accident?

README should quickly answer "what does this solve"

Hi! As quick feedback, the README for this repo makes me want to close Chrome because it's not immediately obvious what this plugin does.

You might want to take another read, but pretend you've never heard of the plugin before.

The repository you link out to (https://github.com/jdhao/better-escape.vim) has a better introduction:

A lot of people have been mapping jk or kj or kk to ESC in order to escape insert mode quickly. However, when we press the first key in these mappings, Vim/Nvim will wait for timeoutlen milliseconds before writing this char to buffer. The apparent lag caused by this behaviour is annoying.

Better-escape.vim is created to help Vim/Nvim users escape insert mode quickly using their customized key combinations, without experiencing the lag.

You should have something like that front and center on this project's README. If don't immediately understand a plugin's purpose when browsing the repo, I will often just close the tab and move on. Get people excited about it!

Possible to use in visual mode?

Hi,

I wanted to ask if it would be somehow possible to also escape out of visual mode (or other things that are "cancelled" by pressing Escape) using this plugin

And sorry if that's a stupid question ๐Ÿ˜

Weird interaction with `nvim-cmp`

I just had a case where I use cmp to complete blac into blackjack and instead of inserting nicely its going all over the place. This doesn't happen if I disable better-escape.nvim. I believe that plugin uses TextChanged autocmds to detect the jk input, so perhaps it is triggering in the middle of nvim-cmp feeding the keys in? Is there anything that can be done to prevent this from happening?

Packer update failed due to rebasing

Hey, I just had this problem. Since the latest commit, I was not able to update this plugin using packer (will most likely also not work with vim-plug). The reason seems to be because you rebased the dev branch onto master (not sure what exactly happened, though). For more context on this see this packer issue: wbthomason/packer.nvim#381.

When I checked the status of the Git project locally, I got Your branch and 'origin/master' have diverged, and have 6 and 68 different commits each, respectively..

If someone else has this issue, you can use git pull --rebase in the better-escape.nvim directory.

Just wanted to point this out to you, feel free to close this after reading :)

Error when typing `ini` since the last update

Hey, I just got this error after quickly typing ini in a buffer (I remapped ii to escape).
Previously, everything was working fine.

Error detected while processing InsertCharPre Autocommands for "*":
E5108: Error executing lua ...ck/packer/start/better-escape.nvim/lua/better_escape.lua:22: attempt to call field 'stop_timer' (a nil value)
stack traceback:
        ...ck/packer/start/better-escape.nvim/lua/better_escape.lua:22: in function 'start_timeout'
        ...ck/packer/start/better-escape.nvim/lua/better_escape.lua:104: in function 'check_charaters'
        [string ":lua"]:1: in main chunk

Don't modify file if nothing changes

Do you see a way to avoid "modifying" a file if directly after entering insert mode, the insert mode is left again by using "jk"? Sometimes I enter insert mode but then after some thinking don't changing anything. This will still create an entry in the file undo tree which is unintuitive, I think. Of course, this is not a big issue but still. What do you think?

Thanks,
Daniel

`autoindent` option doesn't work

This behavior is described in vimdoc

'autoindent' 'ai'	boolean	(default on)
			local to buffer
	Copy indent from current line when starting a new line (typing <CR>
	in Insert mode or when using the "o" or "O" command).  If you do not
	type anything on the new line except <BS> or CTRL-D and then type
	<Esc>, CTRL-O or <CR>, the indent is deleted again.

When I press <Esc> the indent is automatically deleted. But when I press kj (my mapping to <Esc>) the indent is still there.

Disable within certain filetypes?

It'd be nice if there was a setting for a condition function to be called to see if the mapping should be "applied". My usecase specifically is disabling it within TelescopePrompts

Mapping 'kj' doesn't seem to work

Not really sure what else do say, but I've put three mappings in my config file, and jj and jk both seem to work, but kj doesn't. Any ideas?

    5 โ”Š   use({
    4 โ”Š   โ”Š   "max397574/better-escape.nvim",
    3 โ”Š   โ”Š   config = function()
~   2 โ”Š   โ”Š   โ”Š   require("better_escape").setup({ mapping = { "jj", "jk", "kj" } })
    1 โ”Š   โ”Š   end,
  32  โ”Š   })

`i_ctrl-a` not working

Hi, nice plugin!

I've noticed a problem: when trying to use ctrl-a in insert mode (see :h i_ctrl-a), it doesn't work as expected.

It should insert the text that you previously inserted, but instead it inserts the text that you previously inserted with the two last characters removed. For example:

  1. Insert the text foobar.
  2. Leave insert mode by using the better-escape shortcut.
  3. Enter insert mode (via o for example).
  4. Press ctrl-a.

Actual result: the text foob is inserted.
Expected result: the text foobar should be inserted.

When repeating with `.`, the cursor ends up in the wrong place

Something about this plugin and the . repeat key is causing the cursor to jump around once you hit the . key.

Repro:

  1. Create a file commits.txt with:
pick 8a8df92 some commit msg
pick 8a8df92 blah blah
pick 8a8df92 another
pick 8a8df92 yes
pick 8a8df92 commits
pick 8a8df92 more
  1. Put your cursor at line 2, column 1, and hit cw to change the word pick. Type s and then jk to exit insert mode.
  2. Move down a line with j and press . to repeat the macro and change pick to s.
  3. The cursor ends up on the line above a few characters from the end.

I have two GIFs showing what happens. The first GIF is with a normal noremap jk <esc>, and the second one is using better-escape.nvim:

With noremap jk esc

As you can see, the cursor stays in place:

normal-jk

With better-escape.nvim

The cursor jumps above one line after repeating with .:

better-escape-jk

Does not work with macros

Whenever entering a new macro that contains an exit with better escape keybinding, the macro does not register an escape but instead enters the keys as is.

e.g.
if mapping == 'jk'
and macro combination entered is this is a test<jk>[o]this is on a newline
where [o] is meant to be a normal mode operation
and <jk> is the exit mapping

expected:
this is a test
this is on a newline

result:
this is a testjkothis is on a newline

is this something wrong with my setup or just the nature of using this plugin for exiting insert mode?

[Feat]: do not change the buffer state after `escape`

After using jk or jj escape from insert-mode, the current buffer is considered to be modified by nvim.

The simple keymapping of escape like inoremap jj <esc> will not change the buffer state.

Can this feature be added throuth some way?

General API for custom escapes

Hi, I'm looking to use this plugin to make custom escapes. As an example, I want to bind 00 in normal mode to go to the end of line, while 0 will go to the start as usual. Is it possible to achieve something like this with this plugin?

will give error if set to `opt = true` in packer.nvim

here is my setup for better escape, if i didn't set to opt true, it still give me error

use({"max39757/better-escape.nvim",
  opt = true,
  event = "InsertCharPre",
  config = function()
    require("better_escape").setup()
  end,
})

it is because my all plugins setup in opt = true ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.