Giter VIP home page Giter VIP logo

Comments (11)

zeertzjq avatar zeertzjq commented on June 26, 2024 1

This breaks the expected behavior of most if not all modern text editors...I hope this could be an easy fix...Many Thnxs!

What "all modern text editors" have a Normal mode?

from neovim.

luisjakon avatar luisjakon commented on June 26, 2024

kovidgoyal/kitty#7191

from neovim.

murtaza64 avatar murtaza64 commented on June 26, 2024

Isn't this behavior expected, matching the behavior of "+p? or are you claiming the behavior differs from "+p in which case I wasn't able to reproduce on iTerm

from neovim.

zeertzjq avatar zeertzjq commented on June 26, 2024

This is the expected behavior.

from neovim.

luisjakon avatar luisjakon commented on June 26, 2024

Hi, thanks! It should be +P when in normal mode as far as i understand...or at least should be configurable somehow...no?

from neovim.

zeertzjq avatar zeertzjq commented on June 26, 2024

If it's equivalent to P instead then it's not possible to paste after end of line, which is much more common.

from neovim.

luisjakon avatar luisjakon commented on June 26, 2024

@zeertzjq thnxs! It is very very common to do this at the beginning (and middle) of a line as well...
is there any possibility to have logic to check what position the cursor + mode the editor is in?
In Insert mode everything works fine. Maybe check the mode and if in normal mode, change to insert mode before pasting or appending? or perhaps there's a better way you can think of since you know best...Many thnxs!

from neovim.

luisjakon avatar luisjakon commented on June 26, 2024

Hi! Incidentally, in visual select mode it also works as expected. Only normal mode is off by one character when not at the end of line...
This breaks the expected behavior of most if not all modern text editors...I hope this could be an easy fix...Many Thnxs!

from neovim.

zeertzjq avatar zeertzjq commented on June 26, 2024

There is a way to achieve this by overriding vim.paste(). To paste before cursor when at the beginning of a line:

vim.paste = (function(overridden)
  return function(lines, phase)
    if
      phase < 2
      and vim.api.nvim_get_mode().mode == 'n'
      and vim.api.nvim_win_get_cursor(0)[2] == 0
    then
      overridden({}, 1)
      debug.setupvalue(overridden, 5, true)
      phase = phase == -1 and 3 or 2
    end
    overridden(lines, phase)
  end
end)(vim.paste)

If you want to do that in the middle of a line as well then adjust the vim.api.nvim_win_get_cursor(0)[2] == 0 condition.

Although note that this solution uses debug.setupvalue(), so it may stop working if Nvim's vim.paste() implementation changes.

from neovim.

luisjakon avatar luisjakon commented on June 26, 2024

You got me on that! : )

from neovim.

luisjakon avatar luisjakon commented on June 26, 2024

Hi! This seems to work with virtualedit = "onemore" enabled.

vim.paste = (function(overridden)
      vim.opt.virtualedit = "onemore"

      return function(lines, phase)
        local eol = vim.fn.col "$"
        if 
           phase < 2 
           and vim.api.nvim_get_mode().mode == "n" 
           and vim.api.nvim_win_get_cursor(0)[2] < eol
        then
          overridden({}, 1)
          debug.setupvalue(overridden, 5, true)
          phase = phase == -1 and 3 or 2
        end
        overridden(lines, phase)
      end
    end)(vim.paste)

I hope other people find this useful. If there is a more practical solution that can't broken or is future-proof please let me know...

Thank you so much for your responses and the great work you all have put in to making this fantastic piece of software.

from neovim.

Related Issues (20)

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.