In Visual Code (mac) is there a way to start at the second placeholder on a snippet? - visual-studio-code

I love to use snippets in the form of:
println("MyVariable:" + MyVariable);
So I end up creating snippets like this:
SnippetBody:[ "printlns(\"$1:\" + $1);" ]
The problem is that I want the focus on the second $1 so the intellisense triggers. Since the focus is on the first $1 and it's a string, then there is no intellisense.
Thanks!

If all you want is for autocomplete to work on strings, you can look at the settings and set:
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
}
Then you start typing and use CtrlSpace to trigger the list.

Related

how to Suggestion acceptance only using enter and tab

I want to write normally in VSCode for newline, Want to type "e.keyCode" I try to type in new Javascript file only one char "e" and showing "else" suggestion, and when I type "." (dot), the "e" become "else"
In setting already done this.
"editor.suggest.showKeywords": false,
"editor.acceptSuggestionOnEnter": "on",
"editor.quickSuggestions": {
"other": "on",
"comments": "off",
"strings": "off"
}
Add setting for showKeywords and acceptSuggestionOnEnter.
The acceptSuggestionOnEnter is not working,
My question is how to accept suggestion only with enter and/or tab only.?
Thank you.

VS Code Multiple Cursors - Paste Individual Lines Repeatedly

I am using VS Code with VI bindings and I am trying to do the following.
I have the following file contents:
abc="some value"
def="some other value"
ghi="some other other value"
jkl="some other other other value"
.
<etc. for many lines>
I want to make this file change to (Expected Output):
abc=${abc}
def=${def}
ghi=${ghi}
jkl=${jkl}
So far, I have first replaced =.+ with =${. I get the following:
abc=${
def=${
ghi=${
jkl=${
Then I am trying to use multiple cursors in VS Code by Cntrl + Alt + I and I am trying to copy each line from the beginning to paste it so that I get the expected output. For some reason, it isn't letting me select the whole line when I do a Cntrl + Home. Could someone please help me out with this?
For reference: The VI section of my settings.json file is as follows:
// my settings
"vim.easymotion": true,
"vim.sneak": true,
"vim.incsearch": true,
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": true,
"vim.hlsearch": true,
"vim.handleKeys": {
"<C-a>": false,
"<C-f>": false,
"<C-w>" : false,
"<C-x>" : false,
"<C-c>" : false,
"<C-h>" : false,
"<C-b>" : false,
"<C-n>" : false
},
I don't use VI, but this is easy to do with a snippet (in your keybindings.json).
{
"key": "alt+b", // whatever keybinding you wish
"command": "editor.action.insertSnippet",
"args": {
"snippet": "${TM_SELECTED_TEXT/(.*)=.*/$1=${$1}/g}"
},
"when": "textInputFocus && editorHasSelection"
},
Then select your code and alt+b (or whatever keybinding you use). You don't need multiple cursors or need to select each line separately.
Why does it not work with Multi Cursor?
Using the default key bindings.
position cursor before a
use Ctrl+Alt+DownArrow as often as you like
use Shift+Ctrl+RightArrow select all before the =
Ctrl+C
RightArrow 2 times
Shift+End select all after the =
${
Ctrl+V
Esc
Or start selecting =" followed by
Ctrl+Shift+L LeftArrow Shift+Home Ctrl+X RightArrow Shift+End ${ Ctrl+V Home Ctrl+V Esc

Disable intellisense for css classnames in .tsx/.ts files

Whenever I enter a . after a object the autocomplete dropdown contains a lot of unnecessary css classnames as options:
Is it possible to ignore css files for ts/tsx intellisense, so i only get relevant options?
VS Code version: 1.37.1
"[typescript]": {
"editor.suggest.showClasses": false
},
"[typescriptreact]": {
"editor.suggest.showClasses": false
}
Basically the same as Mark's answer but it looks like "editor.suggest.filteredTypes" has been deprecated since VSCode >= 1.40 in favor of settings like "editor.suggest.showClasses".
Try something like this in your settings:
"[typescript]": {
"editor.suggest.filteredTypes": {
"class": false,
}
},
"[typescriptreact]": {
"editor.suggest.filteredTypes": {
"class": false,
}
}
[it would be nice if you could combine these but [typescript, typescriptreact] didn't work for me.
From types of completions it looks like it is class that you want to filter out.
And see create language-specific settings to see how to create settings for specific languages.
You will have to reload vscode to see these changes take effect.

Can't get suggestions in snippets

I have customized one snippet:
"Import for eslint": {
"prefix": "import",
"body": [
"import { $2 } from '$1'",
],
"description": "import (eslint)"
}
Though it works well, but I can't get suggestions when you code the file path($1), Like this:
the image No Suggestions
the code has highlight background, and don't have suggestions, How should I do some work to implement the feature like this:
only has cursor
Try changing to
"editor.suggest.snippetsPreventQuickSuggestions": false,
true is the default which may be preventing you from seeing suggestions inside your snippet. You want false.

Sublime Text autocomplete window closes when scrolling off the list

When scrolling the autocomplete list with up or down, if you go too far in either direction (e.g. there are no more suggestions), the list will close.
The behavior I want is to have the list wrap when reaching the end instead of close.
This is easy to fix with downward scrolling by assigning this hotkey:
{ "keys": ["down"], "command": "auto_complete", "context":
[ { "key": "auto_complete_visible" } ]
},
That's because the auto_complete command has built-in functionality to scroll downward each time it's invoked, which is why the hotkey works.
...But upward scrolling is different. I've tried about 20 different hotkey and macro combinations with no success.
I'm almost certain the only way to achieve this behavior is with a plugin, but unfortunately my Python skill level is nil.
If it matters, I'm manually invoking autocomplete with ctrl+space (the automatic popup is disabled).
I'm using Sublime Text 2.
Best solution: use auto_complete_cycle settings (added 26 March 2015):
Please use this new simple solution and not the python plugin
Sublime Text new version relased on 24 March 2015 has a new setting called auto_complete_cycle that implement this behaviour. Set it to true to iterate through the autocomplete results.
"auto_complete_cycle": true
Worst old solution: this custom plugin
I have just made this plugin that works well on Sublime Text 3 in Linux Mint. I have not tested it in Sublime Text 2 but think the plugin system it's the same, so, it should work on that version too. The workaround used it's not too pretty but works.
import sublime, sublime_plugin
class UpArrowInAutoCompleteCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.settings().set('autoCompleteFlag',True)
self.view.settings().set('initialPoint', self.view.sel()[0].begin())
""" Move one line up """
self.view.run_command('move', {"by": "lines", "forward": False});
""" Auto-complete was opened and up arrow was pressed, so if the cursor changes
(on_selection_modified will be triggered) we have gone outside the list.
If we were not in the first element on_selection_modified will not be triggered, so
we turn of the flag"""
sublime.set_timeout(lambda: self.view.settings().set('autoCompleteFlag', False),300)
class AutoCompleteSelectionModifiedTriggerCommand(sublime_plugin.EventListener):
def on_selection_modified(self, view):
if view.settings().get('autoCompleteFlag'):
""" If the up arrow was pressed and on_selection_modified
has been triggered, then we know that we were in the first element
of the list and we hitted the up arrow"""
view.settings().set('autoCompleteFlag', False)
initialPoint = view.settings().get('initialPoint')
""" We don't know how many words the auto_complete has, so,
in order to calculate that number, we move down in the list
till we get outside the list. After that we make the list appear
again and move down n-1 times to go (and stay) to the last line """
view.sel().clear()
view.sel().add(initialPoint)
view.run_command('auto_complete')
numLines = 0
while view.sel()[0].begin() == initialPoint:
view.run_command('move', {"by": "lines", "forward": True})
numLines += 1
if numLines == 401:
return
if numLines == 0:
return
view.sel().clear()
view.sel().add(initialPoint)
view.run_command('auto_complete')
numLine = 0
while numLine < (numLines-1):
view.run_command('move', {"by": "lines", "forward": True})
numLine += 1
To make the plugin use Tools>new Plugin and paste the code. Then save it in Packages/User folder. You can use Preferences>Browse Packages to find the Packages floder, inside which the User folder is located.
To make it work I added to my user key-bindings file this bindings (the second it's your own binding):
{
"keys": ["up"],
"command": "up_arrow_in_auto_complete",
"context": [{
"key": "auto_complete_visible",
"operator": "equal",
"operand": true
}]
}, {
"keys": ["down"],
"command": "auto_complete",
"context": [{
"key": "auto_complete_visible"
}]
}
Edit: this is an example result: