Code Monkey home page Code Monkey logo

Comments (10)

iansinnott avatar iansinnott commented on May 18, 2024 12

Thank you @macintacos.

For anyone else coming across this issue I'd point out that using vscode-neovim the <space> key will be sent to neovim, so you can remap it within your init.vim file:

  " Integrate with whichkey for spacemacs-style space key
  nnoremap <space> :call VSCodeNotify('whichkey.show')<CR>

from vspacecode.

pomdtr avatar pomdtr commented on May 18, 2024 11

For example, here is my init.vim

" Vscode Commands
if exists('g:vscode')
	function! s:VisualCommand(commandString)
			normal! gv
			call VSCodeNotify(a:commandString)
	endfunction

	xnoremap <silent> gh :<C-u>call <SID>hover()<CR>

	nnoremap <silent> <Leader><space> :<C-u>call VSCodeNotify('workbench.action.showCommands')<CR>
	nnoremap <silent> <Leader>pf :<C-u>call VSCodeNotify('workbench.action.quickOpen')<CR>
	nnoremap <silent> <Leader>/ :<C-u>call VSCodeNotify('actions.find')<CR>
	nnoremap <silent> <Leader>= :<C-u>call VSCodeNotify('editor.action.formatDocument')<CR>
	nnoremap <silent> <Leader>bd :<C-u>call VSCodeNotify('workbench.action.closeActiveEditor')<CR>
	nnoremap <silent> <Leader>bo :<C-u>call VSCodeNotify('workbench.action.closeOtherEditors')<CR>
	nnoremap <silent> <Leader>br :<C-u>call VSCodeNotify('workbench.action.files.revert')<CR>
	nnoremap <silent> <Leader>bs :<C-u>call VSCodeNotify('workbench.action.files.newUntitledFile')<CR>
	nnoremap <silent> <Leader>el :<C-u>call VSCodeNotify('workbench.actions.view.problems')<CR>
	nnoremap <silent> <Leader>ep :<C-u>call VSCodeNotify('editor.action.marker.previous')<CR>
	nnoremap <silent> <Leader>en :<C-u>call VSCodeNotify('editor.action.marker.next')<CR>
	nnoremap <silent> <Leader>f/ :<C-u>call VSCodeNotify('actions.find')<CR>
	nnoremap <silent> <Leader>f2 :<C-u>call VSCodeNotify('fileutils.duplicateFile')<CR>
	nnoremap <silent> <Leader>fd :<C-u>call VSCodeNotify('fileutils.removeFile')<CR>
	nnoremap <silent> <Leader>fe :<C-u>call VSCodeNotify('workbench.action.openGlobalSettings')<CR>
	nnoremap <silent> <Leader>fE :<C-u>call VSCodeNotify('workbench.action.openSettingsJson')<CR>
	nnoremap <silent> <Leader>fh :<C-u>call VSCodeNotify('gitlens.showQuickFileHistory')<CR>
	nnoremap <silent> <Leader>fm :<C-u>call VSCodeNotify('fileutils.moveFile')<CR>
	nnoremap <silent> <Leader>fn :<C-u>call VSCodeNotify('fileutils.newFileAtRoot')<CR>
	nnoremap <silent> <Leader>fo :<C-u>call VSCodeNotify('workbench.action.files.openFile')<CR>
	nnoremap <silent> <Leader>fO :<C-u>call VSCodeNotify('workbench.action.files.openFile')<CR>
	nnoremap <silent> <Leader>fr :<C-u>call VSCodeNotify('fileutils.renameFile')<CR>
	nnoremap <silent> <Leader>fs :<C-u>call VSCodeNotify('workbench.action.gotoSymbol')<CR>
	nnoremap <silent> <Leader>fw :<C-u>call VSCodeNotify('workbench.action.files.save')<CR>
	nnoremap <silent> <Leader>fy :<C-u>call VSCodeNotify('workbench.action.files.copyPathOfActiveFile')<CR>
	nnoremap <silent> <Leader>gb :<C-u>call VSCodeNotify('gitlens.toggleFileBlame')<CR>
	nnoremap <silent> <Leader>gh :<C-u>call VSCodeNotify('gitlens.showQuickRepoHistory')<CR>
	nnoremap <silent> <Leader>gs :<C-u>call VSCodeNotify('workbench.view.scm')<CR>
	nnoremap <silent> <Leader>hd :<C-u>call VSCodeNotify('workbench.action.openGlobalKeybindings')<CR>
	nnoremap <silent> <Leader>hD :<C-u>call VSCodeNotify('workbench.action.openGlobalKeybindingsFile')<CR>
	nnoremap <silent> <Leader>pf :<C-u>call VSCodeNotify('workbench.action.quickOpen')<CR>
	nnoremap <silent> <Leader>pl :<C-u>call VSCodeNotify('workbench.action.files.openFolder')<CR>
	nnoremap <silent> <Leader>pp :<C-u>call VSCodeNotify('workbench.action.openRecent')<CR>
	nnoremap <silent> <Leader>ps :<C-u>call VSCodeNotify('workbench.action.showAllSymbols')<CR>
	nnoremap <silent> <Leader>qq :<C-u>call VSCodeNotify('workbench.action.closeWindow')<CR>
	nnoremap <silent> <Leader>qr :<C-u>call VSCodeNotify('workbench.action.reloadWindow')<CR>
	nnoremap <silent> <Leader>rn :<C-u>call VSCodeNotify('search.action.focusNextSearchResult')<CR>
	nnoremap <silent> <Leader>rp :<C-u>call VSCodeNotify('search.action.focusPreviousSearchResult')<CR>
	nnoremap <silent> <Leader>rs :<C-u>call VSCodeNotify('workbench.action.findInFiles')<CR>
	nnoremap <silent> <Leader>rn :<C-u>call VSCodeNotify('editor.action.rename')<CR>
	nnoremap <silent> <Leader>ta :<C-u>call VSCodeNotify('workbench.action.toggleActivityBarVisibility')<CR>
	nnoremap <silent> <Leader>tb :<C-u>call VSCodeNotify('workbench.action.toggleSidebarVisibility')<CR>
	nnoremap <silent> <Leader>tc :<C-u>call VSCodeNotify('workbench.action.toggleCenteredLayout')<CR>
	nnoremap <silent> <Leader>td :<C-u>call VSCodeNotify('workbench.view.debug')<CR>
	nnoremap <silent> <Leader>te :<C-u>call VSCodeNotify('workbench.view.explorer')<CR>
	nnoremap <silent> <Leader>tf :<C-u>call VSCodeNotify('workbench.action.toggleFullScreen')<CR>
	nnoremap <silent> <Leader>tg :<C-u>call VSCodeNotify('workbench.view.scm')<CR>
	nnoremap <silent> <Leader>t/ :<C-u>call VSCodeNotify('workbench.action.findInFiles')<CR>
	nnoremap <silent> <Leader>tl :<C-u>call VSCodeNotify('workbench.view.extension.gitlens')<CR>
	nnoremap <silent> <Leader>tm :<C-u>call VSCodeNotify('workbench.action.toggleMenuBar')<CR>
	nnoremap <silent> <Leader>tM :<C-u>call VSCodeNotify('editor.action.toggleMinimap')<CR>
	nnoremap <silent> <Leader>tp :<C-u>call VSCodeNotify('workbench.action.togglePanel')<CR>
	nnoremap <silent> <Leader>' :<C-u>call VSCodeNotify('workbench.action.terminal.toggleTerminal')<CR>
	nnoremap <silent> <Leader>ts :<C-u>call VSCodeNotify('workbench.action.selectTheme')<CR>
	nnoremap <silent> <Leader>tx :<C-u>call VSCodeNotify('workbench.view.extensions')<CR>
	nnoremap <silent> <Leader>tz :<C-u>call VSCodeNotify('workbench.action.toggleZenMode')<CR>
	nnoremap <silent> <Leader>v :<C-u>call VSCodeNotify('editor.action.smartSelect.grow')<CR>
	nnoremap <silent> <Leader>V :<C-u>call VSCodeNotify('editor.action.smartSelect.shrink')<CR>
	nnoremap <silent> <Leader>w- :<C-u>call VSCodeNotify('workbench.action.splitEditorDown')<CR>
	nnoremap <silent> <Leader>w/ :<C-u>call VSCodeNotify('workbench.action.splitEditorRight')<CR>
	nnoremap <silent> <Leader>wd :<C-u>call VSCodeNotify('workbench.action.closeEditorsInGroup')<CR>
	nnoremap <silent> <Leader>wh :<C-u>call VSCodeNotify('workbench.action.focusLeftGroup')<CR>
	nnoremap <silent> <Leader>wH :<C-u>call VSCodeNotify('workbench.action.moveActiveEditorGroupLeft')<CR>
	nnoremap <silent> <Leader>wj :<C-u>call VSCodeNotify('workbench.action.focusBelowGroup')<CR>
	nnoremap <silent> <Leader>wJ :<C-u>call VSCodeNotify('workbench.action.moveActiveEditorGroupDown')<CR>
	nnoremap <silent> <Leader>wk :<C-u>call VSCodeNotify('workbench.action.focusAboveGroup')<CR>
	nnoremap <silent> <Leader>wK :<C-u>call VSCodeNotify('workbench.action.moveActiveEditorGroupUp')<CR>
	nnoremap <silent> <Leader>wl :<C-u>call VSCodeNotify('workbench.action.focusRightGroup')<CR>
	nnoremap <silent> <Leader>wL :<C-u>call VSCodeNotify('workbench.action.moveActiveEditorGroupRight')<CR>
	nnoremap <silent> <Leader>wm :<C-u>call VSCodeNotify('workbench.action.toggleEditorWidths')<CR>
	nnoremap <silent> <Leader>wo :<C-u>call VSCodeNotify('workbench.action.closeEditorsInOtherGroups')<CR>
	nnoremap <silent> <Leader>ws :<C-u>call VSCodeNotify('workbench.action.splitEditorDown')<CR>
	nnoremap <silent> <Leader>wv :<C-u>call VSCodeNotify('workbench.action.splitEditorRight')<CR>
	nnoremap <silent> <Leader>ww :<C-u>call VSCodeNotify('workbench.action.focusNextGroup')<CR>
	nnoremap <silent> <Leader>wW :<C-u>call VSCodeNotify('workbench.action.focusPreviousGroup')<CR>
	nnoremap <silent> <Leader>xw :<C-u>call VSCodeNotify('editor.action.trimTrailingWhitespace')<CR>
	nnoremap <silent> go :<C-u>call VSCodeNotify('editor.action.showContextMenu')<CR>

	xnoremap <silent> <Leader><space> :<C-u>call <SID>VisualCommand('workbench.action.showCommands')<CR>
	xnoremap <silent> > :<C-u>call <SID>VisualCommand("editor.action.indentLines")<CR>
	xnoremap <silent> < :<C-u>call <SID>VisualCommand("editor.action.outdentLines")<CR>
	xnoremap <silent> go :<C-u>call <SID>VisualCommand("editor.action.showContextMenu")<CR>
	nnoremap <silent> <Leader>/ :<C-u>call <SID>VisualCommand('actions.find')<CR>

	xmap gc  <Plug>VSCodeCommentary
	nmap gc  <Plug>VSCodeCommentary
	omap gc  <Plug>VSCodeCommentary
	nmap gcc <Plug>VSCodeCommentaryLine
