|Written by Wayne Ye Sunday, June 22, 2014|
My life with Vim
I started learning Vim during Aug, 2011, the original motivation was trying to "get rid of my mouse while I am coding", I had no teacher but google, learnt it from the very hard way. From the beginning 2-3 months, honest speaking, I was less productive while using Vim comparing with IDEs, there were so many things I could do in second in IDE, for example: search/replace, formatting, re-factoring, folding, and so on, whereas I had to spent days in learning how to accomplish a simple task in Vim, that was really painful, but I never gave up! After the first two months of exploration, I was feeling much more comfortable in using Vim, and I believe I am going to use this king of text editor during rest of my life:).
Reasons why loving
There are millions of people love Vim during the past decades in the planet, there could be different reasons why people love Vim, I believe the ultimate reasons are:
Hacking with Vim technical talkNavigate with < and > Or Click to View the presentation in a new Tab
I did a technical talk to share my most favourite Vim tips to colleagues in Autodesk Singapore office, it was a short one, but with many ultimate and useful hacking tips with Vim, my intention was trying to excite people, let them open their mouth: "Wow! I never realized that Vim can do things like this!!", or "I did know Vim is powerful, I never expect it can be that powerful!!".
As I wish, I got some very positive feedback, and some familiar friends said they re-recognized me:)
My favourite Vim tips
The content below are the tips I demonstrated in my talk above, all of them are not my invention, but standing upon giant's shoulder! Since I will be using Vim in rest of my life, there is no doubt I about this point, and I wish I will contribute as much as I can to this god like text editor and its eco-system in the future!
Ultisnips + vim-snippets
Ultisnips boosts my coding speed like a rocket! It works with vim-snippets behind the scene to allow you to type very few characters but generates a usually used code snippet for you, with place-holders for you to easily customizing the snippet, this combination supports all mainstream languages as long as there are geeks speak it! See my screenshot below:
Dragging line(s) with automatically indentation fixing, this trick is accomplished by adding the following lines into vimrc:
" Alt+j/k to move current line/selected lines up and down nnoremap :m+== nnoremap :m-2== inoremap :m+==gi inoremap :m-2==gi vnoremap :m'>+gv=gv vnoremap :m-2gv=gv
It works for single line:
It works for multi lines:
The JSON conversion I did during the technical session was accomplished by the following key combinations:
Learn more: Macros - Vim Tips Wiki
Execute script inside Vim
Every vimer knows we can execute script (shell, perl, python, ruby, js, just everything) right inside Vim without switching to terminal, although many people are tmux funs, I still prefer do it in Vim's way, by having the following lines in my vimrc, I can instantly run the current script and view the result with nearly no latency:)
autocmd FileType sh map
Match & Until
f$ # Forward to the first occurrence of $ within current line
F$ # Backward to the first occurrence of $ within current line
dt$ # Delete content until matching the first occurrence of $ within current line
vt$ # View (Select) content until matching the first occurrence of $ within current line
Search & Replace
Vim is extremely powerful in dealing with searching and replacing, the trick I've done in the session is just tip of the iceberg, I typed :g/#/d to remove all comments in a Ruby file.
This is a awesome Chrome extension, the home page is: https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb?hl=en, suffering the internet without mouse is absolutely feasible!
My future on Vim
I have been using Vim everyday during the past 3 years, I never stopped learning it, and with no doubt, I will do so in rest of my life, really, I just can't breath without it!
There are absolutely a lot of improvement space for me, apart from continuously improve productivity, I have intention to do more things in vim: Email, highly customized snippets (refer: Ultisnips Screencast Episode 4, presentation, and more important, I want to contribute to Vim ecosystem!