• Hexarei@programming.dev
    link
    fedilink
    arrow-up
    48
    arrow-down
    4
    ·
    9 months ago

    The biggest benefit of (neo)vim is the motions.

    Honestly if you don’t use vim motions in your ide of choice, you’re missing out big time. Being able to do things like “Delete everything inside these parentheses”. di( or “wrap this line and the two lines below in a pair of {}” ys2j{ , or “swap this parameter with the next one” cxia]a. with a single shortcut is game changing.

    Even just being able to repeat an action a number of times is ridiculously useful. I use relative line numbers, so I can see how many lines away a target is and just go “I need to move down 17 lines” and hit 17j.

    Absolutely insane how much quicker it is too do stuff with vim motions than ctrl-shift-arrows and the like.

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      47
      arrow-down
      5
      ·
      9 months ago

      Honestly those things just don’t sound like common enough actions to be worth shaving 0.5 seconds off. How often do you know exactly how many lines to move a line by? And how often do you even need to move a line that far?

      I still don’t buy it.

      • pearable@lemmy.ml
        link
        fedilink
        arrow-up
        18
        ·
        9 months ago

        Relative lines means each line except the one your cursor is on is relative to your current line. Like this:

        5 5k jumps here

        4

        3

        2

        1

        6 your cursor is here

        1

        2

        3

        4

        5

        6

        7

        8 8j jumps here

        The main reason I like it is I don’t like mouse ergonomics. Keeping my hands on the keyboard just feels better

        • FizzyOrange@programming.dev
          link
          fedilink
          arrow-up
          14
          arrow-down
          11
          ·
          9 months ago

          Yes I understood that. My point is how often do you know you need to move a line exactly 17 lines? Do you count them? Clearly much slower than doing it interactively by holding down ctrl-shift-down for a bit.

          • pearable@lemmy.ml
            link
            fedilink
            arrow-up
            15
            ·
            edit-2
            9 months ago

            I just look at the line number. If the code I want to edit is 17 lines up there’s a 17 next to it. My ide window looks like my comment. Normally an ide would look like this

            1

            2

            3

            4

            5

            6

            7

            8

            9

            10

            11

            • lunarul@lemmy.world
              link
              fedilink
              arrow-up
              3
              ·
              9 months ago

              As a vim user myself, I don’t understand why you need relative lines either. I can just as easily type :23 to go to line 23.

              • pearable@lemmy.ml
                link
                fedilink
                arrow-up
                1
                ·
                9 months ago

                Mostly a matter of taste I think. One benefit is one less key press since relative keys shouldn’t need to press enter at the end of the command. I mostly use it because it came default with LazyVim.

            • FizzyOrange@programming.dev
              link
              fedilink
              arrow-up
              2
              arrow-down
              1
              ·
              9 months ago

              Line numbers are absolute, not relative (normally anyway; I think some editors allow showing relative line numbers). Anyway I think holding down (page) up/down is going to be just as fast.

              • mexicancartel@lemmy.dbzer0.com
                link
                fedilink
                English
                arrow-up
                3
                arrow-down
                1
                ·
                9 months ago

                There are both modes for absolute and relative line numbers in vim. Holding up/down might be intuitive nd easy to remember, but saving 1 second everytime you need to do this can add up pretty fast

      • Hexarei@programming.dev
        link
        fedilink
        English
        arrow-up
        3
        arrow-down
        1
        ·
        9 months ago

        Not “move the current line of code”, but instead “jump the cursor a number of lines”

        • FizzyOrange@programming.dev
          link
          fedilink
          arrow-up
          2
          arrow-down
          4
          ·
          9 months ago

          Oh so like page up/down then? Not exactly showing the raw power of Vim when you can use an existing key press! 😄

          • Hexarei@programming.dev
            link
            fedilink
            arrow-up
            7
            arrow-down
            1
            ·
            9 months ago

            I can’t tell if you’re trolling; Page up and page down are different from “I need to jump 10 lines down” with 10j. Or 11 lines with 11j. Or “Delete the line I’m on and the six below it” with d6j.

    • Potatos_are_not_friends@lemmy.world
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      9 months ago

      Honestly if you don’t use vim motions in your ide of choice, you’re missing out big time. Being able to do things like “Delete everything inside these parentheses”. di( or “wrap this line and the two lines below in a pair of {}” ys2j{ , or “swap this parameter with the next one” cxia]a. with a single shortcut is game changing.

      I read things like this and feel like I do a different type of coding than everyone else does. I’m not generating code at this speed.

      • niemcycle@lemmy.world
        link
        fedilink
        arrow-up
        5
        arrow-down
        1
        ·
        9 months ago

        Yeah exactly this, the main bottleneck when writing code is either reading the existing code or thinking about how I want to implement some logic, not how I move my cursor and writing the code itself.

    • floofloof@lemmy.ca
      link
      fedilink
      English
      arrow-up
      7
      ·
      edit-2
      9 months ago

      Being able to do things like “Delete everything inside these parentheses”. di( or “wrap this line and the two lines below in a pair of {}” ys2j{ , or “swap this parameter with the next one” cxia]a. with a single shortcut is game changing.

      Those are handy, but most IDEs make at least the second two easy to do without reaching for the mouse (not sure about the first one), and for most people the other conveniences offered by IDEs are pretty attractive. I do use vim when I’m working in the terminal though, because it’s solid and handles large files better than anything else I know.

      • Hexarei@programming.dev
        link
        fedilink
        arrow-up
        4
        ·
        9 months ago

        I have most of the features of an IDE in my neovim config; name a feature and there’s almost certainly a plugin for it!

        Those are just a few small examples. One of my favorite things that vim enables for me is working with text objects. Things like functions, variables, classes, conditionals, paramters… Etc. Any action works with any text object - Want to jump to the next function in the file? Copy everything inside of a conditional? Cut everything up to (but not including) the nearest capital D on the line? Delete just the word your cursor is in the middle of (and one of the spaces around it)? Delete the current line and the N lines below it?

        The motions make editing code incredibly fast, and I still have modern features like variable completion, copilot, intellisense, ‘jump to definition’, “hover” information, fuzzy search in project… Name a feature. I highly recommend giving it a closer look for stuff like that.

        • floofloof@lemmy.ca
          link
          fedilink
          English
          arrow-up
          2
          ·
          edit-2
          9 months ago

          That does sound pretty good, and all without an IDE that hangs several times a day too. I haven’t really taken advantage of vim’s power.

    • shalva97@lemmy.world
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      9 months ago

      For me that’s not how it works. there is no way to escape mouse. People use Jira, Figma, Charles, lots of different software that just doesn’t have support for Vim like keys.

      Vim is good at editing a single file at a time. In my case I do like 95% reading and 5% editing. Most of the time there are bugs to fix, in a day I might read 20-30 files and change 5 lines in 5 different files.

      now add one more detail. None of my coworkers know Vim so when I ask for help I need to make sure I turn Vim shortcuts otherwise they won’t be able to help.

      you can go on GitHub on any repo and press . you will get vscode in your browser. Did same with my server and after that I just never want to look at Vim. If I have to use cli then I will install micro editor

    • AVincentInSpace@pawb.social
      link
      fedilink
      English
      arrow-up
      4
      arrow-down
      1
      ·
      edit-2
      9 months ago

      Feel it’s worth noting that ys[motion][symbol] is a plugin (vim-surround or nvim-surround at your option) and most IDEs therefore don’t support it

      Also as for plugins, Tim Pope’s vim-argumentative is another one I love. “Swap this parameter with the next one” is >, and “swap this parameter with the previous” is <,

      • Hexarei@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        9 months ago

        Ah right, I forget that that one is from vim-surround. Though I know some ides do support somewhat custom vim-configs!

        I didn’t know about argumentative, my swapping is powered by Tree-Sitter