How to move the cursor in SML/NJ's REPL in terminal on Mac? - functional-programming

In the terminal of Mac OSX, I open SML, if I type something wrong, I wish to move my cursor to that place to modify something or add/delete something, but once I hit <- (the left arrow ) on the keyboard, the REPL gives me
Yes, that ^[[D thing.
So how do I move the cursor?

Yes, the REPL of SML/NJ does not support arrow keys. You can use the rlwrap tool to fix this. That allows you to use the left and right arrow keys to navigate within a line and the up and down arrow keys to recall lines you've entered earlier.
If you're using Emacs to write your SML files, you can also run SML in an Emacs buffer.

Related

Which keybind for smart-searching in history with ZSH?

When using the up and down arrow in my terminal (iTerm 2 on Mac OS Catalina), I can browse through my last commands using the up and down arrows.
I use ZSH (Oh-my-zsh to be precise) and if I type e.g. vim then press up, it will browse my history for any commands issued starting with vim.
I think it's annoying to have to move my hand to the arrow keys, so i wanted to bind ctrl-j and ctrl-k for browsing up and down.
I looked at bindkey and bound ^j to down-history and ^k to up-history. This allows me to browse my history, but not with the "smart" functionality (i'm not sure of the right terminology here) - It simply goes up and down in my history, without regards to my input.
I've looked through the standard widgets on the Zsh Line Editor manual, but I cannot find the right command for this.
Which command should I bind ^j and ^k to to get my desired result?
After some further digging, i ended up on the The Z-Shell Line Editor page at the section called "Prefix searching".
It revealed that the widget I was after, is called history-beginning-search-backward.
When using that widget, it works almost as I wanted it to, but not jumping to the end of the line.
A quick search lead me to another StackOverflow Question, that states that if you want to jump to the end of the line (as with the up arrow), it should be done as follows;
I had the same question and managed to find the solution with some experimentation.
I added the following to my .inputrc
"\eOA": history-search-backward # Up
"\eOB": history-search-forward # Down
"\C-P": "\eOA\C-E" # Ctrl-P
"\C-N": "\eOB\C-E" # Ctrl-N
This binds two hotkeys to Ctrl-P and Ctrl-N. One for history search, and the other Ctrl-E for end-of-line.

How to scroll up in Vim buffer with R (using Nvim-R)

I'm a happy user of the Nvim-R plugin, but I cannot find out how to scroll up in the buffer window that the plugin opens with R. Say for instance that I have a large output in console, but I cannot see the top of it - how do I scroll up to see this? In tmux for instance there's a copy mode that quite handily lets you do this, but how is this done in the R buffer?
An example below where I'm very curious to see what's on the line above the one begining with "is.na(a)...". How can this be achieved?
I have scoured the documentation found here, but without luck.
The answer is apparently to use Ctrl+\ Ctrl+n according to this answer on the bugreports for NVim-R.
Here's what my output looks like when I output mtcars:
When I hit Ctrl+\ Ctrl+n, I can move the cursor and I get line numbers:
To get back to interactive, I just use i, the same way I normally would.
Apparently, if you are using neovim, then you can add let R_esc_term = 0 in your ~/.vimrc file and you can then use the escape key, but if you don't use neovim, you are stuck using the two ctrl commands ¯\_(ツ)_/¯.
As pointed out by ZNK, it is about switching to normal mode in Vim's terminal. This, however, can easily fail due to cumbersome keybinding. If such is the case, remap the default keybinding to something reasonable, say, by putting this in your .vimrc:
tnoremap jk <C-\><C-n>
This works for me in Linux running Vim 8.0 in terminal (e.g. does not require Neovim). As you can see, I use 'jk' to switch from insert to normal mode. One can use Esc instead of jk, however, this makes me unable to use up arrow to retrieve command line history as been reported elsewhere.

vim-mode-plus keymaps for switching between panes not working

I have installed vim-mode-plus package and added the following keymap bindings in the keymap.cson file.
'atom-text-editor.vim-mode-plus.normal-mode':
'ctrl-j': 'focus-pane-or-panel:focus-below'
'ctrl-k': 'focus-pane-or-panel:focus-above'
'ctrl-h': 'focus-pane-or-panel:focus-on-left'
however I am not able to switch between the panes ( I am on Windows)
I am able to switch if I use a built-in keybinding as below:
ctrl-w ctrl-j window:focus-pane-below Vim Mode Plus atom-text-editor.vim-mode-plus:not(.insert-mode)
Above is copied from the Keybindings search results in atom
I don't think you are using the right command names. If you open the Command Palette (CtrlShiftP), you can search "focus" and find the various commands available for what you're trying to do.
Window: Focus Pane Above
Window: Focus Pane Below
Window: Focus Pane On Left
Window: Focus Pane On Right
To turn these into keybind command names, apply this formula:
Lowercase everything
Remove the space after :
Replace remaining spaces with hyphens
This gives the keybind command names:
window:focus-pane-above
window:focus-pane-below
window:focus-pane-on-left
window:focus-pane-on-right
Also notice the working example you point to uses a different selector than you are using. It uses atom-text-editor.vim-mode-plus:not(.insert-mode) rather than atom-text-editor.vim-mode-plus.normal-mode. That may be a better option, so your key bindings would work in modes other than normal mode (such as visual select mode).
I think what you need is:
'atom-text-editor.vim-mode-plus:not(.insert-mode)':
'ctrl-j': 'window:focus-pane-below'
'ctrl-k': 'window:focus-pane-above'
'ctrl-h': 'window:focus-pane-on-left'
And I'm not sure if you also wanted CtrlL to work, e.g.
'ctrl-l': 'window:focus-pane-on-right'

Bash via Platformio on Atom: arrow keys not functioning

I'm using the Windows Subsystem for Linux Bash in Atom via Platformio - and none of the arrow keys work.
There was an ongoing bug in WSL Bash with the arrow keys that should've been fixed, so I opened system32\bash.exe to test, and indeed the arrow keys work there; the problem happens only in Atom.
Does anyone know of a workaround/solution?
Thanks!
I've had this problem myself but I haven't found a full solution. It looks like there's a bug lurking upstream.
Until it's patched, here's a list of alternative commands courtesy of CherryDT in this thread:
Ctrl+P: Previous command (like up arrow)
Ctrl+N: Next command (like down arrow)
Ctrl+B: One character backwards (like left arrow)
Ctrl+F: One character forwards (like right arrow)
Ctrl+A: Start of line (like home key)
Ctrl+E: End of line (like end key)
Ctrl+D: Delete character (like delete key)

Vim with R-plugin and LaTeX-Suite results in backslash in insert mode misbehaving

Here's what happens. I'm using Vim + LaTeX-Suite to edit TeX files in Vim. This could be in the Terminal or in MacVim.
I happily
Insert lots of $\LaTeX \commands$ etc. I love using the $\backslash$.
TeX works great. No problem.
Then I go and open up a .R file in the same window (different tab). R-Plugin for Vim uses the <Leader> key (mapped to \ as per usual) to execute commands, e.g. I type \sa to send the selection to R and execute and move the window down. Life is nice.
Problem: even though while editing an R file, Vim is nice enough not to bug me in insert mode when I type \, for some reason when I switch back to the tab to edit the TeX file, then type \ in insert mode, it moves the cursor left of the \ and pauses as though waiting for the rest of the command, before then re-moving to the right of the \ and moving on as I type.
Below shows what happens just from typing \ in insert mode; obviously I could reproduce this by moving the cursor to the left with the arrow keys, but that's not how this happened--the cursor just moves left for a split second as though waiting for the R command to finish being input.
So: how can I stop the annoying behavior in the TeX file insert mode, without sacrificing other functionality? Note, (a) I don't expect mapping <Leader> to a different key to help since then that key will just have the same left-cursor-move problem in TeX; (b), I like the leader as \ anyway so I don't want to change it.
Put this line in your vimrc (requires Vim-R-plugin >= 0.9.9.2):
let g:vimrplugin_insert_mode_cmds = 0
If the problem persists, you can do the following in Normal mode to know what are the keyboard shortcuts in Insert mode:
:imap

Resources