I've read that H should make the cursor go to the top of the current screen. Also L doesn't goto bottom of current screen. However, M does goto middle of current screen. How can I fix this? Or find out hat the actual mapping is.
HML are not mappings; they are hardcoded commands. But some plugins or your own configuration can create mappings that override those default commands.
This command tells you where a mapping was last set and what it does:
:verbose map H
It sounds that there is mapping that overwritten the default H, L function.
you can use :verbose map H to find out the current key mapping on H and where it was done.
It's likely that a plugin has remapped those two keys. You can find out with
:verbose map H
:verbose map L
In addition to the normal suspicions about an interfering mapping given in other answers, you may have your 'scrolloff' option set to some non-zero value. When this option is set to N, Vim always keeps N lines of text between the cursor and the top/bottom of the window. As you scroll, this means that the text scrolls when the cursor reaches a line within N lines of the top/bottom, but when using H or L, it means the cursor will only move to within N lines of the top/bottom of the window.
In particular, if 'scrolloff' is set higher than the window height, then your cursor always stays in the middle of the screen as you scroll, and H/L do nothing at all.
Related
I use vim in xterms on Arch linux. Wanting to automatically set marks for subsequent command ranges I wrote this mapping
map <LeftMouse> mp:let g:oc=g:nc<cr>:let g:nc=getpos('.')<cr>:call setpos("'o", g:oc)<cr>:call cursor(g:nc[1], g:nc[2])<cr>
but now the mouse no longer places the cursor at the clicked location. How can I keep standard mouse function, and add to it rather than replacing it?
It seems its not possible to modify LeftMouse, but you can achieve the effect of it using LeftRelease. So my mapping does what I want as
nmap <LeftRelease> mp:let g:oc=g:nc<cr>:let g:nc=getpos('.')<cr>:call setpos("'o", g:oc)<cr>
and the standard function of is unchanged.
You can :set mouse=a for using visual select mode. (This is not what you wanted but it is a trick).
Then, click on text, you will see that it is getting selected. Then, you can release it.
A mapping like
:map gv ma
will set the last recently selected text as mark a.
Other way:
Instead of :set mouse=a, you can press v and then select a letter or a word, depending upon your convenience and then ma for marking it as mark a.
A short mapping for it will be
:map vly ma
I am experiencing a weird problem: vim doesn't expand my foldings sometimes when I use a horizontal gesture like l. It always expands if I use zo though. I can see hor option in my foldopen settings variable. I am experiencing this when foldmethod is set either to indent or expr. What may I be missing? I don't seem to be mapping l anywhere.
Thanks
If you cursor is on an empty line inside the fold then the left move (l) will not work, thus it won't open the fold.
The same happens if your cursor is at the last column in the line. But in this case an h will make the fold open.
You can check if the a movement command fails by paying attention to the error beep, the same it issues when you hit Esc when you are in normal mode. If you are unable to hear it, you could try using the 'visualbell' option.
I sometimes find document traversal to be too slow in Vim when using h, j, k, l.
Is there a way to temporally increase the number of lines / characters that these keys move the cursor? (I.e. instead of moving 1j, pressing j will move 3j)
Edit:
Solution:
:map <F8> :noremap j 3j <CR>
:map <S-F8> :noremap j j <CR>
I wanted something like this so that I can easily browse longer bodies of code that am not necessarily familiar it. This approach allows me to easily toggle between "browsing" mode and "coding" mode.
While possible (use :noremap j 3j Enter and :noremap j j Enter to restore), it may not be useful for very long to change the behaviour of these keys.
There are many ways to navigate in Vim. Of course you can advance by full screens using CtrlF and CtrlB.
You can, as you alluded to, enter a number of moves before executing the navigation.
You can also go directly to a specific line using :9Enter, for example.
If you see the text to which you want to navigate, use / or ? followed by the text.
For h and l, you can navigate word boundaries more quickly with b, w, and e, and contiguous non-whitespace with B, W, and E.
Try Ctrl+D/Ctrl+U and Ctrl+F/B (Up/Down, Forward/Back respectively).
These will traverse the document much faster than h,j,k,l.
What #Bryan Ross have suggested is absolutely right. I want to add just a thing. Use relativenumber, it will help you to use j and k more efficiently.
Answered by Jay is sufficient, I would like to add the following !
There are many different kinds of navigation possible in vim, ( where as the h, j, k, l are just line navigation ). Some more are:
screen navigation
spl navigation
search navigation
word navigation
Refer this write up to find out the short cut keys to do it: Essential Vim editor navigation
Another thing that helps is to have line numbers turned on (:set number). If you see on the screen where you need to go and see the line number, it's just G.
If you deal with code in blocks, % will move you to a matching brace, parenthesis, etc.
If you deal with files with lots of wacky characters, t, T, f, and F are very helpful.
try CTRL + Y & CTRL + E to scroll instead of moving the line
use the CTRL + B to scroll to bottom of page and CTRL + F to scroll to top of page
use the H (Height), M (middle), L (low) to move the cursor to top, middle and bottom of screen
you can also increase the speed of CTRL + Y and other keys as of this answer explained https://stackoverflow.com/a/7990810/10539792
I know there's so many vim tricks to traversal quickly, but for me is the most comfortable is a mechanical keyboard, with built in repeat rate increase when u hold a button it increase the repeat reat etc for the j or k so the traversal will be quick and smooth too. (So nice!)
But its annoying when u have your vimrc but didnt have your keyboard so not a universal solution.
I have been currently tweaking my Vim _gvimrc file to add a few features etc. and I've recently noticed, that when I use the cursor key to move left while at the beginning of a line, it no longer moves to the end of the previous one, it just stays put.
I used to be able to move from line to line just by holding the left or right cursor keys but for some reason that functionality has been lost. This is also true for the standard Vim h j k l keys.
:set whichwrap=b,s,h,l
whichwrap can be abbreviated to ww.
One frustrating behavior in vim is that when i move my cursor right or left (respectively "l" or "h)" and i am at the end or the beginning of the line, my cursor doesn't move to first column of next line or last column of previous line.
Is there a way to change this behavior ?
You can use the whichwrap setting to make h and l wrap around the start and end of individual lines:
set whichwrap+=h,l
However, Vim's documentation recommends against this, probably because it could have unexpected side effects (like breaking plugins, or changing how common key mappings work).
As an alternative, you can do what what Matti Virkkunen recommended:
set whichwrap+=<,>,[,]
This leaves h and l with their default behavior, but allows the left and right arrow keys to wrap around lines. (This is what I do, and it works well.)
You might also want to take a look at the backspace setting, to control how Backspace, Delete, Control+W, and Control+U work in Insert mode. I set mine like this:
set backspace=indent,eol,start
That allows me to backspace over pretty much everything.
For more info, see these topics in the Vim help:
:help 'whichwrap
:help 'backspace
Put the following into your .vimrc:
set whichwrap+=<,>,[,]