You can make a vscode extension and bind the command to a keyboard shortcut.
How to get line and column(character) of cursor:
const activeEditor = vscode.window.activeTextEditor
if (activeEditor) {
console.log(activeEditor.selection.active.line)
console.log(activeEditor.selection.active.character) //column
}
api: https://code.visualstudio.com/api/references/vscode-api#details-159
activeEditor.selection gives you an object with 4 objects
start:Object
line:4
character:8
end:Object
line:6
character:8
active:Object
line:4
character:8
anchor:Object
line:6
character:8
activeEditor.selection.active is your cursor.
activeEditor.selection.anchor is
The position at which the selection starts. This position might be before or after active.
anchor-active may be reversed, but start-end will always be up-down.
note: I found the api AFTER I found out how to get current line from here:
VScode API why can't I get the current line?
EDIT: for columnNum (see Eric's comment):
const activeEditor = vscode.window.activeTextEditor
if (activeEditor) {
const lineOffset = activeEditor.selection.active.line
const charOffset = activeEditor.selection.active.character
console.log(`line: ${lineOffset + 1}`)
console.log(`character: ${charOffset + 1}`)
console.log(`column: ${getColumn(activeEditor.document.lineAt(lineOffset).text,charOffset) + 1}`) //column
function getColumn(str, sumCharacter) {
const arr = [...str]
let whichCharacter = 0
for (let whichColumn = 0; whichColumn < arr.length; whichColumn++) {
if (whichCharacter===sumCharacter) {
return whichColumn
}
whichCharacter+=arr[whichColumn].length
}
return arr.length
}
}