Last active
February 2, 2018 22:43
-
-
Save analogrelay/e5b807b46b4896b35557 to your computer and use it in GitHub Desktop.
My VIM drill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| VIM Drill | |
| ========= | |
| NEVER USE Arrows or Esc! | |
| 1. Type the following: | |
| public class Foo { | |
| public string Property { get; set; } | |
| public int Property { get; set; } | |
| public object Property { get; set; } | |
| } | |
| 2. Use "/" and "n" to prefix each property with the type | |
| public class Foo { | |
| public string StringProperty { get; set; } | |
| public int IntProperty { get; set; } | |
| public object ObjectProperty { get; set; } | |
| } | |
| 3. Use "/", "n" and "dE" to delete the "Property" suffix | |
| public class Foo { | |
| public string String { get; set; } | |
| public int Int { get; set; } | |
| public object Object { get; set; } | |
| } | |
| 4. Use "%s/Find/Replace/g" to change public to internal | |
| internal class Foo { | |
| internal string String { get; set; } | |
| internal int Int { get; set; } | |
| internal object Object { get; set; } | |
| } | |
| 5. Convert the properties to fields using per-line "s/ { get; set; }/;/g", "@:" and "@@ | |
| internal class Foo { | |
| internal string String; | |
| internal int Int; | |
| internal object Object; | |
| } | |
| 6. Replace "object" with "decimal" using navigation commands. Start with "gg", use down, w, w, ce | |
| internal class Foo { | |
| internal string String; | |
| internal int Int; | |
| internal decimal Object; | |
| } | |
| 7. Suffix the "Object" property with "1" | |
| 8. Create 4 more "ObjectN" properties with the same name with "Y" and "p" | |
| internal class Foo { | |
| internal string String; | |
| internal int Int; | |
| internal decimal Object1; | |
| internal decimal Object2; | |
| internal decimal Object3; | |
| internal decimal Object4; | |
| internal decimal Object5; | |
| } | |
| 9. Rename them to Decimal1 through Decimal5 using "r<Number>" to change numbers and "c6l" to change names | |
| 10. Delete Decimal1-4 in one command using "d4d" | |
| 11. Rename Decimal5 to Decimal without entering insert mode using 'x' | |
| 12. Reorder the fields from shortest line to longest using "dd" and "P" | |
| 13. Convert back to properties using recording: | |
| a. Go to middleish of a field line | |
| b. type "qa" to start recording in the "a" register | |
| c. use "$C" to remove the trailing semicolon and begin inserting | |
| d. type " { get; set; }" | |
| e. <C-C> "q" to stop recording | |
| f. Move to next field, use "@a" to replay | |
| g. Again | |
| 14. Open a new split and move the code there | |
| a. C-w n | |
| b. C-w j | |
| c. ggvG to select whole buffer | |
| d. d | |
| e. C-w k | |
| f. p | |
| 15. Close the old split | |
| a. C-w j | |
| b. :q! | |
| 16. Put the property suffixes back | |
| a. Go to the first field line | |
| b. use e to get to the end | |
| c. use "aProperty<C-C>" to insert | |
| d. use down and e to position at the end of the next field's name, use '.' to repeat | |
| e. again | |
| 17. Remove all visibilities | |
| a. gg | |
| b. dw | |
| c. +. until done | |
| 18. Prepend a comment | |
| a. gg | |
| b. O | |
| c. // Comment | |
| These remaining steps require the "vim-surround" plugin. I stopped using it because it doesn't work in VsVim | |
| 19. Use vim-surround to change "{" to "[" by highlighting somewhere in the center of a property definition (between the "{") and using "cs{[" to change surrounding "{" to "[" | |
| 20. Delete all delimiters using "ds<Delim>" | |
| DONE! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment