Live data from Hacker News

To Master Vim, Use It Like Language

danielmiessler.com

91–100 of 124 posts

Re: To Master Vim, Use It Like Language

#91

My issue with getting better at vim is that I've gotten to the point where I'm comfortable moving around text, copying/pasting, and everything I would normally do with a mouse. I know vim is so much more than that, but it's one of those things where "you don't know what you don't know" and because of that, I don't have the incentive to continue learning. Hopefully this post will inspire me to incrementally advance my…

"My issue with getting better at vim is that I've gotten to the point where I'm comfortable moving around text, copying/pasting, and everything I would normally do with a mouse."

exactly why I use Vim this way. On DEC VT-100 terminals this was the only way you could work and I must say I sometimes cheat and add the necessary bash commands to make it work on my console.

Re: To Master Vim, Use It Like Language

#92

I consider myself at least an intermediate user of Vim, and I'm glad that you mentioned the "f" motion (along with its cousins "t" and ";"). I don't think these keys get enough exposure among beginner Vim users (they aren't mentioned in vimtutor), but they allow you to quickly and efficiently move across files and do things like "ct(" (change text up to first left parentheses), which is super useful for changing func…

By the way, in your specific example, "ct(" is not necessarily the most efficient, because most of the time a function name will be a nice alphanumeric string; hence you can use "ciw" which will work anywhere in the string, not only at the beginning.

Re: To Master Vim, Use It Like Language

#93
post #43

Earlier quoted context omitted.

Aiming to combat "you don't know what you don't know", here's a list of things to consider. How comfortable are you with: * find/replace/regexes * registers and macros * vim settings (spell, list, highlight, number, wrap) * the plugin ecosystem * editing multiple files simultaneously (splits, buffers, moving between them) * folds Anyone else want to chime in with stuff I've either forgotten or don't know I don't know…

I asked on /r/vim about "Who uses folds?" Didn't get any takers. I always forget they exist and haven't used them in my workflow yet. Tag files would be another good one.

I use them all the time (I've switched them on by default in .vimrc) while editing C++ code. Extremely, extremely helpful to get the structure of a file at a glance. For example, if a 400-line file has about 10 functions in it, you can fold all "zM" and instantly you see only the function signatures, while the bodies are folded.

How to enable it: use "set foldmethod=syntax" (with C++) or "set foldmethod=indent" (with JS, where "syntax" doesn't work for me). Also, I use "set foldminlines=0" so that 1-line paragraphs get closed as well (it looks more consistent).

How to use it: close all folds "zM" (I remember it because the M is shaped like it's all folded on itself). Open all folds "zR". Open one fold "zo", close one fold "zc". Open one fold recursively "zO", close one fold recursively "zC".

By the way, I almost never use manual folds, so "zf" is almost useless to me.

Re: To Master Vim, Use It Like Language

#94

Thanks for this tutorial. I'm at Level 1 having switched from an IDE (PyCharm) and I find this helpful. Any reason why you use Pathogen vs Vundle for managing plugins? Does it even matter?

You're doing yourself a disservice. Intellij (PyCharm) has a vi plugin. Whatever extra stuff you give up from regular Vim, you gain an order of magnitude of productivity using a development environment that is "smart". Think about what PyCharm does for you and what Vim doesn't. Vi(m) is a model, not an implementation. I wish people would stop handicapping themselves with very bad implementations. Intellij, Visual Stu…

I think PyCharm is awesome, but the reason I switched to vim is because I have to code on a remote machine especially when I don't have a Vagrant synced folder setup. I'd love to try vi key bindings on PyCharm, though!

Re: To Master Vim, Use It Like Language

#96
post #43

Earlier quoted context omitted.

Aiming to combat "you don't know what you don't know", here's a list of things to consider. How comfortable are you with: * find/replace/regexes * registers and macros * vim settings (spell, list, highlight, number, wrap) * the plugin ecosystem * editing multiple files simultaneously (splits, buffers, moving between them) * folds Anyone else want to chime in with stuff I've either forgotten or don't know I don't know…

I asked on /r/vim about "Who uses folds?" Didn't get any takers. I always forget they exist and haven't used them in my workflow yet. Tag files would be another good one.

I still don't fully understand how folds work (e.g., how can I get them in my JavaScript files by default?), and thus I find them difficult to work with, but when I can get them to work, I'm very glad of them. They make navigating round a large file much easier.

Re: To Master Vim, Use It Like Language

#97

Learning vim is easy, I've done it a thousand times! (As Mark Twain might say) This time around I've been keeping a list of the stuff I miss from my usual workflow. Here's two of the most maddening: 1. Searching for literal text. Is there a way to avoid having to manually escape special characters? 2. Maintaining cursor position when scrolling. Maybe I want to go look at another part of the file and come back. How ca…

1. /\Vliteral search 2. C-e and C-y as long as the cursor position doesn't move out of the visible area

1. For the mnemonic, "\v" turns on "very magic" where all possibly special characters will have their special meaning without prefixing them with "\". Now, "\V" is just the opposite of "very magic", which is "very not magic", i.e. disable all special characters.

Re: To Master Vim, Use It Like Language

#98
post #88

Learning vim is easy, I've done it a thousand times! (As Mark Twain might say) This time around I've been keeping a list of the stuff I miss from my usual workflow. Here's two of the most maddening: 1. Searching for literal text. Is there a way to avoid having to manually escape special characters? 2. Maintaining cursor position when scrolling. Maybe I want to go look at another part of the file and come back. How ca…

2) is generally accomplished with marks. Press m followed by a letter to set a mark where you are, go down to wherever you want, and then you can pop back by pressing ` (backtick) followed by the letter you set for the first mark. If you want to go back and forth, you can set two marks.

Pressing `` (backtick twice) will jump you back to the place of your last edit -- unless you've explicitly set another mark in the meantime, in which case it'll send you there instead.

Re: To Master Vim, Use It Like Language

#99

The thing that always frustrated me about Vim (and command-line apps in general) is that it punishes you for being a GUI power user. The more mastery you have of conventional GUI keyboard shortcuts to highlight, jump words, copy/paste, etc., the more often you will reflexively hit them and do the wrong thing while trying to use Vim. You have to unlearn a lot of perfectly good skills before you can really master Vim,…

I have the opposite problem. When I'm writing stuff in MS Word at work, I'll often see a ":w" appear in the text when I automatically try to save the file Vim-style.

Cream[0] is a configuration for Vim that makes it work in a way more familiar to people used to Word and other traditional Windows GUI programs.

[0] http://cream.sourceforge.net/

Re: To Master Vim, Use It Like Language

#100

Learning vim is easy, I've done it a thousand times! (As Mark Twain might say) This time around I've been keeping a list of the stuff I miss from my usual workflow. Here's two of the most maddening: 1. Searching for literal text. Is there a way to avoid having to manually escape special characters? 2. Maintaining cursor position when scrolling. Maybe I want to go look at another part of the file and come back. How ca…

> 1. Searching for literal text. Is there a way to avoid having to manually escape special characters?

Put "set nomagic" in your .vimrc. This makes e.g. "." match a literal period/full-stop rather than any character. To get the special behaviour, escape the character: e.g., in nomagic mode, "\." matches any single character.

If you only want this behaviour occasionally, putting "\M" at the start of your search will invoke it for that search only: e.g. "/\Mfull.stops.only" will match "full.stops.only" but not "full-stops:only".

Even in nomagic mode, a few characters are treated specially, e.g. "$" for end of line. To suppress even these, start your search "\V": e.g., "/\V$1000". N.B., you can't make this behaviour permanent in your .vimrc: you can only invoke it search by search.

If you want the full gory details for all of the above, try ":help pattern" in Vim.

Post reply on HN