set scrolloff=999
That will keep the cursor in the middle of the window always, except at the start and end of the file. Before discovering that I used to `zz` after nearly every movement; that's all gone now, saving a ton of time and frustration.While scanning a buffer for some pattern I'll quite often make a one-off keyboard macro that searches for a pattern and then invokes `C-l C-l`, it's very nice to then bounce on the "repeat keyboard macro" key and leave my eyes in the same place while the screen contents change under them.
Quite some years later, I don't think I could ever do without vim. Not saying that emacs wouldn't probably fill the same role, editor wars considered and all. I just had somebody tell me to pick an editor and get good with it, some blog or forum posting made me go with vim and it's been one of my favorite pieces of software since.
To contribute a little bit, what I've really come to learn recently is the 'hybrid line numbering mode' that was added with 7.4 iirc. When you add both. set relativenumber
set number
to your .vimrc, you get relative numbers for all lines except the current, which is displayed as absolute. Helped my navigation game a huge deal. Just in the unlikely case anyone here hadn't heard of it.
Then I realized I could do y6k to pull the next six lines, rather than "told on, let me count/do the math on the line numbers". Took me another moment to realize "4j" is the way to move.
I think I'm going to like this.
" for scrolling up and down quickly
nnoremap J 7j
nnoremap K 7k
vnoremap J 7j
vnoremap K 7k
and the second (which requires a third party plugin): " easymotion allows us to jump to all places that could have been reached by
" (w in this case), and the bd- indicates we want to search backwards too.
nmap f <Plug>(easymotion-bd-w)
vmap f <Plug>(easymotion-bd-w)
The first one originates from recognizing the problem from the antipatterns article: that spamming j j j j to get down to the line you want is dumb. But I choose not to follow the advice of most vim articles I read which is to learn built-in tricks such as typing 10j or :<line number>. The milliseconds it takes for me to count the number of lines I want to go down or assess the line number of the line I'm interested in aren't worth it, I'll just tap j if the line is close enough or J if it is five or more lines down. I think it is a good solution.The even better solution (and I use them both in tandem) is to install easymotion [1] and use it like I show in the second example.
I also use gg and G to get to leap to the top and bottom of the file quite a lot.
---
As to your question about using O to insert above the current line, that should not work that way. Your specific issue sounds very much like a binding has been defined for O<other character>. Type :nmap in vim to display a list of bindings and check for lines starting with O. It might be in your .vimrc or some plugin defined something. I would definitely say remove the binding or the plugin rather than put up with that, O is very useful.
nmap <C-j> 3j3<C-e>
nmap <C-k> 3k3<C-y>
(replace "3" with whatever number you like best).
These shortcuts will enable you to scroll the text, while keeping the cursor fixed. It's similar to web page scrolling. It helpls you type in code while maintaining an overview on what's going on below and above it.
Add these to your .vimrc and use them for some time. You'll thank me later. map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>lI use easymotion because it's the fastest way to go from my eye spotting something on the screen to my cursor being there. It's two button presses consistently, you can't really beat that with some combination like 5j$2b, especially since that combo is different every damn time.
The advantage of using J and K is that they're very vim movements, but if can't because of :join, another workaround would be to use <PageUp> and <PageDown> since they're redundantly bounded to <Ctrl-B> and <Ctrl-F>:
nnoremap <PageDown> 7j
nnoremap <PageUp> 7k
vnoremap <PageDown> 7j
vnoremap <PageUp> 7kAbout the 'O' problem, try ':set noesckeys' and see [1] for more.
[1] http://stackoverflow.com/questions/2158516/delay-before-o-op...
I'll also note that although I do also frequently use () and {}, I very much like the plugin sneak, which adds an f-type motion. Usually f{char} goes to the first following instance of {char} on the line. Sneak adds in s{char}{char}, which goes to the first instance of {char}{char} (not restricted to the line), and is ;-repeatable just like f-type motions. What this means is that my default navigation is often, look where I want to go, find two letters, sneak to that combination, and then ;;; until I get to the right one.
On your also: My O doesn't stall at all. Have you tried performing the same action on an empty vimrc? You might start vim with `vim -u NONE`, enter some text, and try out O. Or maybe `:map O` or `:nmap O` will inform you that you have some operator-pending map beginning with O.
Also, with relativenumber set, it's easy to move to the exact line without counting, or to see how many lines you need to yank, etc.
But sometimes I'm just idly moving through a file with j and k, and it feels perfectly natural to do so, the same way I unconsciously move the mouse cursor over text as I read it (outside of vim).
I have to mention that for navigation purposes, f/F is only useful with ;, otherwise you could find yourself looking through the line for a suitable character which slows you down. With ; it's enough to pick a "rare" character on the line which is near to/in the desired object.
Next to c2f, ci" (and ci) etc) could be really useful when you end up being in the middle of a string literal and just want to change the whole thing. Or in the middle of an expression in parens - http://fuckyeahvim.tumblr.com/image/122373002741
set relativenumber nonumber
autocmd InsertEnter * :set norelativenumber number
autocmd InsertLeave * :set relativenumber nonumber
IIRC this tip was from the Practical Vim bookYou can look through :map and try and find it -- not sure if there's an easier way.
http://stackoverflow.com/questions/2158516/delay-before-o-op...
set number + set relativenumber is pretty awesome for line counting. This marks all lines with relative numbers, except the current one.
Oh also: he mentions O to insert above the current line. I use that a lot, but on my systems (going back 15 years or so I think) it has always required a pause, like vim is waiting to see if I'm typing O or some longer command. If I type O and immediately start entering text, strange things happen. This doesn't happen with o. Does anyone else experience this? Maybe it's just something weird in my own setup.
EDIT: Some more "moving fast sloppily": 1G goes to the top of the file. G goes to the bottom. Also you can not-move, but scroll the visible area so that your cursor is on the top line (zENTER), middle line (z.), or bottom line (z-). I use that a lot when I am Ctrl-Fing through a file, so I can see more context.