3

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 "

3 Answers 3

3

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>')
7
  • Doesn't quite work; see my updated answer. Jan 23, 2012 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. Jan 24, 2012 at 1:15
  • why do you call map twice for each key combination? Jan 24, 2012 at 7:44
  • @danielkullmann :map and :map! cover different modes (normal & friends vs insert & friends). Jan 24, 2012 at 15:16
  • In linux, both ctrl+leftarrow and ctrl+rightarrow goes to right position with this answer.
    – Arda
    May 28, 2014 at 10:35
0

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
1
  • 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, 2014 at 10:35
-1

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

2
  • This happens everywhere, also on computers where I don't have a .vimrc. Jan 19, 2012 at 14:18
  • What is in your .screenrc? Jan 19, 2012 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .