Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Increment duplicates is just one of many, many utilities that pairs well with multiple carets.

Formatting is another.

Boilerplate code, for example today I had to implemented code like this:

    impl Into<Node> for ProcessNode {
      fn into(self) -> Node {
        Node {some_boilerplate(self)}
      }
    }
I had 6 node types. Using multiple cursors I:

* Implemented it once

* Duplicated it 5x

* Copied the names of the types I needed to impl for

* Attached a cursor to each impl

* Used ctrl + left/ right to word-jump, and past in the appropriate area

Now it's not like this saved me more than a minute or two, but this sort of thing is extremely common in my experience, across languages.



Or you could write a macro?


That sounds like considerably more work.


In Vim (on Unix), type this into the buffer

  for x in type1 type2 type3 type4 type5 type6 ; do
    cat <<!
      impl Into<$x> for ProcessNode {
        fn into(self) -> $x {
          $x {some_boilerplate(self)}
        }
      }
  !
  done
Now do a line-oriented visual select of all the lines from for to done (using V + cursor movements). Then pipe to shell with !sh[Enter].

Poof! The above is replaced with the following:

      impl Into<type1> for ProcessNode {
        fn into(self) -> type1 {
          type1 {some_boilerplate(self)}
        }
      }
      impl Into<type2> for ProcessNode {
        fn into(self) -> type2 {
          type2 {some_boilerplate(self)}
        }
      }
      impl Into<type3> for ProcessNode {
        fn into(self) -> type3 {
          type3 {some_boilerplate(self)}
        }
      }
      impl Into<type4> for ProcessNode {
        fn into(self) -> type4 {
          type4 {some_boilerplate(self)}
        }
      }
      impl Into<type5> for ProcessNode {
        fn into(self) -> type5 {
          type5 {some_boilerplate(self)}
        }
      }
      impl Into<type6> for ProcessNode {
        fn into(self) -> type6 {
          type6 {some_boilerplate(self)}
        }
      }
Don't write in some insane boilerplate-driven programming language in the first place. Anyone proliferating this kind of duplication (whether with multi-cursors or shell here docs or any other way) should be flogged.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: