question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] What is the best way to use VS Code's built in refactoring in vscode-neovim ?

See original GitHub issue

In normal VS Code you need to select some code to get the lightbulb to appear that tells you what refactoring is available for that code.

In this extension:

  • If I enter visual mode and select code then the lightbulb does not appear until I ctrl+shift p to transfer the Neovim selection into VS Code
  • I can then select ‘refactor’ in the menu
  • If I select more lines of code in visual mode then the selection as far as VS Code is concerned is lost, and I need to ctrl+shift p again to get to select refactor

Am I missing some obvious shortcut or easier way to do things? Could visual mode communicate with VS Code and show the lightbulb and allow ctrl+shift r as insert mode does for refactoring?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
David-Elsecommented, Oct 1, 2020

Cheers!

It works but is clunky. It seems to forget when in visual block mode that other lines are selected after the first run. While many are selected on screen it is only acting on one.

Maybe I am just muddling up what VS Code can offer refactoring for with and without selecting code. It is acting funny somewhere, not sure if it is this plugin or Code itself.

I will forget it for now, many refactors are selectble in normal mode. Maybe someone might find it useful or improve it:

function! s:refactorInVisualMode()
    let mode = mode()
    if mode ==# 'V'
        let startLine = line('v')
        let endLine = line('.')
        call VSCodeNotifyRange('editor.action.refactor', startLine, endLine, 1)
    else
        let startPos = getpos('v')
        let endPos = getpos('.')
        call VSCodeNotifyRangePos('editor.action.refactor', startPos[1], endPos[1], startPos[2], endPos[2] + 1, 1)
    endif
endfunction

xnoremap <C-R> <Cmd>call <SID>refactorInVisualMode()<CR>
0reactions
theol0403commented, Apr 29, 2022

Can use xnoremap <C-R> <Cmd>call VSCodeNotifyVisual('editor.action.refactor', 1)<CR>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refactoring source code in Visual Studio Code
Select the source code you'd like to extract and then click on the lightbulb in the gutter or press (Ctrl+.) to see available...
Read more >
Integrating VSCode With Neovim
Copy the content of your file inside Neovim. Execute the command in Neovim. Sync the results back to Visual Studio Code. This means...
Read more >
How to Refactor Code in Visual Studio Code
1. Refactoring with Visual Studio Code Shortcuts · Go to definition: Opens up a pane that shows you where the function has been...
Read more >
vscode-neovim/vscode-neovim: Vim-mode for VS Code ...
This extension uses a fully embedded Neovim instance, no more half-complete VIM emulation! VSCode's native functionality is used for insert mode and editor ......
Read more >
An Intro to Vim for People Who Use Visual Studio Code
Plugin System. Vim by itself is pretty barebones. · Intellisense. The auto-completion system (Intellisense) in VSCode is arguably its best ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found