0

In iTerm2 (and also in terminal) for OS X in Vim 7.4.1941 I'm trying to map alt-right to move one word to the right and alt-left to move one word to the left. In .vimrc I have

noremap <A-LEFT> b
noremap <A-RIGHT> w

The alt-left one works but the alt-right one does nothing...

Also I'm trying to map Shift right to enter visual mode and hit 'right' map <S-RIGHT> v<RIGHT> and shift left to enter visual mode and move left map <S-LEFT> v<LEFT>. Instead what happens is shift right does nothing and shift left gives an error: E388: Couldn't find definition. And my map configuration (see below) doesn't state other plugins setting these mappings so I'm not sure what's going on.

n  \j            <Plug>(CommandTJump)
n  \b            <Plug>(CommandTBuffer)
n  \t            <Plug>(CommandT)
v  gx            <Plug>NetrwBrowseXVis
n  gx            <Plug>NetrwBrowseX
v  <Plug>NetrwBrowseXVis * :<C-U>call netrw#BrowseXVis()<CR>
n  <Plug>NetrwBrowseX * :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())<CR>
n  <Plug>(CommandTTag) * :CommandTTag<CR>
n  <Plug>(CommandTSearch) * :CommandTSearch<CR>
n  <Plug>(CommandTMRU) * :CommandTMRU<CR>
n  <Plug>(CommandTLine) * :CommandTLine<CR>
n  <Plug>(CommandTCommand) * :CommandTCommand<CR>
n  <Plug>(CommandTJump) * :CommandTJump<CR>
n  <Plug>(CommandTHistory) * :CommandTHistory<CR>
n  <Plug>(CommandTHelp) * :CommandTHelp<CR>
n  <Plug>(CommandTBuffer) * :CommandTBuffer<CR>
n  <Plug>(CommandT) * :CommandT<CR>
v  <BS>          "-d
v  <D-x>         "*d
v  <D-c>         "*y
v  <D-v>         "-d"*P
n  <D-v>         "*P

Also my .vimrc:

" Use arrow keys
map <D-A-RIGHT> <C-w>l
map <D-A-LEFT> <C-w>h
map <D-A-DOWN> <C-w><C-w>
map <D-A-UP> <C-w>W

" Go to last active tab
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>
" Go to tab by number
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<CR>

" option/alt selection/navigation
noremap <A-LEFT> b
noremap <A-RIGHT> w
imap <A-RIGHT> <ESC>w
imap <A-LEFT> <ESC>b
vmap <A-RIGHT> w
vmap <A-LEFT> b

" shift+arrow selection
noremap <S-Up> v<Up>
noremap <S-Down> v<Down>
noremap <S-Left> v<Left>
noremap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <RIGHT>
imap <S-Up> <Esc>v<UP>
imap <S-Down> <Esc>v<DOWN>
imap <S-Left> <Esc>v<LEFT>
imap <S-Right> <Esc>v<RIGHT>

" Cut, copy, paste
vmap <C-c> y<Esc>i
vmap <C-x> d<Esc>i
map <C-v> pi
imap <C-v> <Esc>pi
imap <C-z> <Esc>ui

" Begin vim-plug plugins
call plug#begin('~/.vim/plugged')

Plug 'wincent/command-t', {
    \   'do': 'cd ruby/command-t && ruby extconf.rb && make'
    \ }


call plug#end()

EDIT

I've been able to get all keys except shift+ and shift+ mapped by using :map ctrl+k followed by the key/combination desired. Then using what ctrl+k outputted as they keycode instead of S-Up, S-Down etc. The only ones that don't seem to work are shift left and shift right. They both enter visual mode but they don't continue to register as left and right. I have to take my hand off the shift button to continue selecting... The suggestion made to install vim-fixkey helped in that it made this current configuration portable. Hopefully this helps those in the future with a similar setup. If anyone knows why shift-left and shift right aren't maping to h and l in visual mode that will complete the answer to my question. Alt keys work now. Updated config is as follows:

" Go to last active tab
nnoremap [5D :tabprevious<CR> " Ctrl+left
nnoremap [5C :tabnext<CR> " Ctrl+right
" Go to tab by number
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<CR>

" option/alt selection/navigation
nmap æ vw
nmap â vb
vmap â b
vmap æ w
imap â <Esc>vb
imap æ <Esc>vw

" shift+arrow selection
nmap [A vk " Shift+up
nmap <T-S-Up> vk
nmap [B vj " Shift+down
nmap <T-S-Up> vj
nmap [D vh " Shift+left
nmap [C vl " Shift + right

nmap <T-S-Right> vw
nmap <T-S-Left> vb
imap <T-S-Left> <Esc>vb
imap <T-S-Right> <Esc>vw
vmap <T-S-Left> b
vmap <T-S-Right> w

vmap [A k
vmap <T-S-Up> k
vmap [B j
vmap <T-S-Down> j
vmap [D h
vmap [C l
imap [A <Esc>vk
imap <T-S-Up> <Esc>vk
imap [B <Esc>vj
imap <T-S-Down> <Esc>vj
imap [D <Esc>vh
imap [C <Esc>vl

" Cut, copy, paste
vmap <C-c> y<Esc>i
vmap <C-x> d<Esc>i
map <C-v> pi
imap <C-v> <Esc>pi
imap <C-z> <Esc>ui
thed0ctor
  • 1,350
  • 4
  • 17
  • 34
  • Some of this boils down to your terminal, and what it's capable of encoding. Depending on your environment, [vim-fixkey](https://github.com/drmikehenry/vim-fixkey) might be helpful to you. The [docs](https://github.com/drmikehenry/vim-fixkey/blob/master/doc/fixkey.txt) are definitely worth a read. – John Szakmeister Jul 07 '16 at 23:58
  • Yes, I know you (sadly) can't remap Shift-Enter in iTerm2. I'm not sure about your mappings. You might have more luck using macvim instead of iTerm. – lwassink Jul 08 '16 at 04:03
  • The `` key is invisible to Vim and `` is indistinguishable from ``. Use other more portable mappings or, better, get used to Vim's default commands since they are much more efficient than anything you could come up with. – romainl Jul 08 '16 at 06:28

0 Answers0