If you don't use Vim, you should be!
In light of this discussion, I will use this space to emphasize how if you're not using Vim, you're really missing out.
Note: I heard Vim on windows is not good at all (gvim). You may be better sticking with sublime. Perhaps someone has some insight who uses gvim on how to make the experience a bit smoother. On the off chance you're on a Mac though (MacVim), and have heard people talking about Vim, but never really took a look at it -- it is a magnificent piece of software.
Trying to think of myself going back and using textmate or other single-mode editor is just painful.
If you don't really know what it is, allow me to explain.
Firstly, the learning curve is very heavy but after a good 5-7 days of solid use you will be comfortable enough where you are up to speed at least as fast as your old editor. Give it another month and you should be 4-5x faster, if not more.
Vim basically has multiple "modes", where as a standard editor has one mode. For something like, say, textmate, that single mode is "edit" mode. You move the cursor around with the arrow keys (shudder), or with the mouse (double shudder). If youre good at hotkeys, you may move the cursor around with alt+arrows to skip by word, or command+arrows to go to the beginning/end of line/file.
In Vim, you have multiple modes (I vaguely remember there being 9 or more, but theres 6 main ones you will use): insert mode, normal mode, command mode, visual mode, visual line mode, visual block mode.
insert mode is the equivalent of any other editors text edit mode. This is where you actually write code, delete, etc. Note that this does NOT include movement.
normal mode is used for movement. To get 'into' normal mode from insert mode, you press escape (or, control-C in my case). Technically it's capslock-C because I remapped capslock as a control key. Normal mode is where you move around the file very easily using motion verbs + a direction. for example:
See common actions here for normal mode: http://www.eastcoastefx.com/vim
command mode is used for running commands, its essentially a 'mini terminal'. You can run rails tests from here, run rake tasks, do very complex find replace, and a lot more. To get into command mode you press
: from normal mode
visual mode is used for selections. Press
v once from normal mode to insert visual mode, then use the movement keys to select a block of code.
visual line mode is entered by pressing
V). This selects an entire line at once.
visual block mode is similar to textmate or sublime text's feature where you can hold alt while using the mouse to select some arbitrary 'square' of text, even if its in the middle of the document, and then type on multiple lines at once with multiple cursors.
So, without further ado here are some examples to help make this jumbled mess make sense. Note... these are very simple examples: as stated by tamok in this thread, it can get a lot more complex.
- Say youre editing HTML. While in normal mode here are a few commands
vitwill visually select inside the html tag.
vatwill visually select outside the tag ("visually select around tag" is what
vatbasically means). You dont need to just visually select something too.
datwill delete the outer tag while remaining in normal mode, and
citwill delete whats inside a tag and then change to insert mode automatically.
- Say you want to move a whole block of css text below another one. Instead of selecting it with the mouse like a buster, you can push
V%djjpThat will enter visual line mode,
%will go to a closing brace,
ddeletes it into a buffer,
jjmoves down some arbitrary amount,
pputs the last thing in the buffer BELOW the cursor (use
Pto put it above the cursor)
- to delete all empty lines I do
,del, to format an html document i do
- Say I want to wrap a list of text in an unordered list, but the text is prefixed with "- Item" like someone would write it in an email.
V3j:s- //gthen press return. That will enter visual line mode, go down 3 lines, gsub the selection '- ' with ''. Then press
V3kStul>jthen enter visual block mode with
kk0Stli>to wrap in list item tags using tim Pope's surround plugin. The nice part about vim is you can entirely write your own functions and macros as well, so if you find yourself getting a lot of these lists, you spend 2 minutes writing a function in your .vimrc file and then can do chained functions with one keypress.
Those examples were from my head, and they are in no way the 'best' way, just a few examples to get your feet wet. You can basically think of it as typing your way to movement rather than using the mouse or arrow keys.