geekhack

geekhack Community => Ergonomics => Topic started by: wolfv on Tue, 09 April 2013, 21:53:16

Title: Vim on non-QWERTY layout?
Post by: wolfv on Tue, 09 April 2013, 21:53:16
I am a Vim user interested in using a Colmak or Arensito keyboard layout.
Would love to hear from people that have tried Vim on non-QWERTY layouts.

Is it possible to have the best of both worlds: Vim and a good keyboard layout?
I am leery of the hjkl vi arrow keys being off the home row.

Thank you for sharing your experience.
Title: Re: Vim on non-QWERTY layout?
Post by: oneproduct on Tue, 09 April 2013, 23:25:55
I had some trouble with this too when I first started to use Vim. At first I tried to remap everything, but in the end, I found something simpler. Surely you must know about WASD cursor movement on Qwerty? Another variation of that is ESDF, one set of keys to the right. This leaves your index finger on the homing bar on the left side of the keyboard. On Colemak, this would be FRST.

In Vim, R and S are quite similar, and both are similar to C. F and T are again both similar. Also, FTRS are somewhat less critical than other Vim functions (C can often do what R and S can do or you can use X or D paired with I; F and T can be accomplished with other movement techniques or a general search), which is good because we don't want to cause too much disruption when reassigning keys. We then have HJKL as remappable, and I've done the following:

//change FRST to up, left, down, right respectively
R --> H
S --> J
T --> L
F --> K

H --> S (s stands for substitute and in my mind is now hotSwap)
K --> R (r stands for replace and in my mind is now Kill)
J --> F (f goes before the next instance of a character, maybe it was Forward (?) but now I call it Jump)
L --> T (t goes To the next instance of a character which is similar to Forward. Now I call it Leap, which is similar to Jump but a leap is further)

The rest I keep the same, so you can still find most commands by pressing the letter that goes along with their mnemonic. As a bonus, H and K on Colemak are still next to each other as are J and L, so it makes a lot of sense physically.

In general though, using FRST simply avoids worse problems when trying to find 4 keys that are next to each other to take the place of arrows. If you did a direct HJKL to HNEI on Colemak then you lose Next and Insert which are quite notable to lose.
Title: Re: Vim on non-QWERTY layout?
Post by: wolfv on Wed, 10 April 2013, 00:37:10
Thank you oneproduct.  Your remapping strategy makes sense.
Title: Re: Vim on non-QWERTY layout?
Post by: SimpleRabbit on Wed, 10 April 2013, 00:49:43
Hallo, I'm another Colemak user. I've been using it for around 4-5 years alongside Vim and highly recommend it with or without Vim! I actually have a better experience with Vim in Colemak than I did in Qwerty.

My mappings are fairly simple...keep the homerow keys "hjkl" -> "hnei"...that means k, j, and l are now free and n, e, and i need to be accounted for.
Here're my Colemak key mappings I've been very happy using for 4+ years:
Code: [Select]
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colemak Mappings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" hnei = arrows
  noremap n gj|noremap e gk|noremap i l|noremap gn j|noremap ge k
" s/S = inSert
  noremap s i|noremap S I
" k/K = last search
  noremap k n|noremap K N
" l/L = BOL / EOL | <c-l> = join lines
  noremap l ^|noremap L $|noremap <C-l> J
" j/J = end of word
  noremap j e|noremap J E
" _r_ = inneR text objects
  onoremap r i
" c-e/c-n/c-m or <cr> = High/Low/Mid
  noremap <c-e> H|noremap <c-n> L|noremap <c-m> M
" shift+direction switches split panes
  noremap H <C-W>h|noremap I <C-W>l|noremap N <C-W>j|noremap E <C-W>k
" c-h/c-i switches tabs [inoremap <c-i> messes up insert-mode tabbing]
  nnoremap <c-i> <C-PageDown>|nnoremap <c-h> <C-PageUp>
