Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default key bindings in vim

Tags:

vim

After attempting to use vim a number of times, I'm always been put off by its default key bindings. After some research, I decided to remap the default keys to more sane ones (at least for my tastes). I have a few questions about changing bindings that I could not find answers to through Google.

  1. Is there a way to map a key to an action rather than another key. For example:
    :noremap a h
    will bind the a key to move the cursor left. Is there something along the lines of
    :noremap a move-cursor-left
    or
    :noremap a :move-cursor-left<Enter>
    so I can read my config file afterwards?

  2. Is there a way to unbind all of the default key bindings? I've tried :mapclear but it doesn't seem to work, although it might just be clearing non-default bindings. Unmapping every key manually is not an option. If possible, I would like to export the defaults to a file so I can edit them as I need.

  3. Is there another language I can use to write my own commands for vim other than vim-script? I haven't actually looked into this one so much though. If I can bind an external executable to a command, that would be good enough.

  4. I haven't given up on vim although I would like to ask if there are any vim-like alternatives out there. My Google searches came up with nothing actively developed. If the above cannot be done, or reasonably hacked together, I would like to find a fully configurable, modal, command line text editor that can.

like image 827
Lindenk Avatar asked Jul 29 '26 20:07

Lindenk


2 Answers

(i know this question is old)

you can reset the binds by just over-writing them

on vim you can use many <things> (idk the name)
e.g.
<Up> = Up-arrow-key
<C-f> = Ctrl, f
<A-Down> = Alt, Down-arrow-key
<Esc> = Escape-key

it's possible to remap the hjkl keys to wasd like this:

nmap w <Up>
nmap a <Left>
nmap s <Down>
nmap d <Right>

like image 65
OwseiWasTaken Avatar answered Aug 01 '26 11:08

OwseiWasTaken


The command set of vi / Vim has lasted for over 40 years; completely changing it is a bad idea (but many have tried). Like the QWERTY keyboard layout (initially devised to slow down typing), it's surely not optimal (and if one were to redesign it from scratch it would look much different), but by now so many conventions and uses have grown around it that the benefits of a different model cannot get close to the consistency of the status quo.

I can only repeat the reference to this answer from the comments; that should convince you (to accept this, or choose another editor).

Give the default commands another try. It'll take some time to get used to, but most Vim users swear by these. It's fine to make minor adjustments "for personal style": careful evolution, but not revolution. Also, some people with odd keyboard layouts (like Dvorak or Colemak) swap several keys for convenience.

The move-cursor-left is just h; aided by the excellent :help, you should be able to "read" your remappings just fine.

In general, even though it's possible to write extensions / plugins in integrated languages like Perl, Python, Ruby, etc. (based on support for them compiled into the Vim binary), you won't get around learning some key Vim internals and parts of Vimscript. If you don't feel comfortable at all about this, I'd suggest to use another editor. Unfortunately, with your requirements of full extensibility (and probably broad acceptance and platform support), there's only one serious alternative: Emacs (which cannot only be turned into everything but a kitchen sink, but also into a modal editor, too).

like image 22
Ingo Karkat Avatar answered Aug 01 '26 11:08

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!