News for hackers. Stuff that matters.
Re:Vim Anti-Patterns by savanaly on Wednesday October 05, 2016 @01:38PM (#12645960)
I have two tricks for better movement, add the following to your .vimrc:

    " 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.

[1] https://github.com/easymotion/vim-easymotion

Re:Vim Anti-Patterns by mihaifm on Wednesday October 05, 2016 @02:44PM (#12646595)
For better scrolling:

    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.
Re:Vim Anti-Patterns by weaksauce on Wednesday October 05, 2016 @04:36PM (#12647608)
I could see using that with J and K because I use c-(hjkl) for moving between open buffers in a tab. Nice tip though.

   map <C-h> <C-w>h
   map <C-j> <C-w>j
   map <C-k> <C-w>k
   map <C-l> <C-w>l
Re:Vim Anti-Patterns by stephenboyd on Wednesday October 05, 2016 @05:56PM (#12648284)
I have some similar mappings in mine. Capital J and K go up or down 4 lines, capital H and L move by words instead of characters. It feels like holding down the button to run instead of walk in Super Mario Bros.
Re:Vim Anti-Patterns by x0x0 on Wednesday October 05, 2016 @02:42PM (#12646573)
Have you tried using :relativenumber? You still have to type eg 12j or whatever but at least vim does the counting for you. If so, can you share why you like easymotion more? Thanks!
Re:Vim Anti-Patterns by savanaly on Wednesday October 05, 2016 @05:29PM (#12648078)
Yes, I use :<line number> very occasionally, mainly if I know I need to edit a certain line number in a file and just opened that file. But for regular use the time to type in a line number is just too long since I can't touch type numbers very quickly (when do we ever get practice typing in long numbers after all?).

I 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.

Re:Vim Anti-Patterns by Tyr42 on Wednesday October 05, 2016 @06:20PM (#12648464)
Ahg, no I couldn't do that, I need to keep J as Join lines. That's pretty useful to me. Kinda the inverse of gq.
Re:Vim Anti-Patterns by savanaly on Wednesday October 05, 2016 @06:37PM (#12648567)
Ah, I bound join lines to :join since I don't use it that often. I still encourage you to try binding something to 7j (or whatever number of j's feels right). One of the best shortcuts of my life.
Re:Vim Anti-Patterns by yamaneko on Saturday October 08, 2016 @02:18PM (#12667956)
I tried to use J, but it's somewhat tied to my muscle memory already (and I'm surprised I use it quite often joining comments and stuff). If you're like me, remember that you can abbreviate :join to just :j.

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> 7k
Re:Vim Anti-Patterns by christianmann on Wednesday October 05, 2016 @11:49PM (#12650114)
I use that a lot as well, along with K to look up the current word in the man page.