2

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"
    
  • 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. – Martin Tournoij Mar 7 '17 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 '17 at 19:05
  • 1
    that should work out of the box in insert mode. – Christian Brabandt Mar 8 '17 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 '17 at 15:33
  • agree with @carpetsmoker .... when I moved to vim around a month or so back, using vim on ubuntu virtual box.. I missed cntrl+left etc. after a while, you get used to pressing escape and then moving around in normal mode instead. However, I can see that it could be benefitical to be able to move around faster using contrl left and right in insert mode. This is because a lot of times, i just need to move a few words to the right or left, and get into insert mode again. This is a overkill as I need to get into and out of normal mode lot more times than necessary.. – alpha_989 Sep 6 '17 at 17:47
1

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.

  • 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 – Brett Holman Oct 7 '17 at 20:32
0

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.

  • Thanks the help. Unfortunately this didn't work, however I've added the requested information above. – Brett Holman Mar 7 '17 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 '17 at 21:42
  • When I do that I get ^[[A. I'm assuming I do something like <xUp>=\e[[A? – Brett Holman Mar 7 '17 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 '17 at 12:31
  • bash->Ubuntu 14.04 (server) -> Virtualbox -> Windows 10 – Brett Holman Mar 8 '17 at 15:09
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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