How to remap <cr> to go to line number in VSCodeVim - visual-studio-code

In vim I used to map the enter key <cr> to go to line number instead of the letter G using the following settings
nnoremap <expr> <cr> v:count == 0 ? "\<cr>" : "G"
I tried to achieve the same result in vim for VSCode but I couldn't.
Is there a way that manage me from doing so without enabling the experimental feature neovim integration inside VSCode

Related

neovim vscode replace word under cursor

I am using neo vim extension in vscode.
I want to replace the word under cursor. Usually it is just a minor change to the existing word, so I have it available in the replace part. I have the below line in my init.vim
nnoremap ^ :%s/\<<C-r><C-w>\>/<C-r><C-w>/g
When I invoke the binding with ^, the appropriate command appears as shown in image below.
However on pressing return no changes take effect. If I place the same command in the command window by pasting or typing and hit return, then it works.
This mapping didn't work for me either, but I've found a workaround:
nnoremap <leader>sr :<C-u>call VSCodeNotify('actions.find', { 'query': expand('<cword>')})<CR>
So ,sr opens the quick find window with the word under cursor. Then you have to push Ctrl-h to get the replace field also.
Unfortunately the same with editor.action.startFindReplaceAction doesn't work.
The same works for workbench.action.findInFiles but not for workbench.action.ReplaceInFiles
{
"before": ["<Space>","s","r"],
"after": ["*",":", "%","s","/","/"]
},
this works for me using regular vim in VSCode

Shortcut for joining two lines

What's the keyboard shortcut for joining two lines in VS Code?
If the cursor is anywhere in the first line of
f(foo,
bar)
then when I hit the shortcut, I want to get
f(foo, bar)
Visual Studio Code now comes with a default key binding for joining lines, Ctrl + J.
You can find all keyboard shortcuts under Preferences > Open Keyboard Shortcuts.
You can overwrite it using the UI or by providing a different key combination for the command editor.action.joinLines in keybindings.json.
Press F1, and type Join Lines. By default there is no key bindings to it yet, but you can easily set it under 'Preferences > Keyboard Shortcuts', then search for Join Lines and set a shortcut.
You can simply:
Select the lines to be joined.
Hit Ctrl+Shift+P or F1.
Type join lines.
Since the best way is already answered I'm just adding an alternative.
If you want to work with defaults you can hit Ctrl+Del while caret is at the end of the first line.
Works with multi-select too if you want to join multiple lines.
Depending on how much clutter you have in your , try the following "keypress sequence" (you must have focus in an open editor tab for this to work1, and make sure to have your cursor/lines selected before doing this):
Ctrl+Shift+P JL 2
If your Command Palette ends up showing a clash of non-Join Lines entries when you finish typing, you may have to end up typing instead3:
Ctrl+Shift+P JOINSpace L
Ctrl+Shift+P JOINSpace LI
...
Ctrl+Shift+P JOINSpace LINES
...Manually select from the Palette using down arrow or mouse 4
In case you're thinking about setting your own keybind (since it is unset by default in Windows), here are the other Commands that have a keybind associated with them containing a J 5:
Command
Keybinding
When
workbench.action.search.toggleQueryDetails
Ctrl+Shift+J
inSearchEditor || searchViewletFocus
View: Toggle Panel
Ctrl+J
---
Unfold All
Ctrl+K Ctrl+J
editorTextFocus && foldingEnabled
Notebook: Join With Previous Cell
Shift+Alt+Win+J
notebookEditorFocused
Notebook: Join With Next Cell
Alt+Win+J
editorTextFocus && foldingEnabled
I suggest using Ctrl+Alt+J or Ctrl+Shift+Alt+Jif you end up going this route, since it doesn't seem to clash with existing defaults and is similar to what people are already used to.
Alternatively, if you tend to use a different text editor or IDE,
[File > Preferences > Keymaps] (Ctrl+K Ctrl+M) offers a selection of alternative keymaps (these are extensions, which must be installed), including (as of now, sorted by current rating):
IntelliJ IDEA (by Keisuke Kato)
Sublime Text (by Microsoft)
Atom (by Microsoft)
Eclipse (by Alphabot Security)
Visual Studio (by Microsoft)
Delphi (by Alessandro Fragnani)
Notepad++ (by Microsoft)
Vim (by vscodevim)
Emacs (by hirosun)
1 In other words, don't be in a "non-editor" window like Settings or Keyboard Shortcuts
2 Alternatively, Command Palette can also be opened by selecting [View > Command Palette...] instead of Ctrl+Shift+P
3 This could occur due to having 3rd-party Commands containing the letters j and l. Command Palette can also be found alternatively by selecting [View > Command Palette...]
4 Hopefully you don't end up with this case.
5 These are all listed under [File > Preferences > Keyboard Shortcuts] (Ctrl+K Ctrl+S)

vi command line editing key bindings - previous command

I use the vi editor on the command line, and I really like it.
I use
set -o vi
to set the bindings.
The only thing is that I have to use the up and down arrows to cycle through the
previous executed commands.
In the emacs key bindings it was Ctrl+p to get to the previous command. It is the one emacs binding I miss.
I have been looking for something like it vi - but can't find it. My search gets diverted to the text editing vi binding for previous command which is held in " : " or hitting Ctrl+F to get a command window. I am using vi on the command line instead of emacs. There has to be something.
Is there something comparable in the vi command line ?
Using the Up / Down arrow keys is driving me nuts.
Actually I found the answer on this on this site:
Working Productively in Bash's Vi Command Line Editing Mode (with Cheat Sheet)
Make sure set -o vi is set to 'on'. Hit Ctrl+[ or escape to get to command mode. Then tap k go up the history and j to go down. It is so intuitive that I imagine most vi power-users discover it without trying, without help.
Thanks.

Emacs-like line navigation in gedit

I have been using Emacs for the past few months and I like its line navigation feature a lot as it doesn't need you to use arrow keys.
Emacs Line Navigation:
C-p : go to previous line
C-n : go to next line
C-f : go forward one character
C-b : go backward one character
Is there anyway I can use this in gedit text editor 3 also? Is there any plugin or option for this functionality?

C-Tab cannot be recognized in terminal?

I want to bind company-mode-map to C-tab, but it seems doesn't work. And I typed C-h k C-tab, it just said that I typed TAB but not C-Tab. It works in Xwindows, is there any way to fix the problem in terminal mode?
I found these directions, which are targeted at using GNU screen, but they work for me in regular terminal mode. After adding:
*vt100.translations: #override \n\
Ctrl ~Shift <Key>Tab: string(0x1b) string("[27;5;9~") \n \
Ctrl Shift <Key>Tab: string(0x1b) string("[27;6;9~") \n
to my .Xresources file, C-tab is recognized in my terminal, and the binding found by Emacs.