Reblogged from: http://yannesposito.com/Scratch/en/blog/Vim-as-IDE/
This short article is about how the author use Vim as an IDE. Mainly by using some great plugins.
1. Vim Plugin Manager
There are a lot of Vim plugins. To manage them I use vim-plug
.
To install it:
☞ Note I have two parts in my .vimrc
. The first part contains the list of all my plugins. The second part contains the personal preferences I setted for each plugin. I’ll separate each part by ...
in the code.
2. Survival
2.1 Colorscheme
![Solarized theme](https://i-blog.csdnimg.cn/blog_migrate/5a5dabc54cf76b9c86c5e972a3d67984.png)
Before anything, you should protect your eyes using a readable and low contrast colorscheme.
For this I use solarized dark. To add it, you only have to write this in your ~/.vimrc
file:
2.2 Minimal hygiene
You should be able to see and destroy trailing whitespaces.
![Trim whitespaces](https://i-blog.csdnimg.cn/blog_migrate/3f21840d4c2def33dde8bdb53ab53f98.gif)
You can clean trailing whitespace with :FixWhitespace
.
And also you should see your 80th column.
![80th column](https://i-blog.csdnimg.cn/blog_migrate/cdb1837030d0cc0d31e6e6ee7eca941d.png)
3. File Management
One of the most important hidden skills in programming is the ability to search and find files in your projects.
The majority of people use something like NERDTree
. This is the classical left column with a tree of files of your project. I stopped to use this. And you should probably too.
I switched to unite. No left column lost. Faster to find files. Mainly it works like Spotlight on OS X.
First install ag
(the silver search). If you don’t know ack
or ag
your life is going to be upgraded. This is a simple but essential tool. It is mostly a grep
on steroids.
Now type space twice. A list of files appears. Start to type some letters of the file you are searching for. Select it, type return and bingo the file opens in a new horizontal split.
![Unite example](https://i-blog.csdnimg.cn/blog_migrate/cf44c360b126875a85732107078e1b0b.gif)
If something goes wrong just type <space>r
to reset the unite cache.
Now you are able to search file by name easily and efficiently.
Now search text in many files. For this you use ag
:
Don’t forget to add a space after the :Ag
.
These are two of the most powerful shortcut for working in a project. using °
which is nicely positioned on my azerty
keyboard. You should use a key close to *
.
So what °
is doing? It reads the string under the cursor and search for it in all files. Really useful to search where a function is used.
If you type <space>/
followed by a string, it will search for all occurrences of this string in the project files.
So with this you should already be able to navigate between files very easily.
4. Language Agnostic Plugins
4.1 Git
![Show modified lines](https://i-blog.csdnimg.cn/blog_migrate/176145d60e6a6d2935f4fa7dd03259a3.png)
Show which line changed since your last commit.
And the “defacto” git plugin:
You can reset your changes from the latest git commit with :Gread
. You can stage your changes with :Gwrite
.
![Reset changes](https://i-blog.csdnimg.cn/blog_migrate/032319a53c597165a89715059e8cbad5.gif)
4.2 Align things
Just select and type Return
then space
. Type Return
many type to change the alignments.
If you want to align the second column, Return
then 2
then space
.
![Easy align example](https://i-blog.csdnimg.cn/blog_migrate/e8d0b1107edc8b448913980da192fee7.gif)
4.3 Basic auto completion: C-n
& C-p
Vim has a basic auto completion system. The shortcuts are C-n
and C-p
while you are in insert mode. This is generally good enough in most cases. For example when I open a file not in my configured languages.