Live data from Hacker News

How to boost your Vim productivity

sheerun.net

21–30 of 130 posts

Re: How to boost your Vim productivity

#21

I'm all for bending your text editor to your will, but a few of these tips gloss over the core of vim: the shortcut language it offers and the composability of its parts of speech [1]. For example, remapping the paste key to paste + move to end is cool, but `ppppp` to paste 5 times circumvents vim's killer repetition. Want to paste 100 copies? (hopefully you do this rarely). Just type `100p` and you're done. I won't…

> I really do mean language, too. When I'm using vim, I feel a lot more like I'm communicating with my computer than trying to figure out how to do what I want to do.

I tell people learning Vim or Emacs that they should treat it like learning a new programming language -- a programming language for text manipulation. (In particular, don't attempt a first project in C++ while writing your first report in LaTeX, both in Vim for the first time -- it will not be a pleasant experience!)

Re: How to boost your Vim productivity

#22
post #5

Earlier quoted context omitted.

> This means using :normal and macros instead of :s for most of my search/replace actions Interesting. Can you please elaborate more on this?

Suppose a range of lines contains function calls in some programming language: i = foo(a, 42, 1) j = bar(b, c, 100, 2) # this is a comment (well, duh) bazbar(etc, 3) You want to edit the last parameter in each function call -- change it to 'hello'. I have two ways of approaching this: macros (interactive) or :norm (less interactive). 1. Put your cursor on the first byte in the first line, type qq to record a macro of…

care to suggest any resources that helped you reach wizard-like levels of usage? I very much wish to work towards that kind of ability in vi/vim.

Re: How to boost your Vim productivity

#24
post #3

In my 6 years of coding and writing LaTeX in Vim, I have found that the greatest boost to my Vim productivity is learning all about the vi and ex foundation of Vim. My Vim knowledge applies 100% to any default Vim installation on a modern distro, and my vimrc contains mostly trivial tweaks. This means using :normal and macros instead of :s for most of my search/replace actions; using H, M, L, {, } to navigate quickly…

...% to navigate quickly within a line. "%" works fine for moving around, but when I use it to edit it always surprises me, which direction it goes. I almost think vim is psychic, because "%" goes the wrong direction for me at least 80% of the time. There must be a deterministic rule governing this, but can anyone explain to me what it is?

Find first brace to the right of the cursor (be either an opening or closing brace) and jump to the matching one. If the cursor is at the beginning of a line of matched parentheses, % will go to the closing parenthesis of the first group, as in my example in a cousin comment.

Re: How to boost your Vim productivity

#25
post #21

I'm all for bending your text editor to your will, but a few of these tips gloss over the core of vim: the shortcut language it offers and the composability of its parts of speech [1]. For example, remapping the paste key to paste + move to end is cool, but `ppppp` to paste 5 times circumvents vim's killer repetition. Want to paste 100 copies? (hopefully you do this rarely). Just type `100p` and you're done. I won't…

> I really do mean language, too. When I'm using vim, I feel a lot more like I'm communicating with my computer than trying to figure out how to do what I want to do. I tell people learning Vim or Emacs that they should treat it like learning a new programming language -- a programming language for text manipulation. (In particular, don't attempt a first project in C++ while writing your first report in LaTeX, both i…

On the other hand, if you like crying yourself to sleep, then that's definitely a good idea. :-D

Re: How to boost your Vim productivity

#26
post #22
post #5

Earlier quoted context omitted.

Suppose a range of lines contains function calls in some programming language: i = foo(a, 42, 1) j = bar(b, c, 100, 2) # this is a comment (well, duh) bazbar(etc, 3) You want to edit the last parameter in each function call -- change it to 'hello'. I have two ways of approaching this: macros (interactive) or :norm (less interactive). 1. Put your cursor on the first byte in the first line, type qq to record a macro of…

care to suggest any resources that helped you reach wizard-like levels of usage? I very much wish to work towards that kind of ability in vi/vim.

I am sorry, but I don't know any resources... I have collected a few things on the following page: http://users-cs.au.dk/rav/vim/

Basically, I achieved my wizard-level C++, Vim and Git knowledge during my three years as a part-time student programmer in the basic research center MADALGO. I took the time to study the documentation (respectively the C++11 draft, :help and the git man pages) whenever I was curious. For Vim in particular, I made sure to eliminate all repeated keysmashing in my daily workflow, which "unfortunately" required me to learn about macro wizardry.

My only advice is to keep practicing, to keep trying to spot inefficiencies in your own workflows, and to actively eliminate these inefficiencies by studying the Vim help pages.

Re: How to boost your Vim productivity

#27

Why don't people seem to use the F keys? I have mappings for very frequent functions on F1-F5, and it really helps: map :w | "Fast save imap :w | "Fast save map :make | "Fast compile map :bn map :bp " Same mapping for gnome-terminal ( see http://stackoverflow.com/q/12813126/164171 ) map ^[O1;2R :bp map :bd | "Close buffer map :cnext map :cprev imap :cnext imap :cprev

The only F-key I can hit reliably without looking down is F5, which comes from years of browser use & web development, and a slight gap there on my keyboard.

Perhaps it could be learned, but I haven't learned it yet in ~20 years of typing.

Re: How to boost your Vim productivity

#28
This was great even just for the

    p "+p
mapping. I do this all the time ("+p). It's weird because I tend to go through waves of realizing "Oh! I can just remap that!" I feel like I have fairly good vim skills but somehow always forget I can keep making it more efficient than it already is.

Thanks for the reminder =].

Re: How to boost your Vim productivity

#30
post #9
post #5

Earlier quoted context omitted.

Suppose a range of lines contains function calls in some programming language: i = foo(a, 42, 1) j = bar(b, c, 100, 2) # this is a comment (well, duh) bazbar(etc, 3) You want to edit the last parameter in each function call -- change it to 'hello'. I have two ways of approaching this: macros (interactive) or :norm (less interactive). 1. Put your cursor on the first byte in the first line, type qq to record a macro of…

Lord, that's so useful. I normally include a move to next line part in my macro and then guess at how many times to run it (20@q, repeat until I get it right). It's actually the main reason I often don't bother using macros. This is such a great tip. Thanks!

You can combine regexes with macros if you only wish to run your macro on a particular set of lines:

    :'g/foobar/norm @q
will run the macro only on the subset of selected lines that match the regex "foobar". :g/.../ will match the regex against all lines in the file.
Post reply on HN