48

I am currently learning to use Vim. It has been a very good experience so far and I believe the Vim approach to be generally much more powerful than GUI based text editors.

There is however one feature that I miss. I sometimes have to read my document to correct potential mistakes. If I spot a mistake I need to move quickly to the position of the mistake, say in a middle of a sentence. In a standard text editor I will reach briefly for the mouse and point/click to move the cursor to this position.

This is slow, but in VIM it will take me much longer. Generally it is impractical to search for the word, because it may have spelling mistakes or occur many times. The fastest way I found is move to the line using line numbers, then move across sentences, then words, then letters. It is still much slower than reaching for the mouse, pointing and clicking.

My question is two-fold: is there a way to click with the mouse to move the cursor in Vim? I know that's not really the spirit but I think it could be useful occasionally. If not, am I doing something wrong? How do Vim users generally handle this problem of moving to a specific word you're looking at, far from where the cursor currently is, for example when you're reading back what you typed for mistakes?

Thanks

user1188374
  • 829
  • 2
  • 7
  • 9
  • 4
    this sort of heresy ought to be downvoted but you argued well ;) – mike3996 Feb 19 '15 at 20:44
  • Once you've learned the search and cursor positioning functions to the point of muscle memory, that will generally be faster than moving your hand from keyboard to mouse and back again... So keep learning/practicing. – twalberg Feb 19 '15 at 21:47
  • There's nothing wrong with using the mouse in a situation like this, but I usually get by without it. My method would be to keep the cursor close to the text I'm looking at, and if I want to change something, I just get to that point with line movement and then mashing `w` or `e`. This is more keystrokes than "paragraph-sentence-word", but requires a lot less thinking. For me, the power of Vim comes when you don't have to *think* about how you get to a place, and just rely on a simple, repeatable process. (Blog post: http://andrewradev.com/2011/04/26/my-vim-workflow-basic-moves/) – Andrew Radev Feb 20 '15 at 17:58

2 Answers2

89

If your terminal supports it adding

set mouse=a

to your vimrc will enable mouse support.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • Thanks! For other OS X users: this does not work in Terminal, but works in MacVIM. – user1188374 Feb 19 '15 at 20:39
  • 7
    @user1188374 iTerm2 supports the mouse. Terminal supports the mouse in recent versions of Mac OSX. (I forget when they added it but I know Mavericks and Yosemite supports it) – FDinoff Feb 19 '15 at 20:43
  • 4
    FWIW, I'm running OS X (10.10.5) and setting `set mouse=a` in my `.vimrc` file allows me to scroll using the scroll wheel on my mouse, but doesn't allow me to move the cursor with a LMB click. And I'm using the default shell provided by OS X (BASH). – ipatch Dec 17 '16 at 20:21
  • Thanks for posting this. this really worked. I was wondering if that possible and happy to see it working. – Jogendra Kumar Jul 23 '20 at 15:24
  • The problem with this is I can't do copy and paste the old fashioned way. If anyone has any suggestions let me know. In the meantime I need to read up more on visual mode. – Sridhar Sarnobat Nov 05 '20 at 20:01
0

@FDinoff already settled your first question. Let me add some comments to your other questions. I think there is something useful to say there without getting into a flame war.

If not, am I doing something wrong?

It depends. I'd say you are using the wrong tool, or expecting the wrong thing of it.

Yes, vim is open source and is highly costumizable. So much so that eventually you can use it as if it were nano or emacs or whatever. Case in point the solution provided by @FDinoff.

However, I'd suggest you either 1) learn the (admittedly hard) way vim was intended to use; you'll then see in what contexts it makes sense to be vim-esque: In one word: safety. Longer answer: safety against accidental modifications of things you don't want to modify. Or 2) change altogether to nano say, or any gui version of any other editor -including vim

How do Vim users generally handle this problem of moving to a specific word you're looking at, far from where the cursor currently is, for example when you're reading back what you typed for mistakes?

That's the thing: using vim means cli. This in turn means: use the traditional tools that have been around for de facto half a century and thus have abundantly proven their usefulness. In this case, you can use aspell. It's a direct descendant from ispell which was originally written in 1971.

In summary: use aspell mydoc.txt and you'll get to a text-based interface allowing you to quickly and easily correct any misspelling -or add words to you own dictionary.

PS:
I always look for vim and hate when some distro sets its defaults to things like mouse=a say. But if I were to learn from scratch one of these now, I'd go for emacs: for me it has the added bonus that you can practice lisp with it. If you are into programming languages, that's a fun thing to have around.

So, coming back to that first sentence of mine, I'd say it depends what do you want to learn vim for.

As the learning curve of any of these editors is steep and long, for anybody landing anew here you may want to see questions like this.

MASL
  • 929
  • 1
  • 11
  • 25