4

I am new to Vim, however I am learning to love it. As a former/current Windows user, there is one shortcut that I depend on and would like to configure in Vim.

On windows I can use ctrl-arrow left and ctrl-arrow right to skip over words left and right.

I just don't want to press the over arrow a bunch of times when moving any text within the editor. It can be really handy to just right over four words by pressing the arrow four times (with control held down).

Example of functionality I want

Let's say my cursor is represented by a pipe: |

Sample text:
The brown |fox jumped over the lazy dog.  " before pressing ctrl-[right arrow]
The brown fox |jumped over the lazy dog.  " after  pressing ctrl-[right arrow]
  • Has anybody else had similar interests?
  • Is there an easy way to get identical/similar functionality?
  • Any help would be much appreciated!
  • Sorry if I messed up any terminology (let me know and I will update anything that needs fixing).

Update: Thanks for the responses. It's good to know that this is possible with w and b. I will settle for that if needed, however I would like to attempt this anyways for the sake of learning from the exercise, as well as for future vim users attempting this.

  • I am currently using Bash on Ubuntu 14.04 server running in VirtualBox on Windows 10.
  • I edited my vimrc (found in /etc/vim/vimrc) to show this at the end of the file

    execute "set <xUp>=\e[1;*A" 
    execute "set <xDown>=\e[1;*B"
    execute "set <xRight>=\e[1;*C"
    execute "set <xLeft>=\e[1;*D"
    
11
  • 9
    In Vim you would typically do this with w, b, and some related motions. By default this is actually mapped to <C-Left> and <S-Left> already. Mar 7, 2017 at 18:05
  • @Brett : You may have a look at vimtutor for basic vim commands.If you are really interested in vim, let me tell you.VIm has awesome features with respect to editing. Learn about motions, commands, mappings, etc
    – SibiCoder
    Mar 7, 2017 at 19:05
  • 1
    that should work out of the box in insert mode. Mar 8, 2017 at 8:07
  • I recommend using your user's .vimrc (~/.vimrc) so you don't need root if you want to copy your mappings to another computer.
    – Lstor
    May 8, 2017 at 15:33
  • 1
    Some of these commands do work, however Cntrl + left/right doesnt work..
    – alpha_989
    Oct 6, 2017 at 13:23

3 Answers 3

3

This is most likely because you are using the CLI. In CLI Cntrl + Left doenst work natively in VIM. I am using TMUX/SSH into UBUNTU installed in a virtualbox on windows 10, similar to your situation (no X-server running on my Windows 10).

Cntrl+left/right doesnt work when I log in using TMUX/SSH (with no Xserver), however when I use the VIM on the UBUNTU GUI, it does work.

Use the UBUNTU GUI.

1
  • thanks for the comment. As noted in the post, I was using Ubuntu server at the time of this question, so it didn't have a GUI. That being said, I found that it is much more natural to use use w and b alongside other traditional vim movement commands: ^, 0, and $, etc Oct 7, 2017 at 20:32
3

If Vim exits insert mode and appears to do nothing you may need to tell it to use xterm keys.

Add this to your .vimrc:

execute "set <xUp>=\e[1;*A"
execute "set <xDown>=\e[1;*B"
execute "set <xRight>=\e[1;*C"
execute "set <xLeft>=\e[1;*D"

If this does not help let us know what OS/terminal you are using.

8
  • Thanks the help. Unfortunately this didn't work, however I've added the requested information above. Mar 7, 2017 at 21:34
  • But what happens on Ctrl-Up? Type Control-V and then Control-Cursor Up in insert mode to see what your terminal sends (e.g. I get ^[[1;5A).
    – laktak
    Mar 7, 2017 at 21:42
  • When I do that I get ^[[A. I'm assuming I do something like <xUp>=\e[[A? Mar 7, 2017 at 22:11
  • @BrettHolman If you get ^[[A then you either forgot to press "control up" or your terminal does not support it at all. What are you using? Try Gnome or urxvt.
    – laktak
    Mar 8, 2017 at 12:31
  • bash->Ubuntu 14.04 (server) -> Virtualbox -> Windows 10 Mar 8, 2017 at 15:09
0

On Windows and Ubuntu, GVim works with Ctrl + Arrow.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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