This plugin provides emacs keybindings and workflow for Visual Studio Code and is a fork of the great vscode extension by hiro-sun.
It merges some of the pull requests in the original and other external helpers that make the extension a little less an exact copy of emacs behavior, and a little more friendly in interacting with the system clipboard and normal vscode interactions.
The following are some of the changes and enhancements from the original:
The clipboard handling is simplified by the removal of the emacs-only kill ring (which was also an unfinished implementation in the original). Copy, Cut, Yank and C-K work with the system clipboard now.
C+x k to close tab, C+x C-k all tabs
C+l centers screen on the cursor line
C+x C+f bound to quick open file
yank overwrites selection
Move commands
Command
Desc
C-f
Move forward
C-b
Move backward
C-n
Move to the next line
C-p
Move to the previous line
C-a
Move to the beginning of line
C-e
Move to the end of line
M-f
Move forward by one word unit
M-b
Move backward by one word unit
M->
Move to the end of buffer
M-<
Move to the beginning of buffer
C-v
Scroll down by one screen unit
M-v
Scroll up by one screen unit
M-g g
Jump to line (command palette)
M-g n
Jump to next error
M-g p
Jump to previous error
C-l
Center screen on current line
Search Commands
Command
Desc
C-s
Search forward
C-r
Search backward
A-%
Replace
C-Enter
Replace One Match (In replace dialog)
C-M-n
Add selection to next find match
Edit commands
Command
Desc
C-d
Delete right (DEL)
C-h
Delete left (BACKSPACE)
M-d
Delete word
M-Bksp
Delete word left
C-k
Kill to line end
C-S-Bksp
Kill entire line
C-o
open-line
C-w
Kill region
M-w
Copy region to kill ring
C-y
Yank
C-j
Enter
C-m
Enter
C-x C-o
Delete blank lines around
C-x h
Select All
C-x u (C-/, C-_)
Undo
C-;
Toggle line comment in and out
M-;
Toggle region comment in and out
C-x C-l
Convert to lower case
C-x C-u
Convert to upper case
Other Commands
Command
Desc
C-g
Cancel
C-space
Set mark
C-quote
IntelliSense Suggestion
M-x
Open command palette
C-M-SPC
Toggle SideBar visibility
C-x z
C-x r
File Commands
Command
Desc
C-x C-s
Save
C-x C-w
Save as
C-x C-n
Open new window
Tab / Buffer Manipulation Commands
Command
Desc
C-x b
Switch to another open buffer
C-x C-f
QuickOpen a file
C-x k
Close current tab (buffer)
C-x C-k
Close all tabs
C-x 0
Close editors in the current group.
C-x 1
Close editors in other (split) group.
C-x 2
Split editor horizontal
C-x 3
Split editor vertical
C-x 4
Toggle split layout (vertical to horizontal)
C-x o
Focus other split editor
Conflicts with default key bindings
ctrl+d: editor.action.addSelectionToNextFindMatch => Use ctrl+alt+n instead;
ctrl+g: workbench.action.gotoLine => Use alt+g g instead;
ctrl+b: workbench.action.toggleSidebarVisibility => Use ctrl+alt+space instead;
ctrl+space: toggleSuggestionDetails, editor.action.triggerSuggest => Use ctrl+' instead;
ctrl+x: editor.action.clipboardCutAction => Use ctrl+w instead;
ctrl+v: editor.action.clipboardPasteAction => Use ctrl+y instead;
I often get tripped up by how the mark works in vscode. I think there are two main things:
In emacs, when a region is marked and I start typing, the mark disappears (is deactivated), no text is deleted and new characters appear that the cursor. In vscode, the marked text is deleted. Furthermore, the mark stays active, thus if I, say, navigate down with the cursor then it starts marking text again.
I'm using Visual Studio Code 1.15.1 and I installed only the vscode-emacs-friendly extension. Everything works like a charm, expect this two bindings (M-> and M->).
I'm currently trying out VScode to see whether it could (partially) replace emacs. Naturally I was interested to compare typing latency (time between key-press and character showing on screen), see here. I used typometer as in that blog post and found that on my system enabling this extension doubled the latency.
Here a screenshot with all my extension disabled:
Shows average latency of 16.9ms, max 33.1ms and std-dev 2.8ms.
Here with all my extension disabled except vscode-emacs-friendly:
Shows average latency of 32.7ms, max 49.8ms and std-dev 4.1ms.
I'm not sure if this functionality is actually present, but the kill ring is mentioned in the extension's docs ("M-w | Copy region to kill ring"). So I was anticipating being able to cycle through different strings in the kill ring by the usual "M-y" after performing a yank (C-y), per the conventional Emacs behavior.
If C-y M-y kill ring yanking isn't currently supported, consider this a feature request!
Look into vscode back / forward navigation commands, and bind them to something emacs-like.
It seems emacs did not have something "standard" for it, and has a local-ring and a global-ring, we could choose to only bind the global one, as it seems to make more sense.
Hi hi - I'm on a Mac with a touch bar, & having trouble figuring out what meta is. In regular emacs / command line, it's still the (touch bar) escape key. That doesn't seem to work here - what is it? If it's supposed to still be esc, but that isn't working, how can I fix it? Thank you -
It would be nice if we could navigate the explorer similar to the way dired mode works in emacs, it is a bit grating having to remember to not use C-n and C-p when I am in the explorer.
Find file (CTRL+x CTRL+f) or find within file (CTRL+s)
Start typing a few letters
Type CMD+a
Nothing happens. In the code window, it selects all. With the extension disabled, it selects all. What's special about this little search box that the emacs extension breaks?
One emacs editing workflow is to set a mark & then perform an incremental search to set the end of the selection. I notice that the mark works fine with ctrl+p/n/f/b, but the mark is lost once I start an incremental search.
C-x 1 | Close editors in other (split) group.
C-x 2 | Split editor
C-x 3 | Toggle split layout (vertical to horizontal)
C-x o | Focus other split editor
In emacs, if the point is in a line where point to end of line contains only whitespace (or nothing), the whitespace and the newline will be deleted. That is, C-a C-k C-k will remove the current line entirely, and if a line contains "abc# ", and a next line "def" where # is the cursor, and C-k is hit, the result will be "abcdef" with point on the d.
vscode-emacs had.. something.. at some point, e.g.
Wondering if there is an omission here that could be added in a future update - I use the M-a/M-e motion controls a lot to jump to the beginning/end of code chunks, respectively. For example:
my_code <- function(x, y, z) {
return(x + y + z)
}
If my cursor is located at the beginning of line 1, it would jump to the end of line 3 with M-e, and from the end of line 3 it would jump to the beginning of line 1 with M-a. Same outcomes for when the cursor is anywhere in the middle.
Just wondering if this could be added into the keybindings - thanks!
Recently, Microsoft released Visual Studio Online which enables people to use VSCode on the cloud. I've tried it out and install vscode-emacs-friendly plugin the second I opened it.
Things are mostly working as expected, like M-w copies the content into system's clipboard, however, C-y is not working. I can do M-w then Cmd + V in mac to yank the selected content, but C-y seems like not doing anything. I checked the keymap and made sure there is no issues.
Could you please help what's happening, or where can I find some logs to upload here?
Whenever I run a command that relating to the kill ring (ctrl-space, m-w, etc), I get an error like "Running the contributed command:'emacs.enterMarkMode' failed.". This seems to have been happening for about a week, without any changes to my visual studio. I tried a fresh install of visual studio and the problem persists.
I noticed that ctrl-v doesn't seem to work as expected. On emacs the cursor when you move down by one screen unit stays on top whereas on vs code it jumps on the last line of the current visible unit. Also it doesn't scroll down when your starting position is the first line (it just moves the cursor to the end of the visible screen unit).
I don't know how to wirte extension, but I find the "cut" function in editor.js. It should be
let selection = this.getSelection();
if (selection.isEmpty) {
vscode.commands.executeCommand("MARK FROM currentPos to the CURRENT WORD start")
}
let selectText = this.getSelectionText();
if (appendClipboard) {
clip.writeSync(clip.readSync() + selectText);
} else {
clip.writeSync(selectText);
}
let t = Editor.delete(this.getSelectionRange());
vscode.commands.executeCommand("emacs.exitMarkMode");
return t
and can you help me to let keymap Alt+D save killed TEXT to clipboard too
When trying out vscode-emacs-friendly, I installed it, tried it and then when disabling it I end up with vscode that can't do Ctrl-X for cut... Any ideas on how this can be fixed ?
I would like to close the findWidget automatically when moving the cursor. This duplicates the way emacs works. For example, I will often do a search with a few ctrl+s's, and then alt+< to return to the top of the file. In emacs, this cancels the search operation. But with this extension, the findWidget is still open, which causes some confusion with other commands.
Would this be as straightforward as adding this snippet to the each cursor movement command? Is there a smarter way to do this?
{
"key": "ctrl+g", // change to for example alt+<, alt+>, etc.
"command": "closeFindWidget",
"when": "editorFocus && findWidgetVisible"
},
In emacs, an incremental search is completed with , and the cursor is left at the current location. In this extension, has the same behavior as ctrl-s, performing a forward incremental search.
What do you do if you have some text you want to yank back, and then
you kill something else? C-y would yank the more recent kill. But
the previous text is not lost. You can get back to it using the M-y
command. After you have done C-y to get the most recent kill, typing
M-y replaces that yanked text with the previous kill. Typing M-y
again and again brings in earlier and earlier kills. When you have
reached the text you are looking for, you do not have to do anything to
keep it. Just go on with your editing, leaving the yanked text where
it is.
If you M-y enough times, you come back to the starting point (the most
recent kill)."
In emacs I use ctrl-o to open a new line reflexively and the lack of that keybinding causes me no end of frustration in trying to use vscode.
I've added this emacs keybinding in pull request #56 and it fixes my particular problem.
(this is my first time trying to add to an extension, so be warned)
By default VS code maps Open Recent files to ^+R, which is very useful and convenient, but reverse search is binded to ^+R in vscode-emacs-friendly. Please remap Open Recent to another shortcut, for example ^+x f r, or ^+x r.
After using ctrl-space set a mark, what i want to do is then using ctrl-e to jump to the end of line and selecting the whole line(mark the whole line). But now what it does is after setting the mark, if you press ctrl-e you just quit the mark mode and directly jump to the end of line without selecting anything. Not sure if this is right behaviour for emacs. Also only ctrl-b, ctrl-f, ctrl-p and ctrl-n works fine with the mark mode.
It would be great to either implement Move Paragraph commands or come up with some way to allow other extensions affecting cursor movement to play nicely with the Mark. Currently, cursor movement initiated by other extensions disables the Mark entirely.
When I kill it ("Code Helper") in Activity Monitor, VSCode shows a message saying the extension host was killed. When I don't choose to restart host, and I hit the arrow keys, I get this:
The normal emacs worfklow would be to press ctlr-s and type in the search phrase, but this will cause one to accidentally start typing in the editor instead. This isn't an issue if the search bar isn't open yet.
This is more of a question than an issue, but is there a reason why you made so many commands close the search window? For example, I often want to paste something into it (particularly when I'm replacing), and all of the paste commands are set to closeFindWidget (along with like a million other commands...). Ctrl + G and some of the navigation commands make sense ofc...
I am opening this issue because for me this is an important feature of Emacs.
It is common to select some text as to desire to delete it. We can use the cut command (C-w) but this will override the clipboard. When we just want to remove the selection it's common to press <delete>. In Emacs when <delete> is pressed it removes the text and leave the MarkMode. However this plugin doesn't leave the MarkMode and I think this is an issue (and a very bothering one, because sometimes when typing fast I will delete some characters which were in the persistent selection mode).
I have fork the project, and I wish to contribute, I added some few little lines of code to implement this behavior. Please consider merging as it will not affect the original code and could add a better experience for the next users that will use this plugin.