Hi there - I’m trying to dive into neovim and I can’t figure out how to do a certain thing in visual block mode…

Is there a way to extend a cursor/block column down from a long line through a series of shorter lines such that the short lines extend to meet the cursor (thus letting you enter text all in a column)? All I can seem to get it to do is have the cursor go to the end of each line, leaving a set of entry points staggered over a different column positions.

I think the feature I want is called Virtual Space, but I’m not sure. I am sure, however, that I use this feature extensively in Ultra Edit and Notepad++ (and mssql mgmt studio and visual studio but not vscode!)

Is there an add on? A plugin? (bonus points if the entry points remain highlighted once going into insert mode after the block is selected?) I’ve seen suggestions to try using the ‘virtualedit’ setting, but unfortunately, this doesn’t seem to solve the issue. It only adds text to lines that are already of length greater or equal to the column position of the block selection. Unless I’m missing something.

(Adding a link to a vscode issue begging for the same feature. It might help illustrate the concept. - https://github.com/microsoft/vscode/issues/13960 )

Would be grateful for help here. (bonus points is there’s a way to keep the cursor highlighted after the shift to insert mode…)

  • mrbn@lemmy.ca
    link
    fedilink
    arrow-up
    4
    ·
    10 months ago

    I do not think that this is an existing feature in neovim, however this seems to work :%s/\(.*\)\zs\s*$/\=repeat(' ', 15 - len(submatch(1)))

    Change 15 to the column desired. You could probably create a function where you pass the column number you want so that you dont have to type this string all the time.

    • indigomirage@lemmy.caOP
      link
      fedilink
      arrow-up
      2
      ·
      10 months ago

      Thank you for the response. I’m not sure I’d have any idea how to create a function for this at this point. Lack of support for this feature is pretty much the main reason I’m shifting away from vscode. (Also looking at nvim as I want a more powerful go-to solution for CLI editing…)

      Certainly frustrating - it was my most used feature when I was coding SQL extensively…

      • mrbn@lemmy.ca
        link
        fedilink
        arrow-up
        2
        ·
        10 months ago
        command! -range -nargs=1 PadColumns call PadColumns(<line1>, <line2>, <args>)
        
        function! PadColumns(start, end, columns)
            execute a:start.','.a:end.'s/\(.*\)\zs\s*$/\='.'repeat(" ", a:columns - len(submatch(1)))'
        endfunction
        

        Use by typing in Normal mode :PadColumns 20. This will add spaces after the line or selected lines to the column you specify (in this case, 20).

        You could probably improve this by getting the length of the longest line and so you dont need to specify the specific column to add spaces to (20), and instead just add say 5 spaces after longest line for all lines.

        • indigomirage@lemmy.caOP
          link
          fedilink
          arrow-up
          1
          ·
          10 months ago

          It would be faster to just select every end of line and add spaces and then do the edit & Trim later.

          Bottom line is that the functionality doesn’t seem to exist in any useful way. Wish it did. I think Ultra Edit, notepad++ visualstudio and mssql mgnt studio must have spoiled me for other editors (in this respect). Even Geany does this (but oh, so janky…)