I am a Student.
-
๐ญ 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.
Escape from insert mode without delay when typing
License: GNU General Public License v3.0
I really love the idea of this plugin, but it only works for me in Insert mode. Is there a way to enable it for Command mode, Visual mode, and Operator-pending mode?
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.
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.
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?
this plugin is awesome
is there any workaround to get same behavior for fish shell with vi mode?
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,
})
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!
I guess vim.defer_fn() won't do this automatically, maybe we should do it ourselves
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?
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.
Hey, great plugin!
I'm working through Practical Vim. The author has an example that assumes the cursor will placed at the end of a change. With this plugin and "jk" as escape, the cursor is placed 2 away from the end.
How to reproduce:"cw{long word}" move to another word ".".
Cheers,
Steve
If you enter insert mode, then immediately press jk
to go back to normal mode, it thinks the buffer is modified because technically it inserted a j
then removed it when you pressed k
.
If the only "changes" were that the j
was inserted and then deleted from the jk
keymap, it should call set nomodified
.
(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.
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.
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.
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
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.
It's painful to post j and have results refresh then back to normal. it would be cool if this behavior disabled in prompts
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.
v2.11.8
NVIM v0.8.0
macOS 12.5
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).
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
nvim
then <SPC f n>
OR nvim nonexistentfilenamehere.txt
o<Enter Enter (Any number of Enters as you please)>
jk
or jj
escape sequenceo
or one of your <Enter>
s was deleted by the sequence and you have one less newline than expectedTo show this works with existing files and characters let's create a test.txt
file containing
hello
world
nvim test.txt
ijk
or ijj
to enter insert mode and use the jk
or jj
escape sequencehello
word
:q!
and experiment with this as you would like, if the cursor is on the "w" of "world", you'll end up withhelloworld
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.
I stumbled upon this plugin and just gave it a try. I find the insertion of characters quite distracting, especially within longer lines.
Plugin:
Native:
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.
Please.
So, deleting the whitespace of an empty line makes you "lose" the last yank. It would be better to use the "black hole register" so the order of the normal registers stays the same.
better-escape.nvim/lua/better_escape.lua
Line 69 in 2bee35e
Replacing 0D
with 0"_D
should do the trick.
How can I use this plugin to escape terminal mode in terminal
I'm using this one
https://github.com/akinsho/toggleterm.nvim
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?
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!
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 ๐
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?
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 :)
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
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
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.
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
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 โ })
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:
foobar
.better-escape
shortcut.o
for example).ctrl-a
.Actual result: the text foob
is inserted.
Expected result: the text foobar
should be inserted.
Something about this plugin and the .
repeat key is causing the cursor to jump around once you hit the .
key.
Repro:
commits.txt
with:pick 8a8df92 some commit msg
pick 8a8df92 blah blah
pick 8a8df92 another
pick 8a8df92 yes
pick 8a8df92 commits
pick 8a8df92 more
cw
to change the word pick
. Type s
and then jk
to exit insert mode.j
and press .
to repeat the macro and change pick
to s
.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:
With better-escape.nvim
The cursor jumps above one line after repeating with .
:
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?
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?
When I'm typing a word and there's popup window for auto-completion, 'jk' does not trigger escape; instead 'jk' itself is entered.
search for esacpe change is to escape
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?
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
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.