5 ms·
I never got into the habit of using { and }. I just use H M L (high/medium/low) to get approximately in the right part of the screen, then go line-by-line. You
by pjungwir 10y ago
I never got into the habit of using { and }. I just use H M L (high/medium/low) to get approximately in the right part of the screen, then go line-by-line. You can also do 5H or 10L to get "5 lines from the top" or "10 lines from the bottom". I make pretty good use of vim features, but I like to mix some sloppiness with the precision. I don't often count things before typing commands, because that breaks the second-nature quality of navigation. If something is more than 2 or 3 objects away, I approximate. I do use counting with t, T, f, and F a lot to hop around, including things like c2f). Very frequently that combines well with spamming j.j.j.j.j. I use . with trivial movement (like j or n) at least 10x more than @a. Another way to move fast sloppily is W and B. I guess I'm saying: learn all the cool stuff you can do, but don't feel like you have to find the most precise way to do every little thing. If you're just starting out, relax and don't try too hard. You can always just pick one new thing every couple weeks and try to add it to your habits.
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.
- rogual 10y agoSounds like you've got something mapped to a key sequence that starts with O. You can look through :map and try and find it -- not sure if there's an easier way.
- pjungwir 10y agoSo this prompted me to Google for it (Googling for one-letter vim commands works better than I thought!), and this looks like the issue: http://stackoverflow.com/questions/2158516/delay-before-o-opens-a-new-line http://stackoverflow.com/questions/2158516/delay-before-o-op...
- mixedmath 10y agoI share some of your sentiments. I find that I so frequently want to go the first and last non-whitespace characters in a line that I remapped H to go to first non-whitespace character and L to go to the last. I think of these as "linewise-h" and "linewise-l", which almost fits with vim's other conventions. Then I substitute ctrl-d and ctrl-u to go up or down by half-screens. 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.
- Tyr42 10y agoI think ^ goes the the first non-empty character on the line already. Think of it like the regex. Then 0 (zero) goes to column 0.
- savanaly 10y agoI 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 https://github.com/easymotion/vim-easymotion
- x0x0 10y agoHave 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!
- savanaly 10y agoYes, 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.
- grault 10y agoI started combining {} with zt zz zb. I feel like it mimics physical handling of a scroll. This requires some empty lines though. In case I work with dense text, I usually switch to H/M/L also (combined with zt zz zb). 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 http://fuckyeahvim.tumblr.com/image/122373002741
- raygull 10y agoI have similar habits, but use zz to recenter the cursor (instead of z.), and gg (instead of 1G) to move to the top. Very quick. 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).
- gbrown_ 10y agoI remap { and } so I they land on the first and last lines of a block of text between blank lines, rather than the blank lines themselves. I find this is usually what I want then I just move/ take action in a more targeted fashion with f, t, w or the vim-sneak plugin.
- guygurari 10y agoI use the same sloppy methods. What matters to me is speed and staying in the zone while editing. Trying to get the positions precisely right forces me to think consciously and takes me out of the zone. About the 'O' problem, try ':set noesckeys' and see [1] for more. [1] http://stackoverflow.com/questions/2158516/delay-before-o-opens-a-new-line http://stackoverflow.com/questions/2158516/delay-before-o-op...
- apazzolini 10y agoI find normal mode much more pleasant with space mapped to 10j and backspace mapped to 10k. This combined with / and ? make navigation pretty quick without having to mentally switch context to think about the vimgolf way of getting places.
- dnr 10y agoMy favorite "secret" vim feature, that no one has mentioned yet: 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.
- philsnow 10y agoI would go nuts; I prefer to use the whole screen to see what I'm looking at, and if I've just searched a buffer for a function name or whatever, there's a good chance I want to see the whole function and not the (screen height / 2) lines above it. (In emacs this is done with `C-l C-l`, in vim it's `zt`) 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.
- Gruselbauer 10y agoOh guys, thank you so much for new food for my vim-addiction. I'd hesitate to call myself anything but an interested beginner, so it's always very welcome to learn new stuff. I distinctly remember running vimtutor the first time as a teenager fresh of whatever Windows came before and thinking 'goddamn, whyyyyyy is this hot mess so popular among my mentors and idols?'... 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.
- lkbm 10y ago
- karmajunkie 10y agoon the O thing: check :nmap and friends to see if you have a 2-letter mapping set up that starts with O. This has caused issues for me in the past when I wanted to use a key that was doing double duty already—vim has to wait just a sec to see if you keep typing and it needs to act on that.
- owlish 10y agoI've found it helpful to use relative numbering in normal mode and switch to absolute numbering in insert mode: set relativenumber nonumber autocmd InsertEnter * :set norelativenumber number autocmd InsertLeave * :set relativenumber nonumber IIRC this tip was from the Practical Vim book
- OJFord 10y agoI can't remember or find what the "slow O" is about, but it's definitely real; I think I read about it in relation to it being fixed in v8.
- Manishearth 10y ago> If something is more than 2 or 3 objects away, I approximate set number + set relativenumber is pretty awesome for line counting. This marks all lines with relative numbers, except the current one.