Although I played with it before, I'm finally starting to use Dvorak (Simplified) regularly. I've been in a steady relationship with Vim for several years now, and I'm trying to figure out the best way to remap the key bindings to suit my newfound Dvorak skills.
How do you remap Vim's key bindings to best work with Dvorak?
Explanations encouraged!
I use one of the more common recommended keybindings:
Dvorak it!
no d h
no h j
no t k
no n l
no s :
no S :
no j d
no l n
no L N
Added benefits
no - $
no _ ^
no N <C-w><C-w>
no T <C-w><C-r>
no H 8<Down>
no T 8<Up>
no D <C-w><C-r>
Movement keys stay in the same location. Other changes:
Delete 'd' -> Junk 'j'
Next 'n' -> Look 'l'
Previous 'N' -> Look Back 'L'
There were also some changes for familiarity, 's'/'S' can be used to access command mode (the old location of the :, which still works).
Added Benefits
End of line '$' -also- '-'
Beginning of line '^' -also- '_'
Move up 8 'T'
Move down 8 'H'
Next window <C-w><C-w> -also- 'N'
Swap windows <C-w><C-r> -also- 'D'
-Adam
I don't find that I need to remap the keys for Dvorak -- I very quickly got used to using the default keybindings when I switched layouts.
As a bonus, it means that I don't have to remember two different key combinations when I switch between Dvorak and Qwerty. The difference in keyboard layout is enough that I'm not expecting keys to be in the same location.
A little late, but I use the following:
" dvorak remap
noremap h h
noremap t j
noremap n k
noremap s l
noremap l n
noremap L N
" easy access to beginning and end of line
noremap - $
noremap _ ^
This basically does the following:
left-down-up-right are all under the default finger positions on the home row (i.e. not moved over by one as in the default QWERTY Vim mappings)
l/L is used for next/previous search result
use -/_ to reach the end/beginning of a line
This seems to work for me...
I simply use standard qwerty for commands and dvorak for insert mode
Here is how to set it up
My rebindings:
noremap h h
noremap t j
noremap n k
noremap s l
noremap j t
noremap l n
noremap k s
noremap J T
noremap L N
noremap K S
noremap T J
noremap N L
noremap S K
Notes:
In qwert, vi has to use 'h', because vi doesn't want to use ';' a non-letter. But
in dvroak, we have 's', so why not take this advantage?
vi uses Caps for relative actions. This is a good design philosophy. So I try to
conform this.
Meanings:
n (Next) -> l (Left) -- "What's left?" resembles "What's next?"
s (Substitute) -> k (Kill then insert)
t (jump Till) -> j (Jump till)
N, S, T are similar.
J (Join lines) -> T (make lines Together)
K (Keyword) -> S (Subject)
L[count] (Line count) -> N (line Number)
B.T.W. L itself goes to the last line, and N is the last letter of fin.
(Thanks for tenzu to point out this.)
P.S. I have used these rebindings for a while. Now I does not use it in vim. I just use the default ones.
Vim ships with an extensive Dvorak script, but unfortunately it’s not directly source-able, since the file includes a few lines of instructions and another script that undoes its effects. To read it, issue the following command:
:e $VIMRUNTIME/macros/dvorak
You can use this to have Vim use Dvorak only in insert mode:
:set keymap=dvorak
This way all of the commands are still in QWERTY, but everything you type will be in Dvorak.
Caveats: Well, almost everything. Insert mode, search mode, and replace mode will all be dvorak, but ex commands will not. This means that you don't have to relearn :wq, but you will need type :%s/foo/bar/gc in QWERTY.
This won't help if you only want to move certain commands, but I found that in my head, "move forward one word" was bound to "move left ring finger up," rather than "ask the typing department where the letter 'w' is and then press it," which made this method much easier for me.
Related
The same goes for :q and :Q. I almost always don't let up on shift quick enough and seeing that :Q and :W aren't used anyway I thought it would be nice to just have them do the same as their lower-case counterparts.
The hack is via a :cmap or :cabb, but these have side effects (i.e. other instances will be inadvertently converted, too).
The cmdalias plugin does this better.
But I think for your use case it's best to define your own uppercase command-variants. The main challenge is to support all the options that the original one has:
command! -bang -range=% -complete=file -nargs=* W <line1>,<line2>write<bang> <args>
command! -bang Q quit<bang>
Yes, you can remap them in your .vimrc like so:
cabb W w
cabb Q q
or
cmap W w
cmap Q q
The downside is that it "W" will expand to "w" with both cases (cmap displays the change, cabb does not).
It's generally quite easy to remap keys to suit your needs in Vim. Try looking at the following tutorial: Mapping keys in Vim
edit:
As #IngoKarkat points out, this is a hackish solution. I'm leaving it here because it's fast and easy. However, the downside is clear; it interferes with other uses.
noremap works for me with no known side effects
noremap :W :w
Assuming you're looking for a quicker way to do :wq
Really this is a combo of ESC then : (which itself is Shift+;) then w then q then Enter. Five keystrokes, six if you count : as two.
Instead, try ESC then (holding) Shift press Z then Z again (no : at all). It will save and quit the file immediately. One less keystroke (or two, depending upon how you count it) plus much harder to mess up.
You can define W and Q by adding the following entries to your .vimrc:
command! W write
command! Q quit
This is not an answer to your question, but a solution to your problem — "I almost always don't let up on shift quick enough". Swap the meaning of the colon and semicolon. Then no shift is needed, as you will use ;w and ;q.
nnoremap ; :
nnoremap : ;
vnoremap ; :
vnoremap : ;
Hi!
For about 3 last weeks, I have been using Vim. I must say, I love the navigation keys on the home row!
A week ago I switched to Dvorak, and the new location of the movement keys, simply doesn't let me use Vim. It's terrble.
So, I wonder, is there a way to keep movement keys in Dvorak, in the same location as in qwerty?
I don't want to remap keys, as that would be super-confusing. One way I can think of is to assign the function i.e go up one line from key k to t.
So I could have my movement keys in dvorak(d h t n) layed out as in qwerty (h j k l)
Is it possible? How can I do that?
I don't want to remap keys, as that would be super-confusing
You probably want to remap keys, but just in Vim. However the fine people over at vim.wikia.com doesn't think this is such a good idea.
One alternative, as mentioned in the linked article, is to use dvorak in insert mode, and qwerty-position of binds in normal mode, i.e. w = ", i = c etc.
set
langmap='q,\,w,.e,pr,yt,fy,gu,ci,ro,lp,/[,=],aa,os,ed,uf,ig,dh,hj,tk,nl,s\;,-',\;z,qx,jc,kv,xb,bn,mm,w\,,v.,z/,[-,]=,\"Q,E,PR,YT,FY,GU,CI,RO,LP,?{,+},AA,OS,ED,UF,IG,DH,HJ,TK,NL,S:,_\",:Z,QX,JC,KV,XB,BN,MM,W<,V>,Z?
-
One way I can think of is to assign the function i.e "go up one line" from key k to t, so I could have my movement keys in dvorak(d h t n) layed out as in qwerty (h j k l)
Is it possible? How can I do that?
Remember that doing such a thing could break other keys, I can't really tell as it's hard without actually trying/comparing each key. You could however remap all of those keys to custom positions if you'd want to using nnoremap etc.
A basic remapping would be just to remap the home row like this.
nnoremap d <Left>
nnoremap h <Down>
nnoremap t <Up>
nnoremap n <Right>
All in all I don't think it's such a good idea to combine two keyboard layouts, so just remapping home row is probably the safest, and then learn that e etc. has custom positions compared to qwerty.
These problems is why I never bothered to switch to Dvorak og Colemak, because I'd have to relearn all those binds that I have in my muscle memory, for a new vim user it might not be such a big issue though, so you're lucky that way!
I use a Dvorak keyboard layout, and so I've made a few adjustments to the default VIM mappings-- one change I've made is to remap the right-side home row keys to
noremap d h
noremap h j
noremap t k
noremap n l
So that movement keys are conveniently positioned, as they would be for a QWERTY user. h, t, and n do their job fine and are very responsive. d, however, lags for a moment before moving left the way its supposed to. I think this is because there are key-sequence commands that start with d (like dd for delete line), so VIM is waiting to receive the second stroke in the sequence before executing the command for just a single 'd'. I've remapped dd:
noremap dd hh
But this isn't doing the trick. Yet commands for things like d3w or d$ (text objects after d) aren't working (after remapping d), so they couldn't be causing the issue. Anyone know how to get rid of the lag? BTW, even after disabling all plugins I have the same issues. I also have no other mappings with d in my vimrc.
AFAIK, d, c and their "operator pending" friends are not really mappings. This means that you can't :unmap d. The delay you experience can't really be avoided without side effects, I believe.
You might want to play with :h timeout and :h timeoutlen.
For what it's worth, the alternative layouts/Vim story is… complicated. And not settled at all.
VimTutor says in its first lesson:
NOTE: The cursor keys should also work. But using hjkl you will be
able to
move around much faster, once you get used to it. Really!
However, I find no difference at all between them. Is there really a difference between using hjkl v/s the arrow keys?
You don't have to move your hand from the touch type position to use hjkl, whereas you do if you use the arrow keys.
The thing is that you start out using the "hjkl" key just as a slightly better way to move your cursor, but the truth is that they are actually motions.
h motions one character left
j motions one line down
k motions one line up
l motions one character right
So for example, with the delete operator d: dl deletes the current character, dh deletes the previous character, dj deletes the current line and a line below it, and dk deletes the current line and a line above it. The same is of course true for the y, c, V, gU and any operator.
Another example are split windows. You can create a couple of windows using Control-w+s and Control-w+v, then use your trusty hjkl to move around between your windows, Control-w+h moves a window left, Control-w+j moves a window down, etcetera.
So it's not just that they are an improvement over the arrow keys. As your understanding of Vim grows, you'll learn that the hjkl keys can be combined with other commands in many ways, and you will be happy you can use them.
In fact, using h j k l keys makes a good practice to avoid to much of right hand movimentation on your keyboard when you have to reach the arrow keys but, there are more efficient ways to navigate through a text file using vim:
f <char> : Go to the next occurrence of a character<char> on the current line. Cursor is placed above the character;
t <char> : Go to the next occurrence of a character<char> on the current line. Cursor is placed right before the character;
T and F: Backward your character search on this line, however T will put the cursor right after the character(or before if you think backwards ;) ), and F will put it above of it.
/ <char> <Enter>: Go the next occurrence of a character independent of line. After you do this one time, pressing n or N goes to the next and previous occurrence.
? <char> <Enter>: Go to the next occurrence of a character independent of line, backwards. n will search next occurrence(backwards) and N will go to the previous.
{ and } : Navigate on paragraphs. Paragraphs are basically blocks divided by an empty line. See :help paragraph for further details.
( and ) : Navigate back and forward on Sentences(:help sentence). A sentence is a group of words ended by . ! or ? followed by a space, tab or endline.
e : next word, place the cursor at the end of the word
w : next word, place the cursor at the start of the word
b : back 1 word, place the cursor at the start of the word
ge : back 1 word, place the cursor at the end of the word
E W B and gE : Same as e w b ge, but with WORD. See :help word for further details.
If you want to start by getting the first good habits of using h j k l or other movements and avoid the arrow keys, pleace the following lines on your .vimrc file inside your home to disable them:
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
I can map 'jj' to
imap jj <Esc>
and I can even map letters to tab navigation
map tj :tabprevious<CR>
map tk :tabnext<CR>
But I can't map g to page up (even though spacebar acts as page down)
map <Space> <PageDown>
map g <PageUp>
According to this "When you try to map multiple key sequences, you won't be able to start them with lower or upper case letters ("Too dangerous to map that"), but the punctuation and control characters are fair game." Can anyone confirm this?
If so, how does one assign a function to an unmapped key like 'g'
This isn't answering your question, but I thought it may be helpful to the problem you are having with your RSI. It maps the spacebar to toggle between fast and slow move modes. Normally pressing j or k will scroll down one line. Pressing space will turn on fast move mode, where pressing j or k will scroll down/up 10 lines. Press space again to go back to normal. This will only work in vim, not just plain vi (most "vi" programs are just symlinks to vim anyway though).
It works in both normal and visual edit modes.
To use it, put this code somewhere in your ~/.vimrc file:
map <Space> :call ToggleFastMoveMode()<CR>
vmap <Space> :call ToggleFastMoveMode()<CR>gv
let g:fastMoveMode = 0
function! ToggleFastMoveMode()
let g:fastMoveMode = 1 - g:fastMoveMode
if (g:fastMoveMode == 0)
noremap j j
vnoremap j j
noremap k k
vnoremap k k
else
noremap j 10j
vnoremap j 10j
noremap k 10k
vnoremap k 10k
endif
endfunction
(Edit - original answer suggested native Ctrl-f and Ctrl-b, but answer was updated as the goal here is to avoid using Ctrl and Shift)
A few points to add
Leaving the issue of choosing the right character to you, assuming we chose X for now.
I can think of two reasons why map X <PageUp> isn't working for you.
Your version of vi may not support PageUp/PageDown. If this is the issue then try instead to map to vi's page jumping (B for back, accompanied by for forward) eg. map X <C-b>.
Another other option is that it doesn't work 'as expected'. In vi PageUp/PageDown act on the 'viewport' not the cursor. So if you'r looking at the top of the file, but the cursor is not at the top or won't do anything. PageDown won't 'work' if your cursor is two lines from the bottom either.
To address this you could combine the 'move viewport up' <C-b> and the 'move cursor to the top of viewport' H eg. map X <C-b>H (The opposite being map X <C-f>L). Or specifying the number of lines to jump yourself map X 30k (Op. map X 30j).
Then the issue of choosing the right character to overwrite. Vi has a lot of native commands, so many in fact that only a handful of characters don't do something natively.
So if your goal is to avoid RSI, then of course overwrite something. But make sure to overwrite something that isn't too useful for you personally.
Natively:
f searches for a given symbol on the line you are currnetly on (can be very useful, but not critical I guess)
g on it's own does nothing, but gg moves cursor to top of file. Choosing g may cause issus as vim (not the original vi) will interpret two quick keypresses as go to top of file instead of do two PageUp's.