VIM challenge

Nowadays, wind blows me in a very strange direction. Two weeks ago I felt a strong need to learn vim. Now, I can't say I'm a vim ninja, but I can feel that someday I will fully replace my eclipse setup with it. Maybe it's just sexier to program from console, but as I get more confident on a daily basis, I can see what is capable of, whereas it isn't easy to forget these good old keys: Ctrl-C, Ctrl-V and arrows.

Just to note, I'll write my learning steps here:
$ sudo yum install vim
Then I went through vimtutor. Just type it in your console. It's really useful. It will be hard. Very hard to navigate with hjkl but when you reach the motions part it'll be clear that you won't use often these just the jk.

Then for specific programmer tips, I read Why, oh WHY, do those #?@! nutheads use vi?, then Learn Vim Progressively. These two even good when you did not fully committed to learn vim and you want to just see some light.

I share some tips now which I use day-by-day.

Replace line endings

Because I often work with Kendo templates, I have to replace my line endings with a \. This sugar will solve the problem:
:%s/\n/\\\r/g

WRAP lines

If you have a bunch of lines with the same pattern, and you want to wrap every line with a specific text:
http://www.url1.com

http://www.url2.com

http://www.url3.com

http://www.url4.com

http://www.url5.com
:%s/\(.*\)\n/\<a href=\"\1\" target=\"_blank\"\>Some link!<\/a\>\r/
(Okay, here escaping is not a big help for newbies, but it's worth the result)
<a href="http://www.url1.com" target="_blank">Some link!</a>

<a href="http://www.url2.com" target="_blank">Some link!</a>

<a href="http://www.url3.com" target="_blank">Some link!</a>

<a href="http://www.url4.com" target="_blank">Some link!</a>

<a href="http://www.url5.com" target="_blank">Some link!</a>

Show line numbers / turn off

:set number / :set nonumber

Show relative line numbers / turn off

:set relativenumber / :set norelativenumber

At that point, maybe you're wondering, why on earth should one use relative line numbers?
I just tell you one (command) reason below.

Replace from this line through 5 lines

:.,+5s/foo/bar/g[c]
Yes, this is it. You'll exactly see how much lines you should replace with 'bar' when your relative numbering is on.

Open a new pane (split vertically)

:vsplit /tmp/a

Save all panes / Quit all panes

:wa / :qa

Switch between panes

ctrl+w+w
But that isn't it. What can make VIM a fully working IDE (I think) is that you can use linux commands while working with it. So if you fire up vim in the project root, you can always search for files with "foo" content with
:!grep -FR '*foo*'
I don't go into details here, I think you just want to read the Unix as IDE blog series by Tom Ryder. Wonderful tips there.

Okay, enough VIM for now, I'm out.

No comments :

Post a Comment