1
votes

I'm looking for a simple method to determine the column position of a VSCode editor's text insertion cursor/caret, either prior to selecting an area of text to copy or immediately the mouse is used to start the selection. The column number would then be stored in the clipboard before performing further clipboard manipulation.

I have tried searching for AutoHotkey methods to achieve this, but the only solution I'm able to find involves using ImageSearch, which is not suitable for my purpose.

Edit: I found this API reference, could I possibly use this to determine the cursor position preferably using windows cmd/powershell?

1

1 Answers

2
votes

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?