Trying to map <Ctrl>+<hjkl> to <Left Down Up Right> globally (Vim-like arrow keys) with xmodmap

10,768

Solution 1

It is surely very strange idea to turn Ubuntu into the codename "VimOS". I think much more adequate to map Vim's keys to some free and equable more cluster of the keyboard. Or definitely NOT due to it is also might be useful.

However I do not deletes my first suggest about Vim mappings and should to say that answer to your question exist here:
System wide vim-style (hjkl) navigation

Partially I agree this view (thanks to shell hell):

NOTE 3: Setting up Ctrl / Meta + H,J,K,L keybindings seems to be simplest way to have vim-style navigation but it’s not. First: you would have to do this on per application basis which is tiresome process. Second: you’ll probably end up breaking default mappings for any given application. Last but not least: some apps e.g. rtorrent or htop don’t let you change their defaults, save by patching their sourcecode. For similar reasons you won’t get job done with Super / Hyper, either.

And also I found near answer here:
Superuser: Mapping Super+hjkl to arrow keys under X

Vim uses a switching modes to mapping keys. So xmodmap for Vim it is some pluggable globals what breaks classic Vim experience. Even so to claim it sounds pathetic ;)

Vim supports several editing modes - normal, insert, replace, visual, select, command-line and operator-pending. You can map a key to work in all or some of these modes.

Mapping keys in Vim - Tutorial (Part 1)
Mapping keys in Vim - Tutorial (Part 2)
Mapping keys in Vim - Tutorial (Part 3)

Solution 2

I have Tux-J and Tux-K mapped to Up and Down in KDE, it is relevant for all applications. It is actually rather easy to configure.

  1. Go here: System Settings -> Custom Shorcuts -> Preset Actions
  2. Now right-click Preset Actions and choose New -> Global Shortcut -> Send Keyboard Input
  3. Call the new shortcut VIM-J
  4. In the Trigger tab click the Shortcut button and them press Tux-J.
  5. In the Action tab enter Down
  6. At the bottom of the window click Apply.
  7. Check that the shortcut works. If so, then configure the remaining HK and L keys.

Enjoy!

Share:
10,768

Related videos on Youtube

StrugglingProgrammer
Author by

StrugglingProgrammer

The road to success is paved with compilation errors.

Updated on September 18, 2022

Comments

  • StrugglingProgrammer
    StrugglingProgrammer over 1 year

    I am trying to map Ctrl+H,J,K,L to arrow keys Left,Down,Up,Right, respectively, on Ubuntu OS (globally, not inside Vim).

    I've attempted the solution posted here, but the modifier commands are not working. Here is what I am trying:

    xmodmap -e "keycode 45 Control_L = k Up"
    xmodmap -e "keycode 45 control = k Up"
    

    (keycode 45 maps to K)

    Neither commands work. (They give no errors, but Ctrl+K is not remapped to Up Arrow)

    Is there a way to do this xmodmap, and if not, is there a cleaner workaround?

    Thanks!

    Edit: I have found my answer here - thanks to swift

  • StrugglingProgrammer
    StrugglingProgrammer almost 10 years
    Hi swift, thanks for the reply. Perhaps I was unclear in asking my question. I am not attempting to do any key remaps inside of Vim. I'm actually trying to map ctrl+hjkl to arrow keys-left, down, up, right, respectively, on my GNU/Linux Ubuntu distribution. The post I linked claims that this is possible (indirectly), but I am unable to achieve this successfully.
  • swift
    swift almost 10 years
    sorry, I understood your first edition not right. ok, will update answer )
  • jeremyjjbrown
    jeremyjjbrown almost 6 years
    VimOS! Where do I get it?
  • swift
    swift over 2 years
    Make it from xmonad! 😃