Does anyone know a visual studio keyboard short cut to swap around two sides of a statement?

前端 未结 6 1384
借酒劲吻你
借酒劲吻你 2021-01-04 02:39

Just wondering if anyone knows the keyboard shortcut to swap around two sides of a statement. For example:

I want to swap



        
相关标签:
6条回答
  • 2021-01-04 02:52

    Here's how I would go about doing that without a specific keyboard shortcut:

    • First, select the text you want to modify and replace

      " = " with "                 =               "
      

      (the key here is to add a lot of spaces).

    • If you hold down Alt and use the mouse, you can select a "block" of code. Use this to select only the text on the right side of the equation (it's helpful to add extra white space here in your selection)
    • Use the same Alt + Left-Click combination to select the beginning of the left side (just select a blank area). You should be able to paste text into here.
    • If you added extra white space to the text you just added, just should be able to easily insert an = using the Alt + Click technique. Use the same trick to remove the equal sign that's dangling on the right side of your code block.

    While this might not do exactly what you're looking for, I've found these tricks quite useful.

    0 讨论(0)
  • 2021-01-04 02:56

    I think the following thread is a good place to begin with

    Invert assignment direction in Visual Studio

    0 讨论(0)
  • 2021-01-04 02:57

    The feature is in Resharper. Select the code segment and click the content wizard, which is a pencil icon in the left corner reading View Actions List, then choose Reverse Assignment. It is done.

    0 讨论(0)
  • 2021-01-04 02:58

    Since I was not happy with the answers where I need to enter complicated strings into the Visual Studio search/replace dialog, I wrote myself a little AutoHotkey script, that performs the swaps with only the need to press a keyboard shortcut. And this, no matter if you are in VS or in another IDE.
    This hotkey (start it once simply from a textfile as script or compiled to exe) runs whenever Win+Ctrl-S is pressed

    #^s Up::  
     clipboard := "" ; Empty the clipboard
     Sendinput {Ctrl down}c{ctrl up}
     Clipwait
     Loop, Parse, clipboard, `n, `r  ; iterates over seperates lines
     {   
      array := StrSplit(RegExReplace(A_LoopField,";",""),"=")  ; remove semicolon and split by '='
      SendInput, % Trim(array[2]) . " = " .  Trim(array[1]) . ";{Enter}"
     }
    return 
    

    Many more details are possible, e.g. also supporting code where lines end with a comma

    ...and I can put many more hotkeys and hotstrings into the same script, e.g. for my most mistyped words:

    ::esle::else    ; this 1 line rewrites all my 'else' typos
    
    0 讨论(0)
  • 2021-01-04 03:02

    swap-word is a VSCode extension which sounds like it would do what you want.

    Quickly swap places two words or selections...

    But I'm not sure if it is compatible with VS.

    0 讨论(0)
  • 2021-01-04 03:12

    If you're using ReSharper, you can do this by pressing CtrlAltShift + or

    0 讨论(0)
提交回复
热议问题