Git Product home page Git Product logo

vscode-toggle-quotes's Introduction

logo

Toggle Quotes VSCode Extension

cmd ' (ctrl ' on win/linux) will cycle the first quote pair found (from the start/end of the section) through the following sequence:

  • Typescript, JavaScript, Markdown, Go, Svelte: " to ' to `
  • Any other files: " to '
  • Also available different start and end of wrap characters: </>, [/], «/» etc. (thanks to @dirondin )
  • Customizable, see below.

IMPORTANT: By design, what is selected will be ignored by the toggle logic, and the quote match will be from the start and end of the selection. This allows dead-simple code and maximum user flexibility to select what needs to be excluded. So the toggle will start to find the matching from the start and end of the selection.

For example, assuming [ is start of selection and ] end of selection.

example "with s[ome other] text" and more
            <--           -->

The quote match will happen from start selection going left and end selection going right. Toggle Quotes support multiple selections applying the same rule for each.

A Note On Keyboard Shortcuts: Quote keys on keyboard layouts are a special kind of tricky, because they vary a lot on keyboard layouts. They can have sticky keys, double press alternatives, mandatory modifiers or just plain different meanings. Is your layout International, Alternative-International, Nordic or something that doesn't seem to be working by default, you should configure a shortcut that works for you. Go to Keyboard Shortcuts > Toggle Quote and enter your own keybinding. For example, press Ctrl + Shift + ' and accept whatever character will show up.

Features

  • Typescript, JavaScript, Markdown, JSX (since 0.3.2, thanks to @evaera) toggles: " to ' to `
  • Any other file type toggles: " to '
  • Works with multi-select.
  • Text in selection will be ignored.
  • Per languageId Customization (new in 0.2.0)
"configurationDefaults": {          
  "[csharp]": {
    "togglequotes.chars": ["\"","'","`"]
  },
  "[freemarker]": {
    "togglequotes.chars": [["<",">"],["[","]"]]
  }
}

Upcoming

Credits

Self-centered promotion

vscode-toggle-quotes's People

Contributors

aisflat439 avatar bmalehorn avatar dirondin avatar evaera avatar jameygleason avatar jeremychone avatar kerigard avatar qb20nh avatar redsandro avatar will-stone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vscode-toggle-quotes's Issues

Is this still working?

I have tried much time to toggle quotes in the selected string and it did nothing, I tried in JS and PHP files.

Publish extension to Open VSX

Would you mind publishing this extension to Open VSX in addition to the Visual Studio Marketplace? Open VSX is a vendor-neutral open-source registry that can be used by any editor or IDE that supports VS Code extensions, whereas VS Marketplace's Terms of Use requires that the Marketplace and any extensions it distributes only be used with Microsoft products.

Here's Open VSX's publishing instructions. It looks like a pretty easy one-time process:

  1. Log onto their site and create an access token.
  2. Use their ovsx CLI to create a namespace.
  3. Claim ownership of the namespace.
  4. Add an ovsx publish command to your publishing script.

