News for hackers. Stuff that matters.
Re:Vim anti-patterns by babarock on Tuesday February 07, 2012 @03:28PM (#3563513)
Of all the "Vim tricks" article I came across, this one is my favorite so far.

I have been a vim power user for a little over 2 years now. I never bothered installing plugins and spent all my time instead learning ... the exact same commands described in the article. Now I type fast, I mean real fast.

A couple more tips I find useful:

- 'gg' and 'G' in command mode will send you to the beginning and the ending of the file.

- 'Ctrl-N' and 'Ctrl-P' in insert mode will auto-complete (suggestions only come from existing words in opened buffers, for more you'd probably need plugins).

All the other tips are _spot on_! I especially like the first one about moving vertically one line at a time. It takes some time getting used to, but the fact that you can repeat the 'jump' or jump back to your previous position. Believe me, you'll fly :)

My new set of advice for blazing fast typing:

1. Learn to touch type. The rest is meaningless without this.

2. Repeat 'vimtutor' religiously for 10-15 days.

3. Read this post and apply every tip until it's hard-written in your fingers' muscle memory.

4. ... voila!

Re:Vim anti-patterns by scott_s on Tuesday February 07, 2012 @05:48PM (#3564021)
'gg' and 'G' in command mode will send you to the beginning and the ending of the file.

I've always used ':1' for the beginning and ':$' for the end. To me, the benefit of this is that I always use the same mechanism to go to a particular line of a file. (I often do, say, ':45' if an error is reported at line 45.)

For moving up and down large distances, I also prefer ctrl+u for up and ctrl+d for down. There is a minor difference: ctrl+f will put the last line at the top of the screen, filling the rest with the tilde-abyss. That always bothers me.

Re:Vim anti-patterns by jdludlow on Tuesday February 07, 2012 @05:59PM (#3564076)
45G does the same thing as :45, so the people using gg and G can also remain consistent with their muscle memory.
Re:Vim anti-patterns by dasil003 on Wednesday February 08, 2012 @04:44AM (#3565912)
The beautiful thing about muscle memory is you can have two similar concepts map to completely different keys and your muscles will handle it just fine. I happily use gg/G/:# without mental overhead.
Re:Vim anti-patterns by emillon on Wednesday February 08, 2012 @02:19AM (#3565578)
And for completeness, so does 45gg.
Re:Vim anti-patterns by edanm on Wednesday February 08, 2012 @04:47AM (#3565921)
I like the idea of :1 and :$, but how do you get it to work in conjuction with selections (visual mode)?

If I want to select the entire contents of the file, hitting "v" then ":1" seems not to work.

Re:Vim anti-patterns by graywh on Tuesday February 07, 2012 @09:32PM (#3564765)
The reason for that difference between ctrl-d and ctrl-f is that one moves the cursor half a page (or 'scroll') and the other scrolls the screen one page.
Re:Vim anti-patterns by dwc on Tuesday February 07, 2012 @04:09PM (#3563638)
> I never bothered installing plugins and spent all my time instead learning

This wisdom should be shared with everyone learning vi/vim, since this leads directly to the largest payoff.

Re:Vim anti-patterns by gnosis on Wednesday February 08, 2012 @01:54AM (#3565506)
If you don't use plugins, you are really missing out.

Check out PreciseJump and EasyMotion:

http://www.vim.org/scripts/script.php?script_id=3437

http://www.vim.org/scripts/script.php?script_id=3526

(watch the animated gif demos on those pages and be amazed!)

MRU is really useful for navigating the most recently opened files:

http://www.vim.org/scripts/script.php?script_id=521

xptemplate is an awesome, very advanced snippet plugin:

http://www.vim.org/scripts/script.php?script_id=2611

NerdCommenter, for easy commenting/uncommenting blocks of code:

http://www.vim.org/scripts/script.php?script_id=1218

And, of course, before you install any plugin, you should do yourself a favor and install and use Pathogen, or something like it:

http://www.vim.org/scripts/script.php?script_id=2332

For me, these are some of the most essential plugins that I use every day. Some other good ones are tabular, renumber, stripansi, matchit, and surround.

Re:Vim anti-patterns by sohooo on Thursday February 09, 2012 @03:00AM (#3570216)
I'm also a fan of Pathogen (and tpope's stuff in general), but now I would recommend Vundle. It's like Ruby's Bundler for Vim. The difference is that you define the bundles (plugins) you want to use right in your .vimrc. With :BundleInstall/:BundleUpdate clones/updates these plugins.

https://github.com/gmarik/vundle

Re:Vim anti-patterns by gnosis on Thursday February 09, 2012 @02:51PM (#3572717)
I'm not really sold on vundle (or other plugins like it). I don't really like the automation it provides. I'd much rather just install stuff by hand in to ~/.vim/bundle and do my own updates. That way I have maximum control and full knowledge of what's going on in the install process.
Re:Vim anti-patterns by roel_v on Wednesday February 08, 2012 @06:01AM (#3566066)
How long have you been using vim?
Re:Vim anti-patterns by gnosis on Wednesday February 08, 2012 @09:46AM (#3566700)
Decades.
Re:Vim anti-patterns by derwiki on Tuesday February 07, 2012 @05:19PM (#3563902)
I dunno, Command-T was a pretty big boon to my productivity (https://github.com/wincent/Command-T).
Re:Vim anti-patterns by dwc on Tuesday February 07, 2012 @07:05PM (#3564316)
I don't mean to say that you shouldn't find and use plugins, because there are some really great ones that answer real needs.

But it seems that a lot of people new to vim get distracted by plugins, tweaking their config, et al, when they could be learning the "vi way" to get their actual code editing productivity.

Re:Vim anti-patterns by wahnfrieden on Tuesday February 07, 2012 @08:39PM (#3564589)
I disagree to some extant. I've been a power use for more than a decade and some of the default ways of doing things are just wrong. It is true though that people are reluctant to learn about what vim itself already provides - more people should use the fantastic help system (once you know the basics) rather than rely on blog posts for everything, too.
Re:Vim anti-patterns by leviathan on Tuesday February 07, 2012 @06:51PM (#3564264)
The general idea is that if your productivity relies on external plugins, it will drop very low as soon as you have to use someone else's machine, or when you have to work with lots of various systems where setting up your environment isn't an option.
Re:Vim anti-patterns by ulisesrmzroche on Tuesday February 07, 2012 @07:11PM (#3564335)
I think it's more that everyone is taking the bus to Abilene. Can you explain the first point a bit more? On the second point, you can always :e scp if you need to.

I've never maintained my own .vimrc, or know what plugins I have installed or not, btw.

Re:Vim anti-patterns by AlexCP on Tuesday February 07, 2012 @05:19PM (#3563903)
There are some extremely powerful and useful plugins, CommandT for example, that shouldn't be miss.
Re:Vim anti-patterns by nimrody on Tuesday February 07, 2012 @03:54PM (#3563591)
In case you missed it, this one will teach you much more than just a few commands... It's all about combining commands or producing 'sentences' as the author calls it:

http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-n...

Re:Vim anti-patterns by graywh on Tuesday February 07, 2012 @03:55PM (#3563597)
Re:Vim anti-patterns by graywh on Tuesday February 07, 2012 @03:54PM (#3563592)
There's an option to configure how keyword completion works when ctrl-p or ctrl-n is used: 'complete'. Vim can scan the current buffer, other windows, other buffers, dictionaries, spell checking, thesaurus, included files, tags.
Re:Vim anti-patterns by c4n4rd on Wednesday February 08, 2012 @10:47AM (#3566940)
a useful one is 'markers'. I use it a lot when jumping from place to place.

Example: :ma <-- sets a marker at the current cursor location named 'a'

later on, you can go back to this exact place by typing "a (that is quote followed by letter 'a' - the marker you named.

Note that you can have as many markers as you want.

Re:Vim anti-patterns by Nick_C on Wednesday February 08, 2012 @11:26PM (#3569813)
> Example: :ma <-- sets a marker at the current cursor location named 'a'

You don't even need the leading colon, just ma while in normal-mode.