Re:A Starting Guide to VIM from Textmate
by pyre on Friday November 19, 2010 @11:08PM
(#1923817)
Colorschemes that use italics are hit-or-miss for me. Sometimes I prefer to use Terminus which doesn't have an italic typeface, but vim will try and emulate one horribly. (Or when using DejaVu Sans Mono at 9pt (?) because the lowercase 'd' has it's tall part cut off when in italics causing it to look like an 'a')
Re:A Starting Guide to VIM from Textmate
by devdas on Friday November 19, 2010 @06:39PM
(#1923278)
The snipmate plugin at http://www.vim.org/scripts/script.php?script_id=2540 may be useful for other textmate users. As a non Textmate user (I use vim), I have no idea of how well it would map to their Textmate experience.
Re:A Starting Guide to VIM from Textmate
by sudonim on Friday November 19, 2010 @06:55PM
(#1923299)
I used to get stuck in vim when logging in to linux servers. The key things to know for any newbie...
:q
i
ESC
:w
After I learned those, I've really come to love Vim. I imagine I'd need to learn about 50 more commands before I could be really well versed. What are some other important things to know?
I'd start with looking at commands that allow you to quickly move around in buffers first (/, f, t, w, e, b etc). Then start combining those with actions (ct", dw etc). Then "timesavers" such as macros and built-in conveniences (q, gqq, marks etc). The rest will come to you.
Re:A Starting Guide to VIM from Textmate
by bradleyland on Friday November 19, 2010 @07:10PM
(#1923334)
Learning to exit, insert, and save the file is about as minimal a text editor skill set I can imagine. You should definitely start out by running through vimtutor a few times. The vim help is also really good. The author also provides a good list of links at the bottom of the article.
Re:A Starting Guide to VIM from Textmate
by crazydiamond on Friday November 19, 2010 @11:17PM
(#1923835)
Are you not aware that '*' (asterisk) searches for the next occurrence of the word under the cursor. That's one key i just can't live without. '#' (hash) does the reverse.
Why not do a 'qq' to record your macro as 'q' and @q to replay it.
Re:A Starting Guide to VIM from Textmate
by 5teev on Saturday November 20, 2010 @05:18AM
(#1924248)
It was an arbitrary choice for an example. Obviously one would choose a key not being used for anything else. (This choice can also vary from session to session, depending on the task at hand.)
Re:A Starting Guide to VIM from Textmate
by Dobbs on Friday November 19, 2010 @07:13PM
(#1923343)
hjkl for moving around.
I and A insert beginning/end of line.
0 and $ go to the beginning/end of line without entering insert mode.
:%!command -- Runs the entire document through the command. If you use visual mode and then press ':!command' and it will run the selection through the command specified. Super useful for sorting a list.
Also ctrl+[ is equivalent to esc. If you rebind caps to ctrl you can easily hit escape and other commands like ^d, ^u (page down and up).
Re:A Starting Guide to VIM from Textmate
by dhimes on Saturday November 20, 2010 @07:51AM
(#1924412)
do you know how to highlight a block then double-indent? I can't make that work. With a block highlighted, I only know how to indent one ts at a time (then re-hightlight, etc.).
Re:A Starting Guide to VIM from Textmate
by pyre on Friday November 19, 2010 @10:14PM
(#1923723)
> Super useful for sorting a list.
Unless you have some special script/filter for specific sorting of lists, then why not just use ':sort' instead of ':!sort' (i.e. the Vim sort command, rather than piping it to /usr/bin/sort)?
Re:A Starting Guide to VIM from Textmate
by silentbicycle on Friday November 19, 2010 @11:27PM
(#1923849)
Why should vim have :sort built-in, when /usr/bin/sort already does it so well?
If you really want to get on a roll with vi, think of all the other cases where you wish it could do something, then make it work with :%!command_written_in_any_language_you_want .
You can also apply it to ranges. "%1,5!rev" reverses lines 1-5, etc.
Re:A Starting Guide to VIM from Textmate
by pyre on Saturday November 20, 2010 @11:38AM
(#1924741)
I never said that '%!command' was a bad thing. I was just pointing out that that particular use-case was already built into the editor. We could make pedantic arguments about Unix all day long (e.g. "Each command should do something specific and do it well, Vim doesn't need the :sort built-in" vs "Why should I incur the cost of starting up another process and having it eat up my precious memory space?") but it's relatively useless.
Being able to pipe through commands is a powerful tool, but using an example where the external command already has a built-in equivalent seems possibly confusing to the (novice Vim'er) reader (please don't rattle me off the laundry list of options that /usr/bin/sort has that :sort doesn't because you'd be missing the point).
That said... On the topic of ranges, never give :bd! a range unless you know what you're doing. I ran :bd! once while I had a number of lines selected in visual mode because I though that the selected lines wouldn't affect :bd. Bad idea. The '<,>' part of the range apparently is converted to line numbers (e.g. '3,6') and then :bd reads that range as the buffers to delete. So when you select lines 1-8 and then hit :bd! it goes something like this:
:<,>bd! -> :1,8bd! -> delete buffers 1-8 without prompting for unsaved changes
Re:A Starting Guide to VIM from Textmate
by silentbicycle on Saturday November 20, 2010 @12:37PM
(#1924854)
You're absolutely right (and sort's options are rather quirky), just trying to nudge people to thinking about piping through shell commands that way. There's a lot of power in the ex parts of vi (the : commands) that I seldom hear vi(m) users mention.
Re:A Starting Guide to VIM from Textmate
by Dobbs on Saturday November 20, 2010 @01:29AM
(#1924010)
I do a lot of bash scripting so I know `/usr/bin/sort` decently well. Using this technique I can use my bash scripting abilities to enhance my vim abilities.
Re:A Starting Guide to VIM from Textmate
by frb on Saturday November 20, 2010 @10:30AM
(#1924620)
Lately I've noticed that more and more TextMate users are switching (back) to VIM.
For years TextMate has been really popular, but now it looks as it's losing more and more users.
Would be interesting to know why. What made you switch from TextMate to VIM?
Re:A Starting Guide to VIM from Textmate
by lenni on Saturday November 20, 2010 @10:51AM
(#1924657)
I switched to Vim because to me it seems that TM2 is vapourware. I know Allan is trying to get it right with his second go but he is so coy about any sort of details that I lost interest in it.
Re:A Starting Guide to VIM from Textmate
by zenshade on Saturday November 20, 2010 @01:14PM
(#1924936)
One thing that can be a negative irritant for new users is how far the esc key is and how often they have to reach for it. Vi wasn't designed that way. It was designed for keyboards that had esc where the caps lock key is on modern keyboards. One solution is to map caps lock to the esc key. Another solution, the one I prefer, is to map ii instead. This can be done with the following in the .vimrc file:
imap <silent> ii <Esc>:let &insermode=0<CR>
This doesn't work so well if you are frequently editing files on multiple servers you can't edit the .vimrc file on. But for your local environment it'll make going in and out of insert mode a lot more efficient.
I'm dead used to using ii now so I'm probably not going to switch, but others have pointed out kk may be a better choice, due to greater distance between keystrokes/mode. Indeed, about one in ten times I hit ii when I don't need to.
Re:A Starting Guide to VIM from Textmate
by spacemanaki on Saturday November 20, 2010 @10:52AM
(#1924658)
I'm being pedantic but, isn't it "Vim" not "VIM"? I seem to remember seeing something like a usage suggestion on the site but can't find it. It just looks silly to me, like when people write "LISP."
Re:A Starting Guide to VIM from Textmate
by frb on Saturday November 20, 2010 @06:49PM
(#1925728)
Although I've seen people "Vim", "VIM" and "vim" I never really thought about what the correct spelling is. Most times I went with "VIM" since I always thought of it as acronym for "Vi IMproved".
But I think you're right with "Vim", since even on vim.org it's spelled like that.
With Monaco 13 typeface it's bliss.
One thing I'm surprised nobody ever mentions is the ! command.
If I'm working on a file and I want to, say, commit my work, I can do
I used to do this a lot when working with Oracle and Bash. It's much quicker than opening another terminal for one-off commands.http://www.vim.org/scripts/script.php?script_id=2975
drops you into a shell
Very handy.
:q
i
ESC
:w
After I learned those, I've really come to love Vim. I imagine I'd need to learn about 50 more commands before I could be really well versed. What are some other important things to know?
http://tnerual.eriogerg.free.fr/vimqrc.html http://www.pixelbeat.org/vim.tips.html http://www.rayninfo.co.uk/vimtips.html
I'd start with looking at commands that allow you to quickly move around in buffers first (/, f, t, w, e, b etc). Then start combining those with actions (ct", dw etc). Then "timesavers" such as macros and built-in conveniences (q, gqq, marks etc). The rest will come to you.
:map * ddp
Then type * in command mode to execute the steps.
And if you mangle your file beyond hope with out of control macros, there's always u to undo and :q! to quit without saving.
Why not do a 'qq' to record your macro as 'q' and @q to replay it.
I and A insert beginning/end of line.
0 and $ go to the beginning/end of line without entering insert mode.
:%!command -- Runs the entire document through the command. If you use visual mode and then press ':!command' and it will run the selection through the command specified. Super useful for sorting a list.
Also ctrl+[ is equivalent to esc. If you rebind caps to ctrl you can easily hit escape and other commands like ^d, ^u (page down and up).
You might find ^ more useful than 0 for indented code as it takes you to the beginning of the text on the line (like the regexp).
I also find that selecting large blocks of text then using the = command to autoindent everything is exceedingly useful.
If you really want to get on a roll with vi, think of all the other cases where you wish it could do something, then make it work with :%!command_written_in_any_language_you_want .
You can also apply it to ranges. "%1,5!rev" reverses lines 1-5, etc.
Being able to pipe through commands is a powerful tool, but using an example where the external command already has a built-in equivalent seems possibly confusing to the (novice Vim'er) reader (please don't rattle me off the laundry list of options that /usr/bin/sort has that :sort doesn't because you'd be missing the point).
That said... On the topic of ranges, never give :bd! a range unless you know what you're doing. I ran :bd! once while I had a number of lines selected in visual mode because I though that the selected lines wouldn't affect :bd. Bad idea. The '<,>' part of the range apparently is converted to line numbers (e.g. '3,6') and then :bd reads that range as the buffers to delete. So when you select lines 1-8 and then hit :bd! it goes something like this:
Oops!ctrl-[ can be used in place of ESC
. repeats the last edit
Would be interesting to know why. What made you switch from TextMate to VIM?
imap <silent> ii <Esc>:let &insermode=0<CR>
This doesn't work so well if you are frequently editing files on multiple servers you can't edit the .vimrc file on. But for your local environment it'll make going in and out of insert mode a lot more efficient.
I'm dead used to using ii now so I'm probably not going to switch, but others have pointed out kk may be a better choice, due to greater distance between keystrokes/mode. Indeed, about one in ten times I hit ii when I don't need to.
But I think you're right with "Vim", since even on vim.org it's spelled like that.