Alternatively, if you give this project an open-source license (I'd be happy to make a PR to add one if you let me know which license you prefer), I can add this repository to Open VSX's extension-publishing CI, and you won't need to worry about publishing it yourself. 👍🏼

Support open/close pairs

I'd love to be able to use this to make smart/curly quotes an option in text files. Straight quotes convert to curly and vice-versa.

This would of course require more logic, because the char inserted at the beginning would differ from the one at the end, but that additional logic would enable such things as <>, {}, [], and ().

And if your code doesn't require single-char strings, it would also enable more open/close pairs that the user could specify per filetype: {{ }}, , etc.

Editor configuration setting unknown

First off; awesome plugin 💪

minor issue im having:

vscode doesn't know about the configuration described in the README, which makes me unable to use autocomplete for configuring this

schermafbeelding 2018-03-21 om 15 17 27

not sure what's going on, I though vscode would be smart about this.

does anybody else have this problem?

Add icon to project

Would be nice to have an icon for the extension. Makes it easier to find in the extensions menu. Currently, it looks like this:

Screen Shot 2019-07-24 at 9 42 30 am

Just need to add an icon field in the package.json. See the Extension Manifest docs.

The path to the icon of at least 128x128 pixels (256x256 for Retina screens).

Add/remove quotes

It would be nice to be able to surround an element under the cursor with quotes and also to remove quotes completely. The cycle that now changes quotes could also ultimately remove and add them. E.g.:
I have an element in an array:
{
category: default
}
When I select or put the cursor on the category I would like it get quoted.

So the quote changing cycle could look like this:
category -> 'category' -> "category" -> category

Add extension to Open VSX Registry

The extension can't be found in Open VSX Registry.

Editors derived from VS Code such as Gitpod and VS Codium cannot access Microsoft's marketplace by policy, so Open VSX is being used as an alternative marketplace.

As a user of Gitpod, Hopefully, I want you to post an extension on open vsx.

Thank you.

Default hotkey is win+' on Windows

Feels strange having the default hotkey involving the Windows button on Windows. I've rebound it to ctrl+', but would be nice for new users of the extension to skip that step.

In the keybindings contribution, cmd is perceived as the Windows button on Windows, but you can define different default hotkeys based on the user's platform: see here

This is probably just an oversight, but in case it's intentional, here are some points to consider:

  • Out of all my extensions and keybindings, this is the only one that makes use of the Windows button, and binding to the Windows button is unconventional.
  • Likely to break because Microsoft likes to create new Windows button hotkeys all the time (like win+; and win+. for the native emoji picker they added recently)',
  • As a side effect of no one using Windows hotkeys, it's feels really uncomfortable for me to press the Windows button as a modifier while programming regularly.

Support unbalanced/asymmetrical quote pairs

It’s great that we can do pairs like [["<", ">"]] but in some languages, like Ruby, there can be asymmetrical pairs, like [["%{", "}"]].

How difficult would it be to support those kinds of pairs?

Running the contributed command: 'editor.togglequotes' failed.

mainThreadExtensionService.ts:95 Activating extension 'passionkind.prettier-vscode-with-tabs' failed: Cannot find module 'prettier-with-tabs'
Require stack:
- /Users/colch/.vscode/extensions/passionkind.prettier-vscode-with-tabs-1.1.0/out/src/PrettierEditProvider.js
- /Users/colch/.vscode/extensions/passionkind.prettier-vscode-with-tabs-1.1.0/out/src/extension.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js.

dunno if I installed it incorrectly somehow?

Support multi character beginning/end strings, e.g. Ruby's Percent Strings, here docs etc.

I used the following config trying to get support for Ruby's Percent Strings:

  "[ruby]": {
    "togglequotes.chars": [
    "\"",
    "'",
    ["%(", ")"]
  ]
  },

While it worked great to switch from "foo" to 'foo' to %(foo), after that last one it won't cycle back to the first.

I also experimented with an extended version which shows that it just stops as soon as the beginning is a two or three character string.

  "[ruby]": {
    "togglequotes.chars": [  
    "\"",
    "'",
    "`",
    ["%(", ")"],
    ["%[", "]"],
    ["%{", "}"],
    ["%q(", ")"],
    ["%i(", ")"],
    ["%r(", ")"],
    ["%s(", ")"],
    ["%w(", ")"],
    ["%x(", ")"],
  ]
  },

I think it would be great to support multi-character pairs.

Going beyond that, here are some more ideas which might be extracted to separate issues if somebody is interested:

Extended version for here docs

As an extended version, maybe even including newlines to allow here docs like e.g.

puts <<EOF
foo
bar
EOF

However, I personally use different here doc markers and not only EOF, so this might become a rabbit hole. Also there are extra variants for not having the end marker at the beginning of the line (like <<~EOF). Also, this would possibly raise additional questions like indentation etc.

Basic and advanced replacements

As pointed out in the previous examples, there might be tons of possible replacements one might add, but 90% of the time, it's only ", ' and `. A solution might be a second command, e.g. with additional alt-modifier by default. It could be configured with "togglequotes.extChars" and cycle not only through "togglequotes.chars" but both lists. The existing command could replace from both, but only to the regular list.

I'll stop here as this is most likely already waaaay out of scope for this nice little extension 😉

The 'Toggle Quotes' extension is not available in Visual Studio Code for the Web.

Wanted to install Toggle Quotes into the in browser editor https://vscode.dev But get the error:

The 'Toggle Quotes' extension is not available in Visual Studio Code for the Web. Learn Why

Learn Why link takes to:
https://code.visualstudio.com/docs/editor/vscode-web#_extensions

Can you provide partial or full support for the in browser editor?

This is the most useful feature that vscode for web is missing out of the box.

feature - per language configuration, and default tick to js/ts/md

Problem

As of now, there is only one quote sequence " -> ' -> ` which is not suitable for all language (especially the tick)

Solution

  • Default the Tick to JavaScript, Typescript, and Markdown only.
  • Allow customization with togglequotes.chars For example.
"configurationDefaults": {          
  "[csharp]": {
    "togglequotes.chars": ["\"","'","`"]
  }
}

Make back tick key optional

Could you add a config option to exclude the back tick (`) from the characters this plugin rotates through?

I mostly use ruby and the back tick is not a character you use with strings.

Feature request: toggle document

If I have a JSON document that is entirely single-quoted and I need to make it double-quoted, I'd have to select every property name and value one at a time. If that's outside the scope of this extension, is there another extension that could toggle quotes for the whole document?

command failing on osx mojave

Pressed: command + '
Expected: editor to toggle quotes
Got: Running the contributed command: 'editor.togglequotes' failed.

System info

VSCode: Version 1.35.1 (1.35.1)
OSX: Mojave 10.14.5
ToggleQuotes: 0.3.2

logs:

[2019-06-19 17:35:09.107] [exthost] [error] TypeError: Cannot read property 'indexOf' of undefined
	at findChar (/Users/me/.vscode/extensions/britesnow.vscode-toggle-quotes-0.3.2/out/src/extension.js:67:29)
	at toggle (/Users/me/.vscode/extensions/britesnow.vscode-toggle-quotes-0.3.2/out/src/extension.js:35:26)
	at vscode_1.commands.registerCommand (/Users/me/.vscode/extensions/britesnow.vscode-toggle-quotes-0.3.2/out/src/extension.js:16:9)
	at d._executeContributedCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:498:463)
	at d.$executeContributedCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:498:838)
	at d._doInvokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:644:1006)
	at d._invokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:644:698)
	at d._receiveRequest (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:643:346)
	at d._receiveOneMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:642:141)
	at define.constructor._protocol.onMessage.e (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:640:400)
	at u.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:47:720)
	at a (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:176:766)
	at e (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:176:812)
	at u.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:47:720)
	at n.constructor.e.onMessage.e (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:748:721)
	at u.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:47:720)
	at a (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:176:766)
	at e (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:176:812)
	at u.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:47:720)
	at y._receiveMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:185:670)
	at define.constructor._socketDisposables.push._socketReader.onMessage.e (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:182:981)
	at u.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:47:720)
	at f.acceptChunk (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:179:532)
	at define.constructor._register._socket.onData.e (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:178:869)
	at Socket.t (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:187:141)
	at Socket.emit (events.js:182:13)
	at Socket.EventEmitter.emit (domain.js:442:20)
	at addChunk (_stream_readable.js:279:12)
	at readableAddChunk (_stream_readable.js:264:11)
	at Socket.Readable.push (_stream_readable.js:219:10)
	at Pipe.onread (net.js:636:20) editor.togglequotes

Wrong default keybinding on nordic keyboard layout :bug:

I have a Nordic keyboard layout (Finnish in my case) and for me the default key binding was set to ctrl + ä instead of ctrl + '. Not really too big of an issue, but a slight inconvenience. Took me a while to figure out why it wasn't working.

Powershell

I think it's a good idea two support all three types in posh script file types as well

Extension broken with latest version of vscode

Hi, I've just installed the extension, but when i run the Toggle Quotes command or press the shortcut nothing happens. I've tried multiple ways and still nothing happens when I run it.

Is there an issue with the latest version? Could you check? Thanks

How to change default keyboard shortcut

Hi, is it possible to change default keyboard shortcut? I'm not using ENG keyboard while programming and for me to write ' I need to press alt gr + §. Also it won't detect this shortcut.

Files with multiple embedded languages

Some source files (like HTML or Vue templates) have multiple languages inside of them and a set quotes is only valid for one. For example, Vue template files contain HTML, CSS, and JS/TS in one file.

I'd like to use a different set of characters for the TypeScript inside the script tag than the rest of the file. Is it possible to detect the "sub-language" that your cursor is currently in, and use the settings for that?

<template>
 <span class="text">Some HTML here</span>
</template>

<script lang="ts">
 // I want access to the backtick ` quote mark here
</script>

<style scoped>
.text {
 color: "red"; /* But I don't want it here */
}
</style>

Of course, changing the settings for the entire .vue file is currently possible, but this is not ideal.

support empty case

At current moment it's not possible to add empty case, e.g.
[ "\"", "'", ""]

Ignore escaped quotes

Problem

Today, if the cursor ][ is after or before, the escaped quote will be accounted a quote to toggle (and it should not).

"Hello I\'m][ hungry"

Solution

Ignore the escaped single or double quotes when determining which quote pair should be toggled.

Escape apostrophes if present

The Sublime version of this plugin would escape any apostrophes:

"Hello I'm Hungry"

would change to

'Hello I\'m Hungry'

Possible with this one as well?

Does not work on multiple lines

Reproduce:

Create a new file with language set to Perl.

Create content:

$foo = "one line
second line";

Try to hit the hot key inside the text.

Toggling brackets not working + multiple config

Toggling Brackets

The README says Also available different start and end of wrap characters: </>, [/], «/» etc. but it doesn't seem to work, or at least I don't understand how to make it work. I don't find any documentation about that.

I tried the following, using the standard keyboard shortcut Cmd + ', in a Python file, on this line v = [0, 1]:

  • Placing the cursor in the middle, after the comma (so no selection).
  • Placing the cursor before and after [, ], (, and ).
  • On the selections 0, 1 and [0, 1].

Multiple Config

Is it possible to configure multiple lists? Like this:

"togglequotes.chars": [
  [ "\"", "'", "`" ],
  [ ["“", "”"], ["‘", "’"] ],
  [ ["«", "»"], ["‹", "›"] ],
  [ ["(", ")"], ["[", "]"], ["{", "}"] ],
],

It would also be useful to be able to configure different keyboard shortcuts. For example to have one acting on quotes and another one on brackets; so that we don't have to select, it finds the closest type around the cursor.

Svelte files don't currently support backticks

Great extension! Thank you for building it.

In Svelte files the back tick isn't yet supported. It only cycles through single and double quotes.

If this is a feature you would be interested in adding, I'm happy to make a PR. A small bit of guidance on how you would implement this would be greatly appreciated.

Thank you

Toggle curly braces in JSX/HTML properties?

I do a lot of web development. It would be nice to toggle between a quoted string to curly brace backtick. This is when I use your extension the most.

<div class="flex | " />

toggle to 

<div class={`flex | `}

No longer toggles tilde ( ` )

Not sure when this changed (I have been in Python land for quite a while) but when I returned to work on JS code, the command no longer toggles to tilde ( ` ) character.

It just toggles between single and double quotes.

feature request - have no quotes as one of the toggle options

It would be great if it was possible to have no quotes as an option for the toggle sequence.

If I add an empty string to togglequotes.chars as follows:

    "togglequotes.chars": ["\"", "'", "`", ""],

I should be able to toggle between different quote types and have no quotes as one of the toggle options. Then I'd have a really easy way toggle or remove quotes around any text in vscode, all in one extension.

However, when I do this and it reaches the unquoted option, I lose the ability to continue toggling.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.