previous command in R console - r

I would like to retrieve the previous command in my R console that started with a certain character. For example, i can just press the up key to get the last command. However, I'd like the last command that started with xyz for example. Is there a way to do this?

if you're on a linux distro, you can press ctrl+R and start typing, and then ctrl+R to toggle through search matches.
you can also do, history(pattern="^xyz"), but this would require an additional copy.

Related

How to search previously executed commands in the Julia REPL?

Is there a quick way to search old commands which were run in the Julia REPL? Using the up arrow to go back in time seems to have a limit on its history and it is also quite cumbersome.
One of the five REPL models available in Julia is the "Search mode" which allows you to search through previously executed commands from the REPL. You can click "Control" + "r" to open search mode like is shown below:
(reverse-i-search)`':
There is also a forward search available with "Control" + "s". You can read more about Julia's REPL Search mode here: https://docs.julialang.org/en/v1/stdlib/REPL/#Search-modes
In addition to "real" search, you can also enter the beginning of a previous line and scroll up in the history (using ↑ or Ctrl-P) to switch between all previously entered lines starting with the same prefix.
So, if you had previously entered x = some_complicated_expression, you can write x = and go up until the line you were looking for appears.
Checkout: https://kristofferc.github.io/OhMyREPL.jl/latest/features/fzf/#Fuzzy-REPL-history-search
Which will be easier to use than reverse-i-search

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.

How to bind a key combination to a command?

I have recently run into the following use case in LightTable:
I want to execute a command (for instance, duplicate a line)
I press "Ctrl-Space" and a list of commands shows up
I select the command I need
I want to repeat this command often, but there is no keybinding for this command
I go to user.keymap where I am supposed to add a line like [:editor "alt-shift-w" :editor.watch.unwatch]
But I have no idea what is the :editor.watch.unwatch-like key for the command I have just found. All I know is the displayed name of this command: Editor: duplicate line
Is there a way to add this keybinding without digging up the documentation and finding the key?
If you add the beginning of a line like this to your user.keymap:
[:editor "alt-shift-w"
and position the keyboard cursor at the end of the line you should be able to type duplicate line and the relevant command should be listed in a popup autocomplete menu.

Prompt in zsh starts with ↑255 after an error command?

I'm new to zsh and am using the ZSH_THEME="jnrowe", which works great for a little while.
It starts out and I get a prompt that looks like this:
Ξ ~ →
but if I run a command like: ssh it becomes:
↑255 ~ →
I suspect something is messing up the character that was creating the triple bar in the first one, but have no clue really as to what's going on. I could just pick a different theme, but I've noticed most of them with a fancy character in the prompt do the same thing.
Is this a special error code or something? Or is something just borking out?
I don't know the prompt theme "jnrowe" (it's not part of the default zsh distribution afaics), but I suspect this prompt includes the error code of the last command in its output.
Try to run "ls" or "true" and the number will disapper. Run "false" and it will be 1, run ssh without arguments and it will be 255. zsh preserves this value until you run the next command, so pressing ENTER many times will not clear it.
(This will be the same value that is stored in the shell variable "$?")

Resources