0

I am using macOS Monterey 12.5 on M1 hardware. In case this can be relevant, I am using an American keyboard with Brazilian Portuguese (ABNT2) as input.

Also, I am using a cool software Karabiner Elements to configure my keybindings. I have made a special effort to create an Emacs UX in macOS. This is my config file.

In addition, I am using bash and this is my .bash_profile file:


export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export TFR_RELEASE="xx-xx"
export TFR_DEV="xx-xx"

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
export PATH="/usr/local/bin:$PATH"
eval "$(/opt/homebrew/bin/brew shellenv)"

When I am on the terminal, I can use commands such as C-a (beginning of line), C-k (kill line), C-f (character forward), C-b (character backward), and others such as C-u.

The point that really annoys me is that M-f and M-b to move around words do not work on the terminal. They do work in other parts, such as the bard address of browsers and, obviously, in Emacs.

M-f generates this (integral, apparently) "∫" character. And M-b generates this (unknowns named for me) "đ" character. Also, C-M-b and C-M-b do not work either to generate this movement around words. I believe they were the default on macOS to generate this movement.

Considering this and this question, I thought it would default to have M-f and M-b keybindings to move forward and backward around words.

How can I solve this?

5
  • 1
    There’s a lot going on here. If you make a brand new user account with zero modifications, are you able to sort out if Apple keybindings are in play? I would check zsh in addition to bash if possible.
    – bmike
    Commented Sep 4, 2022 at 2:57
  • 1
    bash uses readline. If you want certain keybindings, you need to configure them in ~/.inputrc. Commented Sep 4, 2022 at 14:42
  • I do not have such a file. Should I create one? Commented Sep 4, 2022 at 14:48
  • 1
    If you want to configure keybindings in bash, yes. Commented Sep 4, 2022 at 17:45
  • Is it that the meta key does not work in general, or is it just not interpreted by bash. In the former case, have look here: shell-tips.com/mac/meta-key Commented 2 days ago

1 Answer 1

3

Here is what I use under bash:

# Enable emacs key bindings
set -o emacs

# Configure key bindings
bind '"\C-p": history-search-backward'
bind '"\C-n": history-search-forward'
bind '"\ef": forward-word'
bind '"\eb": backward-word'

and this for zsh:

# Enable emacs key bindings
bindkey -e

# Configure key bindings
bindkey '^p'  history-search-backward
bindkey '^n'  history-search-forward
bindkey '^[f' emacs-forward-word
bindkey '^[b' emacs-backward-word

Regarding the OP, the specific solution is in the binding in lines 3 and 4.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .