Raimondi / delimitMate

Vim plugin, provides insert mode auto-completion for quotes, parens, brackets, etc.
http://www.vim.org/scripts/script.php?script_id=2754
1.99k stars 116 forks source link

Backspace key removes extra space #297

Closed ghost closed 3 years ago

ghost commented 3 years ago

I initially asked this here on Vi and Vim Stack Exchange, so please take a look at that for details.

Expected behavior When you press a backspace key, it should remove only one space.

What happens now When you press a backspace key, it removes extra space.

Environment NVIM v0.5.1

That being said, it's absolutely fine to remove extra space when you are inside a matching pair, and remove both leading and trailing space at the same time when you press a backspace key.

Raimondi commented 3 years ago

I can't reproduce it on my end. Could you find a minimal setup that shows the behaviour? maybe that way I'll could reproduce it.

Please, post the output of :DelimitMateTest here to take a look at it.

ghost commented 3 years ago

I'm a Rust programmer so hope it's okay to demonstrate this behavior in Rust file.

Steps to reproduce

  1. Install Rust
  2. Create a directory and a main file(main.rs) with one command cargo new hello. The main.rs file is created inside src directory that is also created with the command.
  3. Go to the hello directory and execute the following command vim src/main.rs. (I mapped the vim command to neovim, so here it is actually executing neovim.)
  4. Inside main.rs, you see the default code Rust created as follows.
fn main() {
    println!("Hello, world!");
}
  1. Under the line println!("Hello, world!");, start typing let hello | <- Here the pipe symbol indicates my cursor and note that there are two spaces between o as in hello and the cursor.
  2. Now the code looks like this.
fn main() {
    println!("Hello, world!");
    let hello  |
}
  1. Now press the backspace key once and see that it removes two spaces instead of one.

Oddly enough, if you stop typing at let hel and add two spaces afterwards and press backspace key, it only removes one space, which is a correct behavior. So, this issue happens depending on where, in a line of code, you press backspace key. To demonstrate this, see the following.

fn main() {
    println!("Hello, world!");
    let hel  |
}

When you press the backspace key at this location, you will see that it correctly removes only one space.

delimitMate Report
==================

* Options: ( ) default, (g) global, (b) buffer

