5

I freshly installed Ubuntu 16.04 and then I installed vim. Soon I realized that Ctrl + O which I regularly use in vim to jump to the last place, does not work! After some search, I got the following commands:

:nnoremap <M-Left> <C-O>

and

:nnoremap <X1Mouse> <C-O>

I tried putting both these in my .vimrc but they don't give me the desired effect. I am really annoyed by this since this is one of the most used things that I use. What am I missing?

Edit: I reinstalled vim from scratch, also deleted the ~/.vimrc file. After deleting the file, I checked for /usr/share/vim/vimrc; it was there. Then I installed vim and tested for Ctrl+o; it works till I close the file. However, after I open it back, it forgets all the history.

Peaceful
  • 4,920
  • 15
  • 54
  • 79

1 Answers1

3

Well, the actual answer as mentioned in the comments is your vim config files didn't have proper permissions on them. In addition to that, the key mappings you used in your question are invalid according to the docs:

:help X1Mouse

The X1 and X2 buttons refer to the extra buttons found on mice.
The 'Microsoft Explorer' mouse has these buttons available to the right thumb.
Currently X1 and X2 only work on Win32 environments.

And

:h M-Left
Alt-Left        Move cursor to the beginning of the previous word

M = alt.

Put this in your vimrc. Enable the mouse first:

set mouse=a
map <LeftMouse> <c-o>

Although Vim uses inefficient gluing of movements together if you want to get to a far away arbitrary place on the screen, which the mouse solves well and much faster than Vim :)

Andy Ray
  • 30,372
  • 14
  • 101
  • 138
  • I put the last command you told in `~\.vimrc`. Sill doesn't work. – Peaceful Sep 29 '17 at 07:46
  • Yes; without the colon. – Peaceful Sep 29 '17 at 17:13
  • Ubuntu terminal mouse integration, and vim mouse integration, are generally poor out of the box, you may need a terminal plugin to expose mouse actions to vim (this is why gui versions of vim are generally nicer to use). you could try mapping a non-mouse action first, like a key, as a sanity check. My mapping in my answer works correctly in Vim and does what you're asking. – Andy Ray Sep 29 '17 at 17:39
  • The main point here is why doesn't it work? It works on my desktop with the same version of OS and used to work on my laptop with Ubuntu 14. – Peaceful Sep 29 '17 at 18:29
  • Updated the answer. another reason why the gui version is so much nicer! – Andy Ray Oct 05 '17 at 00:54
  • I tried setting the mouse. I think the problem is more fundamental because even the marks don't work in vim. Interestingly, all these things work on my desktop where I have same OS, etc. – Peaceful Oct 05 '17 at 02:52
  • This works fine in Ubuntu, there's nothing else we can help with without more information – Andy Ray Oct 05 '17 at 03:06
  • I think the problem is that the viminfo is not getting updated properly. I don't know why. – Peaceful Oct 05 '17 at 03:07
  • I seem to have solved the problem. My `~/.viminfo` didn't have read and write permissions (and vim didn't complain!). Comments below [this](https://stackoverflow.com/questions/10752863/vim-record-history) helped me. – Peaceful Oct 05 '17 at 03:18