endif

from vspacecode.

macintacos avatar macintacos commented on May 18, 2024 2

@iansinnott I happen to be subscribed to this issue for some reason, but I think a lot has changed since this issue was opened. VSpaceCode (and thus, vscode-which-key) doesn't need any Vim emulation in order to function anymore, as far as I can tell -- it's just an extension that you can invoke. While it's surely a better experience that way, all you need to do is remap the extension's invocation to SPC when you're in the editor and you should be good to go.

With the above in mind, I recommend checking out the README for this project again. One note to call out from "Project History":

This project was initially started by StreakyCobra as a configuration file for VSCodeVim to be merged in your settings.json file. stevenguh developed on his side an extension also with the goal to brings Spacemacs bindings to VSCode. After some discussion we agreed to merge the two projects to keep this niche community unified. stevenguh solution was technically better, and this project had a larger community and was better referenced, so it was decided move his extension here.

Hope that helps.

from vspacecode.

StreakyCobra avatar StreakyCobra commented on May 18, 2024

Hi :) I am not using neovim so I am not going to implement, support or test this. If someone is willing to do a PR and support the feature this would be welcome 😊

In the meantime I'm closing the issue because there is not much to do.

from vspacecode.

iansinnott avatar iansinnott commented on May 18, 2024

Is VSpaceCode tightly coupled to the Vim plugin? Clearly we need a Vim layer to emulate Spacemacs, but do we need that specific vim layer?

