Vim for the win :)
I have been using Vim a lot in the last few weeks, to edit CSS and HTML files. It might seem a bit awkward at first but once you get used to it, it becomes great!
What helps a lot too is to configure Vim properly to make it perfect for use.
Vim and Vi configurations are done by setting variables using :set or by editing the file .vimrc in your home folder.
I will share here my Vim configurations and some of the commands I use more often. It also works as a Vim cheat sheet for my own future reference.
So, my ~/.vimirc looks like this:
set tabstop=2 expandtab autoindent smartindent shiftwidth=2 number
Here’s what each of them does
|tabstop=N||Sets the tab size to N spaces. The default is 4.|
|expandtab||Tabs are expanded, when you press tab, N characters will be inserted instead of a tab character (where N is the amount of spaces set for tabstop).|
|autoindent||Will keep the same indentation when you press enter in the end of a line.|
|smartindent||Vim will try to automatically detect indentations. For instance, if you go to a new line and enter a ‘}’, Vim will go back one indentation level.|
|shiftwidth=N||The number of spaces used for one indentation level.|
|number||Shows lines numbers.|
And here are some of the commands I use more often:
|Command||What it does..|
|:N||goes to line N|
|/foo||searches for ‘foo’|
|:%s/foo/bar/g||replaces all occurrences of ‘foo’ with ‘bar’ in the current file|
|:s/foo/bar/g||Same as above, but replaces only on the current line|
|:s/foo/bar/gc||Same as above, but prompts for confirmation before replacing each occurrence of ‘foo’. Can also be used with ‘%’ to replace all occurrences in the file|
|Shif + G||goes to the end of the file|
|v||enter select mode|
|<<||moves the current line one indentation level backwards;|
|>>||moves the current line one indentation level forward;|
|yy||copies current line to the buffer|
|dd||removes the current line out and place it on the buffer|
|p||pastes the text from the buffer on the next line|
Also remember that many of these commands may be used with a different number of lines.
For instance, pressing 1, 0, d, d will delete he next 10 lines.
Any other cool commands for Vim? Let me know on the comments!