I often miss CTL + M + O, that collapses all properties and methods in the code editor, when working with Xaml.
I installed Xaml Regions and it is nice but I still miss CTL + M + O
I have played around with:
CTL + M + M
CTL + M + L
CTL + M + P
CTL + M + U
But none of them does what I want.
Is there an extension or even a built-in command that does what I want?
To clearify, I want all children of a resource file collapsed to one row for easier navigation like this:
I recently discovered you can use Ctrl+M, L even though it doesn't work directly. It just takes a little algorithm.
Press Ctrl+M, L.
If everything is expanded, press it again.
???
Profit.
Pressing Ctrl+M, L expands everything if anything is collapsed, otherwise it collapses everything. So when you first open a file, pressing it once should be sufficient. If you've been collapsing and expanding some regions, pressing it once to expand and once to collapse works fine.
This may be too off-topic, however using the VSVim add-on will emulate Vim, unifying a lot of keyboard shortcuts for editing files:
The command zc will close a fold (if the cursor is in an open fold), and zo will open a fold (if the cursor is in a closed fold). It's easier to just use za which will toggle the current fold (close it if it was open, or open it if it was closed).
The commands zc (close), zo (open), and za (toggle) operate on one level of folding, at the cursor. The commands zC, zO and zA are similar, but operate on all folding levels (for example, the cursor line may be in an open fold, which is inside another open fold; typing zC would close all folds at the cursor).
The command zr reduces folding by opening one more level of folds throughout the whole buffer (the cursor position is not relevant). Use zR to open all folds.
The command zm gives more folding by closing one more level of folds throughout the whole buffer. Use zM to close all folds.
Edit: Command sequence in this case would be zM then zo.
Related
Can someone please explain to me how the "format selection" (cmd + K cmd + F) shortcut keys - and other shortcuts that seemingly have multiple button press combinations - work in VS Code.
I tried pressing cmd + K and cmd + F simultaneously (though, cmd is listed twice so I am really pressing cmd + K + F in this case) and I have tried hitting them in order. If someone could explain what they mean here, then it would be much appreciated. I am sure it's a simple solution that I have been overlooking for all these years.
The written format for shortcut expressions use the operators '+' (plus) and ' ' (space) to define whether the expressions on each side of the operator should be pressed simultaneously, or sequentially.
'+' represents two keys pressed then held simultaneously, in left-to-right order.
This is the same as typing an uppercase letter using the shift key: Shift+a -> A
' ' represents concatenating the right-hand-side key combo after the left-hand-side combo.
This is the same as typing an uppercase word using the Shift key: Shift+h Shift+i -> HI
In the second example above, note that you can either keep holding Shift, or you can release it and press it again for each letter. The same applies with VSCode shortcuts.
In the case of Format Selection (Cmd+k Cmd+f), Cmd should be held while first k then f are pressed. Pressing k and f together is a different shortcut entirely (Cmd+k+f), as is pressing f and k together (Cmd+f+k). Since the left-hand-side key (Cmd) is the same for both expressions, you don't need to release it between typing the k and f.
To get a better grasp of how keyboard shortcuts are expressed, I'd suggest opening the the VSCode Preferences for Keyboard Shortcuts either using the command palette, or using the shortcut: Cmd+k Cmd+s: (type ks while holding Cmd).
Then activate the Record Keys mode (Alt+K). Now type different key sequences, and it will show you the textual representation in the search bar, along with any shortcuts that match what you typed.
I first do a vimdiff on two files, but they are vertically split, which makes it hard to read. I want to switch to horizontal split. I tried:
control + w then J or h, which doesn't effect at all
I also tried:
command + w, which asked 'Do you want to terminate processes in this tab?'
I got stuck here. What's wrong with me?
This is a regular diff, $ vim -d foo bar, with the foo window active:
Here is how it looks after pressing <C-w>J, that is Control+w then Shift+j:
Notice the active window is now at the bottom.
From the same starting point, here is how it looks after pressing <C-w>K, that is Control+w then Shift+k:
Notice the active window is now at the top.
See :help window-moving.
To split the screen horizontally:
a.) Hit CTRL + w
b.) and then s.
If you want to navigate between the screen:
a.) Hit CTRL + w
b.) and then w.
To exit out of one of the screen:
a.) Go into command mode (i.e. hit ESC)
b.) and quit as usual: :q.
To split the screen vertically, much like splitting horizontally:
a.) Start by hitting CTRL + w.
b.) but then hit v (instead of s).
Navigating between the split screens is the same (CTRL + w + w).
Is it possible to scroll window screen without using control + U or control + D, (or control + F,B,E etc). I am aware that I can use 'j' or 'k', but that is a line by line scroll. I am looking to scroll through a larger chunk of text without using control key. I find it little inconvenient to move from home row. (May be I am thinking too much.)
I am aware that I can use /search or nG to move to a particular line. But sometimes, it is helpful to scroll through the code, without a specific line.
I am using GVim (windows). Thank you.
<C-U> / <C-D> scroll by 'scroll' number of lines. You can emulate that via
:execute 'normal!' &scroll . 'j'
This is too long to type, so you need a mapping, but that probably again would involve a modifier key. For ad-hoc scrolling, just estimate the amount of lines and type 30j.
That said, modifier keys are important in Vim (even if less than in Emacs). Maybe you should consider remapping Ctrl, for example to Caps Lock?
As I wise friend once showed me, you can use L to move cursor to the
bottom of the current window frame. Similarly, you can use H to go to
the top, or M to go to the middle, and also you can then scroll to
center the frame on the cursor location with zz.
With that, you can scroll down with L zt, and up with H zb. Half
scroll with L zz, H zz.
Better yet, if you're using spacemacs, you can use SPC N f or SPC N b to scroll forward and back. Either of which will put you in transient
state, meaning after you enter SPC N f subsequent commands are without
the prefix: f, b, u, d, until you exit the state.
Just wondering if anyone knows the keyboard shortcut to swap around two sides of a statement. For example:
I want to swap
firstNameTextbox.Text = myData.FirstName;
to
myData.FirstName = firstNameTextbox.Text;
Does anyone know the shortcut, if there is one? Obviously I would type them out, but there is a lot of statements I need to swap, and I think a shortcut like that would be useful!
Feel free to throw in any shortcuts you think are cool!
My contribution would be CTRL + E, D - this will format your code to Visual Studio standards! Pretty well known I'm guessing but I use it all the time! :)
UPDATE
Just to let everyone know, using a bit of snooping of the article that was posted, I managed to construct a regular expression, so here it is:
Find:
{.+\.Text = myData\..+};
And replace with:
\2 = \1;
Hopefully people can apply this to their own expressions they want to swap!
I think the following thread is a good place to begin with
Invert assignment direction in Visual Studio
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.
If you're using ReSharper, you can do this by pressing CtrlAltShift + ← or →
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.
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.
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
I recommend using the find-replace option in Visual Studio. IMHO the REGEX string is not that complicated, and moreover, you don't need to understand the expression in order to use it.
The following regex string works for most programming languages:
([\w\.]+)\s*=\s*([\w\.]+)
For Visual Studio's you want to use $ argument in the replace text.
$2 = $1
Make sure to enable regex.
To do this in one shot, you can select a section of the document, and click the replace-all option.
Before:
comboBoxAddOriginalSrcTextToComment.SelectedIndex = Settings.Default.comboBoxAddOriginalSrcTextToComment;
comboBoxDefaultLanguageSet.SelectedIndex = Settings.Default.comboBoxDefaultLanguageSet;
comboBoxItemsPerTransaltionRequest.SelectedIndex = Settings.Default.comboBoxItemsPerTransaltionRequest;
comboBoxLogFileVerbosityLevel.SelectedIndex = Settings.Default.comboBoxLogFileVerbosityLevel;
comboBoxScreenVerbosityLevel.SelectedIndex = Settings.Default.comboBoxScreenVerbosityLevel;
After:
Settings.Default.comboBoxAddOriginalSrcTextToComment = comboBoxAddOriginalSrcTextToComment.SelectedIndex;
Settings.Default.comboBoxDefaultLanguageSet = comboBoxDefaultLanguageSet.SelectedIndex;
Settings.Default.comboBoxItemsPerTransaltionRequest = comboBoxItemsPerTransaltionRequest.SelectedIndex;
Settings.Default.comboBoxLogFileVerbosityLevel = comboBoxLogFileVerbosityLevel.SelectedIndex;
Settings.Default.comboBoxScreenVerbosityLevel = comboBoxScreenVerbosityLevel.SelectedIndex;
IMHO: It's better for a developer to learn to use the IDE (Integrated Development Environment), then to create new tools to do the same thing the IDE can do.
Tried to map it from Preferences -> Settings -> Keyboard, but the "key" combo box has only "forward delete" but no "delete". My keyboard on the other hand has only "delete" and no "forward delete"!
Is there some other way to do it except from the preferences?
Enable option key as meta key
Go to Terminal > Preferences > Profiles > Keyboard
Check Use option key as meta key.
Image
On macOS High Sierra 10.13.6, captured on October 23, 2018.
Notes
Many applications (including bash and tcsh) treat Meta-Delete as "backward delete word."
OS X's terminal runs bash, which includes readline support. Follow Glomek's advice and tell terminal to use option as meta key (or else use Esc) and then you've got a bunch of handy options: Ctrl+w deletes prev word (as does Meta+delete as mentioned), but you can also use Meta+f and Meta+b to walk forward and backwards thru words, Ctrl+a and Ctrl+e to beginning and end of line, Ctrl+k delete (kill) from cursor to end of line, and a bunch more.
See http://www.bigsmoke.us/readline/shortcuts for a nice little reference table.
Delete a word going back:
Ctr-w.
Command Editing Shortcuts
Ctrl + a – go to the start of the command line
Ctrl + e – go to the end of the command line
Ctrl + k – delete from cursor to the end of the command line
Ctrl + u – delete from cursor to the start of the command line
Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + xx – move between start of command line and current cursor position (and back again)
Alt + b – move backward one word (or go to start of word the cursor is currently on)
Alt + f – move forward one word (or go to end of word the cursor is currently on)
Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + u – make uppercase from cursor to end of word
Alt + l – make lowercase from cursor to end of word
Alt + t – swap current word with previous
Ctrl + f – move forward one character
Ctrl + b – move backward one character
Ctrl + d – delete character under the cursor
Ctrl + h – delete character before the cursor
Ctrl + t – swap character under cursor with the previous one
Command Recall Shortcuts
Ctrl + r – search the history backwards
Ctrl + g – escape from history searching mode
Ctrl + p – previous command in history (i.e. walk back through the command history)
Ctrl + n – next command in history (i.e. walk forward through the command history)
Alt + . – use the last word of the previous command
Command Control Shortcuts
Ctrl + l – clear the screen
Ctrl + s – stops the output to the screen (for long running verbose command)
Ctrl + q – allow output to the screen (if previously stopped using command above)
Ctrl + c – terminate the command
Ctrl + z – suspend/stop the command
Bash Bang (!) Commands
Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.
!! – run last command
!blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
!blah:p – print out the command that !blah would run (also adds it as the latest
command in the command history)
!$ – the last word of the previous command (same as Alt + .)
!$:p – print out the word that !$ would substitute
!* – the previous command except for the last word (e.g. if you type _find somefile.txt /, then !* would give you _find somefile.txt)
!*:p – print out what !* would substitute
⌃W (control+W) is not the same thing than meta + delete (ESC+delete if you don't have checked use option as meta key)
meta+delete will treat / _ as word delimiter where ^W will consider space as delimiter.
e.g.
using ESC+Bakcspace on (cursor at the end)
rm /dira/dirb/file1
gives
rm /dira/dirb/
while ^W on the same will give
rm
So it is better to use \033\177 rather than ^W when defining the modifying the terminal profile.
That way you are really mapping ⌥⌫ to what esc⌫ is doing and you keep having ^W to erase word based on space delimiter.
I would love to be able to post an image on how do this but as a newbies I can't.
refer to bouke comment to see how to modify terminal profile.
By default meta backspace does a backwards word yank in most shells. If you press escape and then press backspace, that pretty much works everywhere.
In your Terminal's profile, you can bind ⌥⌫ (option+delete) to ⌃W (control+W), so it works similar to other apps.
If you are using Iterm2 (which is like the regular terminal of OSX just better :)
you can use this like to change this behavior:
You need to set your left ⌥ key to act as an escape character. This can be done going to iTerm2 > Preferences > Profiles > Keys.
With Natural Text Editing preset enabled in Profile -> Keys.
You can simply remove the word
Backward with alt + delete
Forward with fn + alt + delete