As the saying goes: If you want to do a good job, you must first sharpen your tool. As a programmer, a commonly used tool is an editor . I choose an editor vim that can greatly improve my development efficiency (some people may choose emacs ). The vim editor has the following features:
-
Cross-platform and unified environment
Whether in windows or *nix, vim is a perfect cross-platform text editor, and can even be directly configured and used on server platforms CentOS, Ubuntu, etc. The configuration files are similar, and the operating habits are basically the same. -
Customizable and extensible
vim provides a vimrc configuration file to configure vim, and you can customize some plugins to achieve file browsing ( NERD Tree ), code completion ( YouCompleteMe , syntax checking ( syntastic ), file fuzzy search ( ctrlp ), Display vim status bar ( Vim Powerline ), theme color ( Molokai ), display file structure ( tagbar ) and other functions. -
Efficient command line
Editing text with vim can only be done on the keyboard, no mouse at all. In the case of cursor movement, it is much more efficient to press a key to move in units of words, lines, blocks, or functions, compared to repeated keystrokes, character-by-character, or line-by-line movement. Sometimes some operations of repeated deletion and pasting can be completed with only one command, and you can even use key mapping to simplify or combine multiple commands to improve efficiency.
configure
If you need to configure vim, just create a ~/.vimrc file in the Home directory to configure vim, you can refer to my vimrc configuration file. Since I need to install plugins, and separate the list of plugins to be installed to another file ~/.vimrc.bundles , this file is also stored in the Home directory, and the content of the file can refer to vimrc.bundles . To load the ~/.vimrc.bundles file, you must add the following code snippet to the ~/.vimrc file:
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
endif
plugin
Plugin management tool vunble
Vundle is a plugin management tool for vim, it can search, install, update and remove vim plugins, no longer need to manually manage vim plugins.
- Create a ~/.vim directory and a .vimrc file in the Home directory (you can copy my vimrc file)
-
install vundle
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
- Add vundle support in .vimrc configuration file
But in fact, I added a ~/.vimrc.bundles file to save the configuration of all plugins. The following code snippet must be added to the ~/.vimrc file:filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc()
The content of the ~/.vimrc.bundles file must contain:if filereadable(expand("~/.vimrc.bundles")) source ~/.vimrc.bundles endif
You can copy my ~/.vimrc.bundles file to the Home directory.filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc()
Install the plugin
Bundles are divided into three categories, the more commonly used is the second :
- For repos under the Github vim-scripts user, just write the repos name
- For repos under other users on Github, you need to write "username/repos name"
- For plugins not on Github, you need to write out the full path of git
Configure the installed plugins in ~/.vimrc , but I put the plugin configuration information in ~/.vimrc.bundles :
" Define bundles via Github repos
Bundle 'christoomey/vim-run-interactive'
Bundle 'Valloric/YouCompleteMe'
Bundle 'croaky/vim-colors-github'
Bundle 'danro/rename.vim'
Bundle 'majutsushi/tagbar'
Bundle 'kchmck/vim-coffee-script'
Bundle 'kien/ctrlp.vim'
Bundle 'pbrisbin/vim-mkdir'
Bundle 'scrooloose/syntastic'
Bundle 'slim-template/vim-slim'
Bundle 'thoughtbot/vim-rspec'
Bundle 'tpope/vim-bundler'
Bundle 'tpope/vim-endwise'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-surround'
Bundle 'vim-ruby/vim-ruby'
Bundle 'vim-scripts/ctags.vim'
Bundle 'vim-scripts/matchit.zip'
Bundle 'vim-scripts/tComment'
Bundle "mattn/emmet-vim"
Bundle "scrooloose/nerdtree"
Bundle "Lokaltog/vim-powerline"
Bundle "godlygeek/tabular"
Bundle "msanders/snipmate.vim"
Bundle "jelera/vim-javascript-syntax"
Bundle "altercation/vim-colors-solarized"
Bundle "othree/html5.vim"
Bundle "xsbeats/vim-blade"
Bundle "Raimondi/delimitMate"
Bundle "groenewege/vim-less"
Bundle "evanmiller/nginx-vim-syntax"
Bundle "Lokaltog/vim-easymotion"
Bundle "tomasr/molokai"
Bundle "klen/python-mode"
Open vim, run :BundleInstall
or run directly in the shellvim +BundleInstall +qall
After installing the plugin, there may be another problem: the vim version is not high enough
The vim version can be updated with the following command
brew install macvim --override-system-vim
Then run the following command to symlink to/Application
brew linkapps macvim
Finally .zshrc
use an alias in the config file to use the updated vim
#setup macvim alias
alias vim='/usr/local/opt/macvim/MacVim.app/Contents/MacOS/Vim'
Common plugins
NERD Tree
NERD Tree is a tree-shaped directory plug-in, which is convenient for browsing the directories and files in the current directory.
I configure the NERD Tree in the ~/.vimrc file, setting a keymap that enables or disables the NERD Tree
nmap <F5> :NERDTreeToggle<cr>
So you can enable or disable NERD Tree just by pressing the F5 key , NERD Tree provides some common shortcut keys to manipulate directories:
- Move the cursor through hjkl
- oOpen and close a file or directory, if you want to open a file, you must move the cursor to the file name
- tOpen in tab
- s and i can split the window horizontally or vertically to open the file
- p to the upper directory
- P to the root directory
- K to the first node in the same directory
- P to the last node in the same directory
YouCompleteMe & syntastic
YouCompleteMe is a fast vim code completion engine that supports fuzzy matching. Since it provides code hints for C/C++/Objective-C based on the Clang engine, it also supports code hinting engines in other languages, such as Jedi -based Python code completion, OmniSharp - based C# code completion, and Gocode - based Go code completion Complete.
Just type the code, it will automatically prompt the list of codes you want to enter, you can select one of them, and then the tab key can complete the code.
YouCompleteMe has integrated Syntastic , so once you write code with a syntax error, there will be a red error prompt
ctrlp
I don’t know if you have encountered such a situation: in large-scale engineering projects, directories and files are deeply nested. To open a file, you need to enter the directory one by one to open it. In this case, it is time-consuming and inefficient. ctrlp redefines the way to hit directories and files, especially for browsing large-scale project files.
enable ctrlp
- Run command
:CtrlP
or:CtrlP [starting-directory]
to enable ctrlp in find file mode - Run the command
:CtrlPBuffer
or:CtrlPMRU
to enable ctrlp to find buffered or recently opened files mode - Run commands
CtrlPMixed
to find files, find buffers and recently opened files mixed mode to start ctrlp
basic use
- Press
<c-f>
and<c-b>
to toggle between the three search modes - Press
<c-y>
to create a new file and corresponding parent directory - Press
<c-d>
to switch to looking only for filenames instead of full paths - Press
<c-j>
,<c-k>
or the arrow keys to move the search result list - Press
<c-t>
or<c-v>
to<c-x>
open the file in a new tab or split window - Press
<c-z>
to mark or unmark the file, then press<c-o>
to open the file - Press
<c-n>
to<c-p>
select the next/previous string in the prompt history
The demo video shows
how to use ctrlp, please refer to the demo video of happypetterd , the explanation is very clear.
Vim Powerline
Vim Powerline is a plug-in that displays vim status bar, it can display vim mode, operating environment, encoding format, number of lines/columns and other information
Molokai
Molokai is the vim color theme, the effect is as follows
Common commands
For the basic commands of entry vim, you can refer to the concise Vim leveling guide . The following are my common commands such as moving the cursor , inserting/modifying , deleting , copying , pasting , undoing and restoring .
-
move the cursor
- For moving within a line , use
f/F + 字符
to move to a specific character, and then use.
to repeat the command;f
to move forward, and to moveF
backward. If you want to move directly to the beginning or end of a line, use^
or$
- For moving in multiple lines , there are multiple options: the first one is to move by
gg
specifying the number of lines, which means toG
move the first line of the file, which means to move the last line of the file, which means to move to a specific line. The second is to move through regular search , which means forward search, means reverse search, find the next matching result, means the previous matching result, and press to browse the search history. The third is to use the marker to move, the marker position (for a single file, if it is multiple files, use capital letters ), move to the column of the marker position, move to the beginning of the line at the marker position, and some special markers, Indicates the position of the cursor before the jump行数 + G
gg
G
行数 + G
/string
?string
n
N
up/down
m + {a-z}
{A-Z}
`{mark}
'{mark}
'
- For moving within a line , use
-
select text
v
irregular select selectV
by row selectCtrl + V
by column -
Insert/Modify
i
before the current character InsertI
at the beginning of the line Inserta
after the current character InsertA
at the end of the line Insert ato
the next line ofO
the current line Insert at the previous line of the current liner
Change current characterR
Change multiple characterscw/caw
Change wordcf + 字符
Change from current character to specified characterc$
Change from current character to end of linecc
Change entire line -
Delete
x
delete characterdf + 字符
delete from the current character to the specified characterdw/daw
delete wordd$
delete from the current cursor to the end of the linedd
delete a line -
Cut and paste
dd + p
the delete line, then place the delete line below the current cursor , then place the delete worddd + P
above the current cursor , then place the delete word after the current cursor, then place the delete word before the current cursor Acceptable count prefix, repeat pastedw + p
dw + P
p/P
-
Copy
yw
Copy wordyf
Copy from the current character to the specified charactery$
Copy the current cursor to the end of the lineyy
Copy the entire line -
Undo and Redo
u
Undoctrl + r
Redo -
Repeat action
数字+action
indicates how many times an action is performed to.
repeat the previous action -
Macro recording
q + 寄存器(a-z)
start recording录制动作
q
stop recording@ + 寄存器 / @@
replay recorded macro
original link: http://www.jianshu.com/p/a0b452f8f720
The copyright belongs to the author, please contact the author for authorization, and mark "author of Jianshu".