Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim.current.buffer.append() has inconsistent behavior with vim #8690

Closed
Yggdroot opened this issue Jul 6, 2018 · 9 comments
Closed

vim.current.buffer.append() has inconsistent behavior with vim #8690

Yggdroot opened this issue Jul 6, 2018 · 9 comments
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior
Milestone

Comments

@Yggdroot
Copy link

Yggdroot commented Jul 6, 2018

  • nvim --version:
NVIM v0.2.2
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -I/tmp/neovim-20180209-64704-1ao8lfl/neovim-0.2.2/build/config -I/tmp/neovim-20180209-64704-1ao8lfl/neovim-0.2.2/src -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/neovim-20180209-64704-1ao8lfl/neovim-0.2.2/build/src/nvim/auto -I/tmp/neovim-20180209-64704-1ao8lfl/neovim-0.2.2/build/include
编译者 brew@ElCapitan.local

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

     系统 vimrc 文件: "$VIM/sysinit.vim"
         $VIM 预设值: "/usr/local/Cellar/neovim/0.2.2_1/share/nvim"
  • Vim (version: ) behaves differently? yes
  • Operating system/version: MacOS
  • Terminal name/version:
  • $TERM:

Steps to reproduce using nvim -u NORC

nvim -u NORC

:py import vim
:py print vim.current.window.cursor[0]
:py vim.current.buffer.append('aaa', 0)
:py print vim.current.window.cursor[0]

Actual behaviour

output is: 1, 2

Expected behaviour

vim's output is 1,1

Yggdroot added a commit to Yggdroot/LeaderF that referenced this issue Jul 6, 2018
@justinmk
Copy link
Member

@phodge Is this the same as #7756 ? (why does that issue mention multiple windows?)

@justinmk justinmk added the api libnvim, Nvim RPC API label Jul 10, 2018
@ipod825
Copy link

ipod825 commented Jul 12, 2018

I guess they are related. I mentioned multiple windows because that's how I spotted the issue and didn't try just a single window.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 6, 2018

This looks deliberate. Code is here.

Doesn't seem unreasonable to me that in the given test case neovim should prefer to preserve the position of the cursor on the original line of text, rather than on the original line number.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 6, 2018

Having said that, this code is only imperfectly achieving that aim. Eg consider:

:py3 import vim
:py3 vim.current.window.cursor = (2, 2)
:py3 print(vim.current.window.cursor[0])
:py3 vim.current.buffer[:] = ['shorter', 'buffer', 'contents']
:py3 print(vim.current.window.cursor[0])

which results in the cursor moving from line 2 to line 1, though you'd think that it could have stayed where it was. (This example is, I think, consistent with vim).

@Yggdroot
Copy link
Author

Yggdroot commented Aug 6, 2018

@dimbleby Your example is not the same as mine.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 6, 2018

@Yggdroot - of course! It was a second example.

Apparently I was unclear, so I'll try again:

  • I agree that your example shows neovim behaving differently from vim
  • I'm noting that this deviation actually makes some sense, because trying to keep the cursor on the same line of text that it started on is pretty reasonable - perhaps more reasonable than the vim behaviour of keeping it on the same line number that it started on.
  • But I'm then giving a second example in which IMO neither vim nor neovim does a great job of deciding where the cursor should be after the buffer manipulation.

Make sense?

@ipod825
Copy link

ipod825 commented Aug 6, 2018

I just realized that this issue is different from #7756. This one inserts a line to a buffer while #7756 modifies a line in a buffer. Inserting a line does not move the cursor in a second window viewing the same buffer.

@Yggdroot
Copy link
Author

Yggdroot commented Aug 7, 2018

The inconsistency does not mean wrong. But we should think about that should neovim deviate from vim at this point?

@justinmk
Copy link
Member

justinmk commented Mar 5, 2019

Fixed by #9674.

@justinmk justinmk closed this as completed Mar 5, 2019
@justinmk justinmk added this to the 0.4 milestone Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior
Projects
None yet
Development

No branches or pull requests

4 participants