Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have my gvim setup so that I can select word-wise with Ctrl-Shift-Right, Ctrl-Shift-Left etc. (yes, I know it's a bad habit, but it works for me..).

Unfortunately, these key combinations delete text when used in console vim inside a screen session. I believe this is because the two key combinations produce the codes <Esc>[1;6D and <Esc>[1;6C on the terminal, which are interpreted as "delete next 6 lines" or "change next lines", respectively.

Is there some way to stop screen or console vim from interpreting these key combinations?

UPDATE: Content of my .screenrc:

sessionname daku
startup_message off
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "
share|improve this question

3 Answers 3

up vote 2 down vote accepted

Clearly Vim doesn't have a binding for the key sequence ␛[1;6D but has one for some other key sequence that begins with ␛[1, probably ␛[1~ (usually sent by the Home key). Add remappings to your .vimrc to declare that ␛[1;6D is really Ctrl+Shift+Left and so on. I think the following should do the trick:

noremap <ESC>[1;6D <C-S-Left>
noremap! <ESC>[1;6D <C-S-Left>
noremap <ESC>[1;6C <C-S-Right>
noremap! <ESC>[1;6C <C-S-Right>

Here's what I have in my .vimrc:

function Allmap(mapping)
  execute 'map' a:mapping
  execute 'map!' a:mapping
endfunction
function Allnoremap(mapping)
  execute 'noremap' a:mapping
  execute 'noremap!' a:mapping
endfunction
call Allmap('<ESC>[6D <C-S-Left>')
call Allmap('<ESC>[6C <C-S-Right>')
call Allnoremap('<C-S-Left> <C-Left>')
call Allnoremap('<C-S-Right> <C-Right>')
share|improve this answer
    
Doesn't quite work; see my updated answer. –  daniel kullmann Jan 23 '12 at 8:20
    
@danielkullmann Sorry, I was careless in copying code from my .vimrc. I've updated my answer, which still doesn't exactly match yours. Please move your answer from your question to an answer. –  Gilles Jan 24 '12 at 1:15
    
why do you call map twice for each key combination? –  daniel kullmann Jan 24 '12 at 7:44
    
@danielkullmann :map and :map! cover different modes (normal & friends vs insert & friends). –  Gilles Jan 24 '12 at 15:16
    
In linux, both ctrl+leftarrow and ctrl+rightarrow goes to right position with this answer. –  Arda May 28 at 10:35

This is what is in my .vimrc now:

if ! has("gui_running")
  noremap  <ESC>[1;6D <C-S-Left>
  inoremap <ESC>[1;6D <C-S-Left>
  noremap  <ESC>[1;6C <C-S-Right>
  inoremap <ESC>[1;6C <C-S-Right>
endif
share|improve this answer
    
In linux (ubuntu 14.04, default terminal), both ctrl+leftarrow and ctrl+rightarrow goes to right position with this answer on my case. –  Arda May 28 at 10:35

Move the binding from ~/.vimrc into ~/.gvimrc.

share|improve this answer
    
This happens everywhere, also on computers where I don't have a .vimrc. –  daniel kullmann Jan 19 '12 at 14:18
    
What is in your .screenrc? –  William Pursell Jan 19 '12 at 15:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.