Perhaps vscode-neovim could provide the vim mappings in place of the vim plugin.

from vspacecode.

unvalley avatar unvalley commented on May 18, 2024

You can also override space binding to work vspacecode.space at keybindings.json.

 {
     "key": "space",
     "command": "vspacecode.space",
     "when": "editorTextFocus && neovim.mode == normal"
 },

from vspacecode.

a690700752 avatar a690700752 commented on May 18, 2024

for visual mode, can use this to remap in your lua config file.

local function getVisualSelection()
	local start = vim.fn.getpos("v")
	local finish = vim.fn.getcurpos()
	return start, finish
end

local function exit_visual_mode()
	vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
end

vim.keymap.set("n", "<space>", ":call VSCodeNotify('vspacecode.space')<CR>")
vim.keymap.set("x", "<space>", function()
	local start, finish = getVisualSelection()
	if vim.fn.visualmode() == "V" then
		vim.fn.VSCodeNotifyRange("vspacecode.space", start[2], finish[2], 1)
	else
		vim.fn.VSCodeNotifyRangePos("vspacecode.space", start[2], finish[2], start[3], finish[3], 1)
	end
	exit_visual_mode()
end)

from vspacecode.

aveaves avatar aveaves commented on May 18, 2024

for visual mode, can use this to remap in your lua config file.