" U = Redo with U
  noremap U <C-r>

" Not Colemak specific, but I like it :)
  noremap ; :

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDTree
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  let g:NERDTreeMapJumpFirstChild      = "ge"
  let g:NERDTreeMapJumpLastChild       = "gn"
  let g:NERDTreeMapToggleHidden        = "H"
  let g:NERDTreeMapOpenSplit           = "S"

The only inconvenience I've experienced was a plugin [forget which] that hard coded "map"s into it, so I had to crawl through their source to fix them, but wound up not using the plugin anyways. Surround.vim, NERDTree, and others all have worked nicely for me.
Title: Re: Vim on non-QWERTY layout?
Post by: SimpleRabbit on Wed, 10 April 2013, 01:15:30
Related, here are my Colemak .lessrc and .pentadactylrc [vimperatorrc] if you use them as well.

Full ~/.lessrc
Code: [Select]
#command
n forw-line
e back-line

N forw-line-force
E back-line-force

d forw-scroll
u back-scroll

f forw-screen
b back-screen

/ forw-search
? back-search
k repeat-search
K reverse-search

g goto-line
G goto-end
% percent

Snippet for ~/.pentadactylrc
Code: [Select]
" Standard Vim 'Homerow' Arrows
map -builtin n <Down>
map -builtin N 20<Down>
map -builtin e <Up>
map -builtin E 20<Up>
map -builtin i l
map -builtin I L

" k/K = repeat/reverse last search
map -builtin k n
map -builtin K N

" switch command line mode / extended hint mode
map -builtin ; :
map -builtin : ;

" select next/previous tab
map -builtin <c-i>   gt
map -builtin <c-h>   gT
imap -builtin <c-i>  <esc>gt
imap -builtin <c-h>  <esc>gT

" move current tab left/right
map -builtin <c-s-I>   :tabmove! +1<CR>
map -builtin <c-s-H>   :tabmove! -1<CR>
Title: Re: Vim on non-QWERTY layout?
Post by: pyro on Thu, 11 April 2013, 13:24:10
I use Dvorak and Vim. Haven't changed anything, because its just fine like that.
Title: Re: Vim on non-QWERTY layout?
Post by: eviltobz on Fri, 12 April 2013, 14:34:14
I switched to colemak a few months ago and I'm also something of a novice vim user (actually I mostly use vsvim as a vim emulation layer in visual studio, but it's the same sorta thing). I looked at the official colemak vim rebindings, but decided to stick to the normal setup to avoid confusing myself when reading vim tips etc and it's working ok for me. Were I less lazy might have tried making j & l be left and right and h & k be up and down to make a slightly more meaningful positioning, but, well, lazy.

One of the key drivers to my not changing anything is from seeing advice about people temporarily turning off hjkl in vim to force the use of other navigation techniques. As a novice vimmer that home row feels like a good draw, but there is so much to the range of motions that you can do it is good to try and ditch that char by char mentality for most things. Whilst I'm at it I'll pimp this ere book too: http://pragprog.com/book/dnvim/practical-vim (http://pragprog.com/book/dnvim/practical-vim) for maximal vimmy goodness :)
Title: Re: Vim on non-QWERTY layout?
Post by: wolfv on Fri, 12 April 2013, 15:23:12
eviltobz,

I haven't seen that Vim book before, it's new.  The reviewers at Amazon love it.

Turning off hjkl in vim is a great idea!  That experience will help me decide to remap keys or not, as well as force me to use more advanced vi navigation.

Thanks for all your inputs.  You have all been very helpful.
Title: Re: Vim on non-QWERTY layout?
Post by: sordna on Sat, 13 April 2013, 14:48:13
I use Dvorak and Vim. Haven't changed anything, because its just fine like that.

I'm using Dvorak and doing exactly the same! Although I tend to use regular arrow keys more often than hjkl, since they are so easy to reach on the Kinesis Advantage.