469 points · by kawera · 8y ago · 270 comments
- In the Git view, select a modified file, select some lines of code you modified, cmd shift P, Git: Stage Selected Ranges. I dropped my dedicated Git GUI since I know this trick.
- If you spend a lot of time coding in React, and have half of your files named index.js, do yourself a favor, go in the settings and add "workbench.editor.labelFormat": "short" (display the name of the file's folder in all the tabs)
- You can preview markdown files natively (button at the top right corner).
- Real time collaborative development: https://marketplace.visualstudio.com/items?itemName=MS-vsliv...
Re the git stuff though- one place that I'm pretty sure emacs is the uncontested champ is in git integration via magit. I'd be inclined to recommend using emacs as their git interface even to people who want to use a different interface for everything else. It is that good, and IMHO the only git porcelain that is strictly better than the standard git porcelain.
Evil-mode solves that, and just as magit is better than git evil-mode seems, to me, better than vi. Emacs is better than ever (though you do need to use auto-formatting for languages like JS that change a lot- there is no emacs mode that has kept up with ES whatever. Luckily emacs makes it easy to use formatters like prettier on a per-buffer basis.)
But that said - it does it's job very well and magit is certainly excellent software for those that are interested in that interface.
But when it comes to magit I'm not so sure. I'm inclined to think that magit is _strictly_ better than any other git interface, so much so that even if you don't like emacs you should suck it up and use magit as your git porcelain, even if you use a different editor for everything else. Magit is that good- I just gave $100.00 to the project, and I never donate to open source stuff. It is that good.
Others, such as myself, suffer it only when compelled by an instructor.
tig status=> 1 to stage line, u to stage a hunk, \ to split hunks, ! to revert get() {
return new Promise((resolve, reject) => {
fetch(`${baseAPI}/heroes`)
.then(response => response.json())
.then(json => resolve(json))
.catch(err => {
reject (err);
});
});
}
Why not just: get() {
return fetch(`${baseAPI}/heroes`)
.then(response => response.json());
} function fetchPost(uri, body) {
return new Request(uri, {
method: 'POST',
mode: 'cors',
headers: {
'Authorization': 'token 123412341234'
},
body: JSON.stringify(body)
})
}
function fetchStatus(response) {
return response.ok ? Promise.resolve(response) : Promise.reject(new Error(response.statusText));
}
fetch('https://httpstat.us/500')
.then(fetchStatus)
.then(function(result) {
console.log(result)
})
.catch(function(err) {
console.log('BAD:', err)
});
https://medium.com/@luminarious/i-was-trying-out-fetch-liter... async get() {
const response = await fetch(`${baseAPI}/heroes`);
return response.json();
} async get () {
return await (await fetch(`${baseAPI}/heroes`)).json()
}(Option)Alt-Cmd + Down or Up arrow key
From there, you can use arrow keys as normal, but instead of controlling one carrot, you control all the ones you created. So if I use the shortcut key to move to the next word, they all do, same with end of line, or what have you. In the past I had to use regex in my editors to extract quoted text in each line... now I just use multi-select. Each carrot can also be created with the mouse in the Selection menu.
Edit: Apparently it's a feature lifted from Sublime and in other IDEs - thanks!
Multicursor is amazing.
One thing it's been great for:
I have code like:
byte b1 = array[0];
And I want to do this for 16 bytes. Control + D to duplicate 15x. Double tap control, hit up 15 times - now there's a cursor at every row. Hold control, hit right (jump by word), index to end of 'b1' on each line. Ctrl + shift + a, 'increment duplicates' - now every line is 1, 2, 3, 4... 16. `ctrl + right` my way to the index key and do the same thing.
It's awesome.
edit: I just found 'duplicate and increment' :o
You must do some kind of programming I've not encountered in my many years. While my editor of choice can do this, I would have no idea how, because a feature like "increment duplicates" is needed so infrequently that I would never remember the shortcut.
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.
I've been using it in editors since well before VSCode existed. It's very nearly a requirement for me to use an editor now.
For your example, this is the kmacro I ended up with:
;; Keyboard Macro Editor. Press C-c C-c to finish; press C-x k RET to cancel.
;; Original keys: 2*M-f M-DEL b C-x C-k TAB C-a 2*C-k 2*C-y C-p
Command: last-kbd-macro
Key: none
Macro:
2*M-f ;; forward-word
M-DEL ;; backward-kill-word
b ;; self-insert-command
C-x C-k TAB ;; kmacro-insert-counter
C-a ;; move-beginning-of-line
2*C-k ;; kill-line
2*C-y ;; yank
C-p ;; previous-line
(after you've created a macro, you can get the above by doing M-x kmacro-edit-macro.) YP<Ctrl-A>l<Ctrl-A>
That can be recorded into a register (say "a") with qaYP<Ctrl-A>l<Ctrl-A>q
then replayed with @a, and further repeated with @@.This is nothing new; I was doing this in Vim 20 years ago.
That and arbitrary window splitting (split any pane horizontally or vertically) are two features I really miss when they're not present. The latter's surprisingly hard to find; Sublime and VS Code don't do it (Atom does).
I've had issues in IDEs where they have shitty implementations of multicursor that break that example.
Super handy when you want multiple cursors to line up at the start of every line (by default vscode will wrap the cursor around to the end of the longer lines if you try to move around with the arrow keys).
There's about 20 other extensions I routinely use, which I documented at https://nickjanetakis.com/blog/switching-to-vscode-from-subl....
Additionally, there is a case where if you don't select the last line until the end, you end up in a state where the last cursor is already at the beginning. If you press "Home" now, you end up having that last cursor at the beginning of the line - and the other ones at the indentation level (see https://github.com/Microsoft/vscode/issues/14919#issuecommen...)
(Disclaimer: Author of the mentioned plugin, so I am heavily biased against my own workflow and saving-keypresses-obsession :P)
Pressing home doesn't always put you at the true beginning of the line. It will put you at the first non-whitespace character.
https://visualstudio.uservoice.com/forums/121579-visual-stud...
"keyboard.dispatch": "keyCode"
and see if it helps.Still found 2 useful things for me, Parens colorizer and settings sync via Github Gist.
I'm also using it as my main editor on my Windows box at home where don't do serious development.
My only real annoyance is that I seem to run into multiple addons that can't be properly installed for one reason or another and sometimes "Ignore this" doesn't work and then the popup gets stuck and you can't see the top three lines...
Apart from that it's been really nice for Rust, Go, and Python.
The newest version has smaller popups on the bottom-right of the window, and that was a nice surprise for me.
What is your setup? Is it system wide or do you configure it manually for each project/workspace/folder?
I'm early on in evaluating ElixirLS and vscode-elixir but have run into some issues with both.
(And FWIW, I have used Jetbrains products before I used VS Code.)
But the costs are more than offset by the benefits. I didn't realize how much of a cognitive burden thinking about formatting was until I stopped thinking about it, and it turns out that using formatting to signal intent is perilous when people don't agree on how formatting signals intent.
I'm pushing to have Prettier used across all our JS code- there is some resistance to the idea of running it across a several hundred k line non-prettified codebase and some resistance to the idea of using it at all. And this causes problems. Prettier is best when you use it for everything.
But I'm pretty sure we'll eventually just move to prettification. It seems like the right thing to me, and I'm generally right ;). Anyway, thanks for Prettier- I am not actually a huge JS fan despite mostly writing it professionally, but Prettier does away with some of my complaints about JS, and just generally makes my life easier.
I do prefer adding a .prettierrc to projects, though, instead of inside vscode options (user or project) like what is suggested here. That way my teammates and I can use the same settings, even if they don't use vscode.
Thank you
The cognitive load it costs to worry and fret about code formatting....
(thank you)
Add this to your settings:
``` "search.location": "panel", ```
Not perfect, but it's a start.
https://marketplace.visualstudio.com/items?itemName=adammara...
I've always wished this key at least had an LED indicator along with Caps Lock.
One thing I'd like from the past is a blinking block cursor.
Can you explain the exact scenario you use it in, I honestly can't think of a scenario where insert is useful.
It hasn't been updated in over a year, but I've yet to have any issues with it.
Want to collect all values of something as your code runs? conditional breakpoint: `x = (x || []).append(val)` and then print it whenever you feel like it. Log breakpoint? spit it out each time and... browse by hand? hope nothing's logged in between? bah.
>Teach people to use the conditional breakpoint and just enter `console.log(...)` instead, it's overwhelmingly more powerful.
If you're going to print things for insight at breakpoint time, wouldn't it make more sense to just use watch expressions?
But very frequently yes, all you need is a breakpoint and an expression, and hit "continue" a few times. I absolutely do that when I can.
---
As to "just a wrapper for console.log", yes. It's a bit of an infection, though I'm not seeing as many as I used to, so maybe we're fighting it off. but e.g.:
jetbrains has stuff like "evaluate and log": https://www.jetbrains.com/help/phpstorm/configuring-breakpoi...
Visual Studio has "condition" and "action" options for breakpoints: https://msdn.microsoft.com/en-us/library/5557y8b4.aspx one of which is "log a message": http://www.visualmicro.com/page/User-Guide.aspx?doc=Working-... (mindlessly copying this UI, because what VS does is Good™ (it generally is!), used to be more common from what I can remember)
even Chrome [1] and MDN [2] refer to conditional breakpoints, but only mention "will stop when condition is true", not "by the way you can mutate state in here, call funcs, anything you like".
[1]: https://developers.google.com/web/tools/chrome-devtools/java...
[2]: https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_...
---
It's oddly crippling to not know this kind of stuff. Ever had a bug, and you wanted to see how it would behave if var X was the right value? You can just override it in a conditional breakpoint and "fix" the bug without rebuilding, to see what happens.
Thankfully there are at least a handful of people who have realized this, despite docs essentially never calling it out: https://davidwalsh.name/debugging-conditional-breakpoints
In many languages, a debugger is very nearly a REPL. Wish Java would have a REPL? Sure, a simple CLI command would be nice, but I've done "live" coding of android apps for years. Just add a periodic callback to the main thread with a disabled breakpoint - once there, modify your views in the expression editor, and your app - on your phone - updates in the very next view tick. There are limitations, like (kinda) not being able to import new things, but they're not hard to work within and the time savings can be immense.
No. This stance is complete nonsense. People who don't want to learn how things work won't learn either way, but an IDE can at least make them safer and more productive. For people who do, an IDE can magnify your abilities quite a lot. All of which is true for any (decent[1]) tool in any field.
[1] here, have a twitter rant. You're advocating for the Hole Hawg: https://twitter.com/myrrlyn/status/980148201456943104
I get that it's not for everybody but being so against it is something I really do not understand.
Why use color schemes or different fonts at all then?
It's a simple package, but it works very well.
I have got to check out the docker features as well.
I really like VSCode. MS is innovating in UX.
It keeps getting better and better and better month by month and it now even knows how to fix small stupid mistakes like a missing this. when trying to access a field in ts etc.
Well, maybe it’s my extensions that made it slow.
That said I wish somebody would make an IDE that would tightly integrate IPython so I could get IDE autocompletion in a paused test. I spend way too much time writing code in IPython prompts and copying it back.
Edit-to-add: with your downvote you are invited to explain why/if I'm wrong.
A: No.
Long A: Org-mode is plain text. So it org-modes, but not in a meaningful way.
https://github.com/ajtoo/vscode-org-mode
I've used it over Emacs for simple use cases without any real issues, and the project's under very active development.
<body>
<div id=app></div>
<script type=text/javascript src=/static/js/manifest.14a76fad9b304f57d579.js></script>
<script type=text/javascript src=/static/js/vendor.ffa8aef8ba29f634abaf.js></script>
<script type=text/javascript src=/static/js/app.08230312c2e739a44ea1.js></script>
</body>
Web developers: Please, you can do better than this.Front-end developers don't tend to view the web with NoScript. Just like 99% of users don't view the web with NoScript.
I'm a back-end developer, but, when I wanted to indent that HTML in order to post it, I switched over to the instance of vscode that I virtually always having running in order to use its pretty printer.
1 out of 15 examples (the Docker one) don't involve HTML or JS. (And backend JS devs are generally pro-JS so likely aren't using NoScript either).
Do you use NoScript? Maybe you do and you're the <1%, but fact is even if you do, both you and GPP turned it off to view the site already ...
I'd replace the snark with additional details so the author could attempt to reproduce your issue.
"Websites should not unnecessarily require JavaScript."
That a simple document with embedded videos "needs" js to load at all is sheer lunacy. The modern web is a massive house of cards. I don't want to be uncivil but I find it very hard to understand how anyone thinks they're doing good work after they create a simple (and useful!) web document that requires javascript to load.
If you're using Javascript to make a web application, fine, clearly there's no reasonable alternative. But if you need Javascript to produce a web document, what are you doing? I wonder how much more electricity is being consumed annually processing utterly pointless Javascript.
Not to mention the huge accessibility benefits that can come from changing the way a site behaves (not just visually but in terms of things like tab and focus behaviour or separating components out) for disabled users. Doing that reliably and effectively for all content on all devices is much easier if you can identify the needs before downloading the content which means JS-loaded content and so it can come down to deciding whether to annoy NoScript users or disabled users.
> JS is a big security/privacy risk.
No, 3rd party JS (and 3rd party cookies, JS regardless) allow you to be tracked. And ad-blockers deal with that. Blocking 1st party JS is of tenuous benefit w.r.t security/privacy.
I do agree that there is no contract saying you should only serve HTML on the web. But still, you can do better than this.
I mean Mozilla's campaign asking users to send complaints to each and every webmaster writing IE5-only sites. It somewhat worked.
Can it not be unresponsive if you have a mechanical disk or a weak CPU?
Ooops, I'll stick to Sublime
I used to feel the same way early in my career. Now I don’t feel the need to be in a rush all the time.
It's usually best if one knows a few different tools designed for different scenarios. Right tool for the job.
Well, it is 2018. Mechanical disks?
Nobody is trying to sell VS Code to you.
Besides, they're still writing in a typed "language" (ts), so it's not like the dynamic language nature of JS that allows the VSCode base code to be developed incredibly quickly.
What really allows them to develop it incredibly quickly is the plugin API -- which allows tons of npm stuff to be ported and tons of JS programmers to create plugins for VS Code. A native statically typed based core would allow for that too. In fact the VSCode team already have moved some VSCode processing to C++ libs exactly for speed (and of course node itself is C++).
Using DOM for the drawing is faster (for a convenience perspective, not execution speed) yes, but with MS resources they could have made a streamlined equivalent that's much faster, more memory efficient, and doesn't have all the baggage of a web rendering engine. In fact, they have several native alternatives lying around they could make cross platform.
As it is, VSCode will ever have the burden of rendering to the DOM.
For what it's worth, the Visual Studio team now releases minor updates roughly every six weeks (including bug fixes and new features), and service updates almost weekly [1]. They also rely quite heavily on user feature requests [2].
[1] https://docs.microsoft.com/en-us/visualstudio/productinfo/vs...
[2] https://visualstudio.uservoice.com/forums/121579-visual-stud...
No, but it would "just be" an open source, MS backed, version of Sublime or TextMate. The concept of Visual Studio is different.
>We would get updates once a year instead of once a month.
The language the core is in is irrelevant as to whenever we would see updates. That's a concern of the release process.
>There are less C++ devs than JS devs.
Not really important, as most of the contributors are MS guys anyway. In fact a single person has made Sublime Text, an editor that offers most of what VSCode offers, with 1/100 the budget and manpower. If only it was Open Source too, or had a few more devs...
How low have we fallen from what programmers were concerned with memory use, and speed, and the right tool for the right job, and so on, and even Emacs was considered bloated...
I'm not saying that it wouldn't have been as successful, but we're here, now, and it is. It's a great product regardless of the fact that it's written with HTML/CSS/JS.