
June 5th, 2007 by

Pete
One of the things I always found awkward about Vim is stretching for the ESC key to get out of insert mode.
Here's a little trick that I like to add into my .vimrc file:
CODE:
-
map <space> i
-
imap <S-space> <esc>
This will let you escape insert mode by pressing shift and space and enter insert mode by pressing space.
/* Pete Graham */
Posted in vim |
No Comments »

May 3rd, 2007 by

Pete
Vim has some really useful commands, especially search and replace ones. Unfortunately I'm always forgetting the finer details of how to use them so here's an example:
CODE:
-
:%s/$/\rthis is a new line
To break down whats happening above:
- : switches Vim into command mode
- % means we're going to apply this command to every line in our file
- s means we're using the substitute command. The format of the command is s/search/replacement, 'search' can be a regular expression
- $ tells vim to search for the end of the line
- \rthis is a new line tells vim to replace with a new line character, and to put the text "this is a new line" on that line.
NOTE: \r is used as the new line character when vim is using DOS file format, to find out which file format you are using type :set ff? You can find out more about Vim file formats here.
#Pete Graham
Posted in regex, regular expressions, vim |
9 Comments »