( ) delimitMate_apostrophes = ''
( ) delimitMate_apostrophes_list = []
( ) delimitMate_autoclose = 1
( ) delimitMate_balance_matchpairs = 0
( ) delimitMate_eol_marker = ''
( ) delimitMate_excluded_regions = 'Comment'
( ) delimitMate_excluded_regions_enabled = 1
( ) delimitMate_excluded_regions_list = ['Comment']
( ) delimitMate_expand_cr = 0
( ) delimitMate_expand_inside_quotes = 0
( ) delimitMate_expand_space = 0
( ) delimitMate_insert_eol_marker = 1
( ) delimitMate_jump_expansion = 0
( ) delimitMate_left_delims = ['(', '{', '[']
( ) delimitMate_matchpairs = '(:),{:},[:]'
( ) delimitMate_matchpairs_list = [['(', ')'], ['{', '}'], ['[', ']']]
( ) delimitMate_nesting_quotes = []
( ) delimitMate_quotes = '" '' `'
( ) delimitMate_quotes_list = ['"', '''', '`']
( ) delimitMate_right_delims = [')', '}', ']']
( ) delimitMate_smart_matchpairs = '^\%(\w\|\!\|[£$]\|[^[:punct:][:space:]]\)'
( ) delimitMate_smart_quotes = '\%(\w\|[^[:punct:][:space:]"''`]\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[
( ) delimitMate_tab2exit = 1

( ) g:delimitMate_excluded_ft = ''
--------------------

* Mappings:

i  )            @<Plug>delimitMate)
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 301
i  }            @<Plug>delimitMate}
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 301
i  ]            @<Plug>delimitMate]
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 301
i  (            @<Plug>delimitMate(
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 291
i  {            @<Plug>delimitMate{
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 291
i  [            @<Plug>delimitMate[
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 291
i  "            @<Plug>delimitMate"
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 313
i  '            @<Plug>delimitMate'
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 313
i  `            @<Plug>delimitMate`
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 313
i  <BS>         @<Plug>delimitMateBS
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 330
i  <S-BS>       @<Plug>delimitMateS-BS
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 339
i  <S-Tab>      @<Plug>delimitMateS-Tab
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 354
i  <C-G>g       @<Plug>delimitMateJumpMany
        Last set from ~/.data/plugged/delimitMate/plugin/delimitMate.vim line 359
--------------------

* Showcase:

Open: (|)
Delete: |
Exit: ()|

Open: {|}
Delete: |
Exit: {}|

Open: [|]
Delete: |
Exit: []|

Open: "|"
Delete: |
Exit: ""|

Open: '|'
Delete: |
Exit: ''|

Open: `|`
Delete: |
Exit: ``|

 * Vim configuration:

filetype detection:ON  plugin:ON  indent:ON

--- Options ---
  columns=96          lines=57            scroll=27
  helplang=en         modified            window=56
  runtimepath=~/.config/nvim,~/.data/plugged/delimitMate,/etc/xdg/nvim,~/.local/share/nvim/site,

NVIM v0.5.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT
Compiled by runner@fv-az87-829

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info
--------------------
Raimondi commented 3 years ago

I think it's not related to delimitmate, I removed the mapping and the issue continued, which , along with your comment about the behaviour when the was an extra space, I suspected :help 'softtabstop'. So, I did the following:

  1. Start neovim with `nvim --clean´.
  2. Execute :set sts=3.
  3. Start typing 123 followed by 3 spaces.
  4. Exit insert mode with Esc.
  5. Press a to enter insert mode at the end of the line.
  6. Press Backspace once.
  7. The 3 spaces are deleted together.

You have to exit insert mode after inserting the spaces for backspace to behave that way. You can try changing the value of softtabstop to zero to see the difference.

Is that the behaviour that you were reporting?

ghost commented 3 years ago

If you start neovim with nvim --clean, it doesn't seem to load delimitMate because when I type opening curly bracket { it doesn't insert closing bracket } automatically.

So, I believe what you did was open a file with neovim without delimitMate, which of course solves the problem because there is no use of delimitMate.

Also, the example I used to reproduce this issue was given only using neovim, rust, delimitMate, and no other plugins. So, you can see my init.vim file as follows.

call plug#begin('~/.data/plugged')

Plug 'Raimondi/delimitMate'

call plug#end()

I still believe this is the issue coming from delimitMate. Were you able to reproduce this just like I described in my last comment?

Raimondi commented 3 years ago

I'm sorry, I didn't explain properly. I tried your steps and could reproduce the issue. Then, I executed :DelimitMateOff to remove the mappings, but the behaviour was the same, which suggests is not a delimitMate issue. That's when I used the setup I gave in my previous reply. Please, note that in my case, if I press backspace immediately after inserting the spaces they are deleted one by one, I need to exit insert mode or move the cursor with the arrow keys for the behaviour to appear.

Please, try set sts=0 and combine it with :DelimitMateOff to see if the issue persists. Next, let me know if the behaviour is the same with the setup in my previous reply.

BTW, in delimitMate's test dir is a minimal setup script that I used as vimrc for the tests.

ghost commented 3 years ago

Please note that I did the following inside the Rust file.

I executed :DelimitMateOff to remove the mappings, and the behavior was different for me. It fixed it. After executing it, it only removed one space. However, this means I can not use delimitMate.

:set sts=0 also fixes it. I didn't have to execute :DelimitMateOff to see this. This seems like a great solution. It fixed the issue and I still can use delimitMate. However, placing set sts=0 in my init.vim didn't fix it. So, I have to execute :set sts=0 every time I open a file to fix this behavior.

:set sts=0 combined with :DelimitMateOff also fixes it, but again this means I can not use delimitMate.


Next, let me know if the behaviour is the same with the setup in my previous reply.

I followed your instructions and it gave me the same behavior as yours.

However, when I followed the instructions by starting executing nvim --clean src/main.rs, and followed the rest of the instructions within that Rust file, it only deleted one space.

Raimondi commented 3 years ago

You can set sts in ~/.vim/after/ftplugin/rust.vim to overrule the built-in ftplugin for rust.

The second paragraph in :help ins-softabstop describes the behaviour at hand. Not sure what else could I try to fix it in delimitMate itself.

ghost commented 3 years ago

I think you misspelled :help ins-softtabstop. One more t should be added.

Adding set sts=0 to ~/.vim/after/ftplugin/rust.vim had no effect. However, adding au FileType rust set sts=0 to my init.vim file worked.

Thank you so much for your support.