VSC Selection Convert
Convert selected text by your custom script.
Getting started
- Install
selection-convert
- Open
Command Palette
, and type Convert Selected Text
- A file in your home folder
.vscode/selection-convert.js
will be created and opened automatically.
- Write your custom converting script.
- Select the text which you want to convert.
- Redo step 2, this time your custom converters should show up.
- Pick the one your want to run, and selected text will be replaced.
Custom Converter Examples:
const vscode = require("vscode")
module.exports = {
// basic
sortLinesByLength(text) {
return text.split(/\n/g).sort((a,b)=>b.length-a.length).join("\n")
},
// take advantage of user input
deleteSpecificWords: (text) => {
const userInput = await vscode.window.showInputBox("CSV of words to remove")
const pattern = new RegExp("\\b(" + userInput.split(",").join("|") + ")\\b", "g")
return text.replace(pattern, "")
},
// convert selected text to camel case
camelCase: (text) => {
return text.replace(/(\w)(\w*)/g, (_, first, rest) => first.toUpperCase() + rest.toLowerCase())
},
// convert selected text to snake case
snakeCase: (text) => {
return text.replace(/(\w)(\w*)/g, (_, first, rest) => first.toLowerCase() + rest.toUpperCase())
},
// convert selected text to kebab case
kebabCase: (text) => {
return text.replace(/(\w)(\w*)/g, (_, first, rest) => first.toLowerCase() + rest.toLowerCase())
},
}
Credit
This is an enhanced version of this extension
Setup
Everything is detailed in the documentation/setup.md
!