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"
    
chicks
  • 332
  • 1
  • 5
  • 13
Brett Holman
  • 153
  • 1
  • 8
  • 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 07 '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 07 '17 at 19:05
  • 1
    that should work out of the box in insert mode. – Christian Brabandt Mar 08 '17 at 08: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 08 '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 06 '17 at 17:47
  • @ChristianBrabandt.. agree.. Was reading the help manuals, and came cross this passage in “usr_24.txt”VIM manual file, with name “inserting quickly”: These special keys are most useful when writing a mapping that doesn't leave Insert mode. The extra typing doesn't matter then. An overview of the keys you can use in Insert mode: to start of the file. a whole screenful up to start of line one word left, one word left one word right one word right to end of the line .... – alpha_989 Oct 06 '17 at 13:23
  • 1
    Some of these commands do work, however Cntrl + left/right doesnt work.. – alpha_989 Oct 06 '17 at 13:23
  • I dont see any particular switch mentioned in the text. I am using VIM with some plugins. Not sure whether those plugins are turning some mode off.

    Do you know whether there is any specific switch that has to be turned on for Cntrl + left etc to work?

    – alpha_989 Oct 06 '17 at 13:25
  • Maybe I am answering my own question.. but I just had a hypothesis that it was because I was interacting with vim through tmux and ssh, so maybe the keys are not being sent through. I tested it by directly logging into the server using the GUI. and Cntrl+left/right does work when using the UBUNTU GUI. I will leave the above comment, in case somebody else has the same problem. – alpha_989 Oct 06 '17 at 13:28
  • @alpha_989 in retrospect, your suggestion is really the best. Vimtutor and learning to use vi/vim as it was intended is the best route to truly taking advantage of the power of it. I look back at this question and chuckle at how little i knew about Vim. Nowadays I never touch arrow keys and I love the various visual modes. Thanks for the help! – Brett Holman Dec 03 '17 at 05:07

3 Answers3

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.

laktak
  • 2,933
  • 13
  • 27
  • Thanks the help. Unfortunately this didn't work, however I've added the requested information above. – Brett Holman Mar 07 '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 07 '17 at 21:42
  • When I do that I get ^[[A. I'm assuming I do something like <xUp>=\e[[A? – Brett Holman Mar 07 '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 08 '17 at 12:31
  • bash->Ubuntu 14.04 (server) -> Virtualbox -> Windows 10 – Brett Holman Mar 08 '17 at 15:09
  • @BrettHolman with termial I mean the app you use to start bash. If Ctrl+cursor does not work at all it's more of a topic for askubuntu though. – laktak Mar 08 '17 at 19:25
  • I am not using any desktop environment, just CLI. I've used Unity and Gnome on Ubuntu 14.04 Desktop in the past, but I am currently using Ubuntu 14.04 Server which comes without any desktop, so when I power up it literally starts me in bash. I am unsure how to check the terminal type. You might be right about taking this to askubuntu. – Brett Holman Mar 09 '17 at 16:35
  • that's the framebuffer - it probably does not support that. just install any lightweight gui. – laktak Mar 09 '17 at 18:27
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.

alpha_989
  • 901
  • 7
  • 15
  • 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 07 '17 at 20:32
0

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

icc97
  • 583
  • 1
  • 6
  • 16