local function getVisualSelection()
	local start = vim.fn.getpos("v")
	local finish = vim.fn.getcurpos()
	return start, finish
end

local function exit_visual_mode()
	vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
end

vim.keymap.set("n", "<space>", ":call VSCodeNotify('vspacecode.space')<CR>")
vim.keymap.set("x", "<space>", function()
	local start, finish = getVisualSelection()
	if vim.fn.visualmode() == "V" then
		vim.fn.VSCodeNotifyRange("vspacecode.space", start[2], finish[2], 1)
	else
		vim.fn.VSCodeNotifyRangePos("vspacecode.space", start[2], finish[2], start[3], finish[3], 1)
	end
	exit_visual_mode()
end)

Could you check if this still works? I tried to toggle comment a visual selection but only the last line of the selection gets commented. That is, I selected a region by "v" using vscode-neovim, pressed "space + ;" to toggle comment of region. Only the last line gets toggled.

For comparison, I successfully toggled the comment of a region by directly invoking the "Toggle Line Comment" command in vscode for the region selected using vscode-neovim visual selection "v".

from vspacecode.

a690700752 avatar a690700752 commented on May 18, 2024

@aveaves The VSCodeNotifyRange API has changed, try this

local function getVisualSelection()
	local start = vim.fn.getpos("v")
	local finish = vim.fn.getcurpos()
	return start, finish
end

vim.keymap.set("n", "<space>", ":call VSCodeNotify('vspacecode.space')<CR>")
vim.keymap.set("x", "<space>", function()
	local start, finish = getVisualSelection()
	if vim.fn.mode() == "V" then
		require("vscode-neovim").notify_range("vspacecode.space", start[2], finish[2], 1)
	else
		require("vscode-neovim").notify_range_pos("vspacecode.space", start[2], finish[2], start[3], finish[3], 1)
	end
end)

from vspacecode.

aveaves avatar aveaves commented on May 18, 2024

@a690700752 Thank you this also works. I solved it a while ago using your first code by removing the exit_visual_mode() function.

from vspacecode.

Related Issues (20)

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.