Setup Your Pure VIM Dev Environment--Part II
- Install Vim Configurations
Install Vim Configurations
We have uploaded our vim configurations to repo, and you can install with following script:
$ wget -qO - https://raw.github.com/sunbingfeng/dot-vim/master/setup.sh | bash
- Leader key is set to
,, and you can change it to any character as you like
:: input a command manually
,+h:: show history vim commands, and it can boost the input speed of command
NERDTree: the File Explorer
A typical NERDTree workspace contains a navigation pane, and several file panes.
Following is my blog project opened through NERDTree:
Some key mappings used with high frequency:
,+n: toggle NERDTree pane
,+v: open NERDTree pane and the cursor focuses on current file
,+tn: switch to the next tab
,+tp: switch to the previous tab
Control+h/j/k/l: switch between different panes
When the cursor is at the NERDTree pane, you can:
?to show list of quick help
kto navigate down/up through files, and press
Enterto open it in current active pane
i: open the file under cursor in a vertical split pane
s: open the file under cursor in a horizontal split pane
t: open the file under cursor in a new tab
You can also press
m at the NERDTree pane to toggle the menu:
Thus, you can copy/move/delete file according to the tips.
Modern IDEs provide many useful shortcuts to make you code easier, e.g.,
goto file, etc.
If Vim can’t do that, it definitely will drop out. However, basic Vim doesn’t have these features. Luckily, we can realize these functions through plugins, e.g.,
FZF in our configuration.
High Frequency Usage
Control+p: search file by name
Control+g: search symbols at global range
Control+f: list symbols in current file, and you can view functions/members easily. Mote that you should create tags first according to tips in README
,+b: list opened buffers, and previous accessed file will be at the highest priority. You can press
Enterto switch back and forward.
,hh: list history accessed files
You can also bookmark at where you add a
TODO, or the line of code you want to access quickly later.
mm: toggle bookmark at current line
mc: clear all bookmarks
ma: list all bookmarks
The charm of Vim is that it provides you the probability to focus on the pure coding, and it definitely will make you happier.
In Vim, key shortcuts are everything. If you master them well, you can almost do everything getting rid of mouse. Not only can it boost your coding efficiency, but also avoid wrist and finger pain caused by heavy mouse use. These are huge advantages over other alternatives.
Coding with ease
There are many tutorials related to Vim, e.g, , and actually it’s impossible to give you an entire introduction in a few words. You can google yourself, and I only list some basics here:
h/j/k/l: [normal mode]move left/down/up/right
Control+u/d: [normal mode]page scroll up/down
i/a/o/s: enter edition mode;
jk: exit edition mode
u: undo edition;
Beautify Your Code
It’s nearly impossible to write a totally formatted code with just manual typing, so we need the tools to assist us.
clangformat to beautify our c++ code with specified style, and
yapf on python code.
,cf: format your code with configured style, e.g.,
View Code Changes
[c: take you to previous modified place
]c: take you to next modified place
,hu: revert your specified change quickly and one by one
That’s all, hope you have a nice journey to work with pure Vim environment!