Vscode recently in tech circles fire for a while, every day can see amway articles and exotic plug-in on the nuggets, “Mr Yang more encourage division”, and work to touch the fish series, “reading a novel plug-in”, “watching stock plug-in”, let me feel vscode function more and more strong, strong enough to do anything, just like the operating system, And this doesn’t look much like emacs, the god editor. Recently, there was a traitor in Taiwan emacs circle, and finally the defender defected to vscode camp and posted the news to Taiwan’s official emacs twitter.
The editor war, which is the best editor, Vim or Emacs, is one of the most enduring debates in the programmer community, and one that could easily spark a holy war anywhere. The development languages used in the company are mainly C++ and python, and the development environments used by our team members are also various, including NetBean, vscode, C++ eclipse, pycharm and vim. An editor or IDE is always just a tool. The value of a tool is not how powerful or rich it is, but how much value it can give us, so the value of the same tool cannot be compared with different people. My point is that if you’re going to be using two or three languages a lot in your development process, it’s important to have a habit interface, and I would recommend vim; However, IDE is a highly packaged tool, which has certain assumptions about the development process, development methods, etc., so in many cases, especially in practical projects, it will also save a lot of valuable time for us.
Each IDE has its own configuration and usage habits, and switching from one IDE to another can be costly. In addition to Vim, I usually use Sublime to look at code in Windows because it’s light and quick to edit, cut and copy in Windows. I developed python with pycharm, and developed C++ with eclipse for a period of time. It is convenient to synchronize the code from Windows to remote Linux with beyond compare, and then make compilation. But it all came down to Vim.
Tell me why I chose Vim as my primary development environment. There are many ides, and the cost of learning is just as high. There are N ides for N languages. The IDE has its own benefits; it is already integrated and optimized for one language, and the user doesn’t really have much to configure. But in fact, the more highly solidified things may be more difficult to use, the lack of certain flexibility. Vim has a lot of plugins, supports a lot of languages, and also solves the problem of running Linux synchronically. Famous plugins are active on Github and StackOverflow. One Vim solves all ides.
I use vim for python and C++ background development, the most important functions can not be lost, prompt completion, definition jump, keyword search, syntax highlighting, syntax check, indent folding, function display outline, file template, directory tree and so on, and my vim now can also facilitate the completion of these functions.
Let’s start with the vim plug-in I used in 2019. This is mainly a brief introduction. For each one, I will briefly introduce the plug-in and the operation of using it, as well as the most important documents, because there are more detailed information about using it.
Learning resources
There is a great vim learning resource on Github, starting with the simplest introduction:
Vim from Beginner to Master: github.com/wsdjeg/vim-… Vimscript: www.treelib.com/book-detail…
In addition, I also pay attention to some Vimers on Zhihu, such as:
- WeiYi smile (www.zhihu.com/people/skyw.)
- Qi-ming zhao (www.zhihu.com/people/zhao)…
- Vim column (zhuanlan.zhihu.com/hack-vim)
It usually covers how to set up the Vim IDE and plug-ins.
In addition, I also like to browse vim-related plug-ins on Github in descending order of Most Star.
My.vimrc reference: github.com/cposture/my…
Plug-in management
The plug-in
- Plug.vim:github.com/junegunn/vi…
Vim 8 already supports asynchronous execution and is supported in most plug-ins, and asynchronous plug-in managers such as Plug.vim no longer have to wait so long to update plug-ins and no longer recommend the old Vundle.
Vim-plug not only supports asynchronous updates, but also supports lazy loading for file types and startup commands, making vim’s startup speed even faster.
The document
- Installation and use: blog.jobbole.com/114132/
- Lazy loading plug-ins technique: segmentfault.com/a/119000001…
- Vim slow start analysis: segmentfault.com/a/119000001…
configuration
Lazy-loaded plug-in
Plug. vim supports lazy plug-in loading so that unrelated plug-ins don’t start at first; Plug. vim supports configuration by command or file_type.
NERDTree plugin starts loading Plug 'scrooloose/nerdtree' when executing NERDTreeToggle for the first time, {'on': 'NERDTreeToggle'}"On supports multi-command Plug'junegunn/vim-github-dashboard', { 'on': ['GHDashboard'.'GHActivity']}"Plug 'tpope/ Vim-Fireplace ', {'for': 'Clojure'}" forSupport multi-file type Plug'kovisoft/paredit', { 'for': ['clojure'.'scheme']}Copy the code
Use the on lazy load YouCompleteMe method:
- The on command list is left blank. It will not start by default
- We use automatic command, can make Vim automatically execute the specified command, the specified command will be executed when the specified event occurs; To enter insert mode, manually call Plug# load(‘YouCompleteMe’)
- Example Delete an automatic command group
# on is empty and will be loaded manually later
Plug '~/YouCompleteMe', {'on': []}
augroup load_ycm
autocmd!
"Lazy loading in insert mode manually loading plug-ins autocmd InsertEnter * call plug# load (' YouCompleteMe) | autocmd! load_ycm augroup ENDCopy the code
Lazy loading is not a silver bullet, ultimately it depends on whether there is a need for it; So we try lazy loading only when there is a slow start. In addition, plug-in authors generally consider their own lazy loading capabilities, rather than waiting for external plug-ins to implement lazy loading.
So how do you analyze plug-in problems with slow startup?
Vim –startuptime vim.log -c q specifies the startup option vim –startuptime vim.log -c q specifies the startup option vim –startuptime vim.log -c q specifies the startup option vim –startuptime vim.log -c q.
times inmsec clock self+sourced self: sourced script clock elapsed: other lines ... 003.691 002.008: sourcing /home/luffichen/.vim/autoload/plug.vim
021.676 000.021 000.021: sourcing /usr/local/ share/vim/vim81 / filetype. Vim 021.869 000.017 000.017: sourcing/usr /local/share/vim/vim81/filetype.vim
...
Copy the code
The first column is the point in time, the second and third columns are both long (difference: the second is self+sourced, the third is self), and we focus on the third column, the execution time of the script itself.
Because the same plug-in will have multiple rows of data, we need to manually count the third column of the same plug-in as a sum, which is very tedious, so someone on Github wrote a plug-in, specifically to analyze the execution time of each plug-in, and output the line graph, you can see: github.com/hyiltiz/vim…
And other analysis methods, specific visible: VIM acceleration: segmentfault.com/a/119000001…
Simple operation
:PlugInstall
To install the plug-in that has been added to.vimrc:PlugStatus
To view the installation progress:PlugClean
Delete plug-ins that are not in the configuration file
Installing plug-ins offline
Since the Linux development environment of the company generally cannot be connected to the Internet, it is not possible to directly install plug-ins from Github using Plug. My method is as follows:
Taking Auto-pairs as an example,
- In an environment with access to the Internet,
git clone https://github.com/jiangmiao/auto-pairs
- Package and compress auto-womp.zip
- Upload the compressed package to the server and decompress it.
rz -bye
,unzip auto-pairs.zip
- Copy to the custom plugin directory, which I put here
~/vim-plugin
Next,cp -rf auto-pairs ~/vim-plugin/
- Configure.vimrc to specify the local directory for the plug-in,
Plug '~/vim-plugin/auto-pairs'
- Run vim, and execute
:PlugInstall
- Check the installation,
:PlugStatus
Prompt completion
The plug-in
- YouCompleteMe:github.com/Valloric/Yo…
- YCM-Generator:github.com/rdnetto/YCM…
- Jedi-vim:github.com/davidhalter…
- Vim Omnicomple: Vim comes with it
These plug-ins are perfect for code completion and hints in C++ and python, and other languages can be referred to in other introductions.
With the promotion of VScode LSP, the corresponding plug-in for VIm syntax completion also appeared, such as coc.nvim, which is mainly asynchronous and supports a lot of SYNTAX completion plug-ins on VScode. You can try it out (PS: The company’s system version is older and the network is disconnected, so we haven’t bothered about this plug-in. I heard that there is a packaged version, you can not install, there is a need to try it).
Coc. Nvim detailed introduction: zhuanlan.zhihu.com/p/39302327 coc.nvim:github.com/neoclide/co…
For C/C++ completeme, please use YouCompleteMe directly. In addition, yCm-Generator is mainly used to solve the troublesome problem of generating the YouCompleteMe configuration file.
The latest version of YCM also supports Python completion, as long as a Jedi can be installed, but the company development environment system version is not very high, can not compile the latest version of YCM, so install a backend Jedi as the completion client plug-in Jedi-Vim.
I also wanted to introduce SuperTab(github.com/ervandew/su…) , its function is simply to use TAB to call the completion function of VIM, which is completely consistent with Linux operation habits, convenient and reasonable, but YCM itself contains the function of SuperTab, so there is no need to install SuperTab plug-in, in order to avoid conflicts. In addition, the YCM documentation also describes the functionality of other plug-ins, as follows:
clang_complete
AutoComplPop
Supertab
neocomplcache
Copy the code
Finally add omnicomple, sometimes YCM and Jedi-Vim cannot complete in some cases. For example, I often encounter that I just want to complete a word THAT I wrote before. This word may be just a word in the comment, and YCM cannot find it. I’ll use the omnicomple command series at this point.
The document
- Jedi – vim plug-in installation reference documentation part: xmfbit. Making. IO / 2018/10/02 /…
- Omnicomplete, Vim omnipotent,
:help ins-completion
- For details about YCM operations, see github.com/Valloric/Yo…
- YCM configuration: zhuanlan.zhihu.com/p/33046090
configuration
YCM
Ycm_extra_conf. py configuration file is described in detail on Google. Here we use the Ycm-generator plugin. You can generate the required configuration files for a make build system.
"= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
"Ycm-generator plug-in configuration
"= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
"Ctrl-i automatically generates.ycm_extra_conf.py
noremap <C-I> :YcmGenerateConfig -c g++ -v -x c++ -f -b make .<CR>
Copy the code
After the above configuration is added to.vimrc, pressing ctrl-i after opening the project root directory will automatically generate the configuration file in the current directory
ctrl + I
, automatically generates.ycm_extra_conf.pyCtrl + Space
Trigger the completion suggestion anywhere, even without a string prefix. This is useful for seeing which top-level functions are available.:YcmRestartServer
, restart:YcmDiags
和:YcmDebugInfo
, query information:YcmCompleter
Command, in conjunction with other suboptions, for example,GoToDeclaration
Jump to declaration
omnicomple
Ctrl-X Ctrl-L
: Complete the entire lineCtrl-X Ctrl-N
: Completes the keywords in the current fileCtrl-X Ctrl-i
: Keywords in the current file and its header fileCtrl-X Ctrl-]
: tags completionCtrl-X Ctrl-F
: File name completionCtrl-X Ctrl-O
: Omni completion
Why do you need omni when YCM can’t complete the string in buffer? Ctrl-x Ctrl-n
jedi-vim
leader + d
: Defines jumps, including statements and import modulesleader + n
: Check usageleader + r
Rename::Pyimport os
: Starts the OS of the moduleCtrl + space
: completion
instructions
- Centos system is old, using YCM version is not the latest, I here github.com/Valloric/Yo… Version for clang + LLVM 3.3 – amd64 – Ubuntu – 10.04.4. Tar. Gz
Syntax highlighting
The plug-in
- Vim-polyglot:github.com/sheerun/vim…
Vim-polyglot is an out-of-the-box syntax highlighting and alignment package that supports 134 languages. At the same time, all language files are lazily loaded according to file types, which will not affect the startup speed of VIm.
For details about the supported languages, see github’s introduction: github.com/sheerun/vim…
configuration
There is almost no configuration to load, just vim to turn on the Syntax function.
syntax on
Copy the code
The indentation line
The plug-in
- IndentLine:github.com/Yggdroot/in…
IndentLine is a plugin that displays vertical lines. It is used to keep code neat, but the plugin only supports space lines, so it does not display lines for tab-aligned code. Because different editors display tabs differently, some show four Spaces, some show eight; My habit is to have Vim automatically convert TAB entries to four Spaces, and this code is displayed the same in all editors.
TAB automatically converts to 4 Spaces:
"Automatically expands the input TAB to a space. Ctrl -v
set expandTab"
Use the number of Spaces indented per layerset shiftwidth=4
"Set tabstop=4"After ET is enabled, you can use the backspace key. Each backspace deletes X Spacesset softtabstop=4
"Make backspace handle indent, eOL, start, Backspace set backspace=indent, eOL,startWhen enabled, pressing TAB at the beginning of the line adds the Shift idth space, otherwise adds the tabstop spaceset smarttab
Copy the code
IndentLine configuration:
D :indentLine_char=' d 'Copy the code
operation
:IndentLinesToggle
Open the indent line
Syntax highlighting + indent line diagram
Syntax checking
The plug-in
- ale:github.com/w0rp/ale
Ale is a syntax checking plugin similar to Syntastic, but with one obvious advantage. One is that the syntax checking is performed asynchronously, so there is almost no lag, but it only supports Vim 8.0 and older.
Ale supports a variety of code parsers in multiple languages and, in the case of C/C++, supports: GCC, CLang, CPPCheck, clang-format, etc., need to be installed separately and placed under PATH. ALE can automatically call these linters to analyze the latest code after you modify the text, and then summarize the results of various Linters and display them on the interface.
Because LSP protocol supports syntax checking, ALE also supports LSP, and also supports LSP syntax completion. As a result, ALE becomes larger and larger, and I basically use it as a syntax checking plug-in.
The ALE and the clang toolset should set up and use good, there’re a lot about the clang https://github.com/w0rp/ale/blob/master/doc/ale-c.txt here configuration options, Support for compile_commands.json, which eliminates header lookup issues, but the company runs older versions of the system.
The document
- Ale official documentation: github.com/w0rp/ale/tr…
- The Vim plug-in ale:www.cnblogs.com/awakenedy/a…
configuration
ale
Ale configurations typically specify language-specific linter and linter options; I have only configured syntax checking for C++, C, and Python. C++ and C use cppCheck, and Python uses PyLint; So you need to install additional cppCheck and PyLint externals.
G :ale_linters are used to specify linters, and I configured syntax checks to be performed only when normal changes are made and inserts are left to avoid speed delays.
let g:ale_linters = {
\ 'cpp': ['cppcheck'], and \'c': ['cppcheck'], and \'python': ['pylint'], and \}Linter let g:ale_lint_on_text_changed = 'normal'"Run Linter when you leave INSERT modelet g:ale_lint_on_insert_leave = 1
let g:ale_c_cppcheck_options = '--enable=all'
let g:ale_cpp_cppcheck_options = '--enable=all'
Copy the code
A short piece of code shows the syntax check results for CPPCheck and ALE:
int *ptr_list = NULL;
*ptr_list = 1;
Copy the code
Error: Null pointer dereference ();
Keyword search
The plug-in
- FlyGrep:github.com/wsdjeg/FlyG…
FlyGrep is a real-time code search tool ported from SpaceVim(spacevim.org/cn/) with regular expression support, and a ctrl-F shortcut is just like any other IDE search.
FlyGrep can only search files in the current directory, so if you want to search the entire project, you need to switch to the project root directory first.
The document
- For details about FlyGrep and how to use it, see the official document github.com/wsdjeg/FlyG…
configuration
FlyGrep
Bind shortcut ctrl-F:
"= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
"FlyGrep plug-in configuration
"= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
nnoremap <C-F> :FlyGrep<CR>
Copy the code
operation
FlyGrep
Ctrl-F
Search for keywords in the current directory. Here I usually search in the project root directory, so move to receive the root directory first<Esc>
, exit the search<Enter>
To enter the selected search results<Tab>
, the next search result<S-Tab>
, the last search result<Home>
The first one starts the result<End>
“, the last search result
Vim bring
Take the search term “main” for example:
-
: vim/main / % | copen: search only the current file
-
Vim/main / * | copen: only search the current directory
-
vim /main/ .. / * * | copen: search ranking directory, and recursive
-
Path2 / vim/main path1 / * * * * | copen: can search in the multiple paths
Description:
%
Represents the current filecopen
Open a window to store search results
Search figure
Switch the source file header
The plug-in
- CurtineIncSw.vim:github.com/ericcurtin/…
C++ projects often need to switch between the header and the corresponding source file; CurtineIncSw provides this functionality, but there are certain prerequisites for switching:
- Header files and source files should have the same file name except for the suffix and directory. For example, foo.c corresponds to foo.h
- Both files are either in the same directory, or the file to be opened is in a subdirectory of the opened file
Operation:
leader-R
: Switch between the original file and source file
jump
- Jedi-vim:github.com/davidhalter…
- ctags
- Vim-gutentags:github.com/ludovicchab…
- Vim-matchup:github.com/andymass/vi…
For python jumps, I used jedi-Vim; C++ jump I use vim + ctags tools; The jump to the tag uses vim-matchup.
Ctags need to be installed yourself.
It used to take a long time to write a few lines of code and run CTags to generate the index.
Vim – Gutentags does two things:
- Determine the project directory to which the file belongs. That is, the current file path recursively searches for landmark files (you can customize them) such as.git,.svn, and.project to determine the project directory to which the file belongs.
- Detect file changes under the same project and automatically incrementally update the corresponding project’s.tags file. Each change of a few lines does not have to be completely regenerated, and this incremental update ensures the symbol ordering of the.tags file, making it easier for Vim to quickly search symbols with binary lookup.
configuration
vim-gutentags
"Gutentags searches for project directory flags, Let g:gutentags_project_root = ['. Root ', '.svn', '.git', '.hg', '.project']"The name of the generated data filelet g:gutentags_ctags_tagfile = '.tags'
"Place all the automatically generated tags files in the ~/. Cache /tags directory, Let S :vim_tags = expand('~/. Cache /tags') let G: gutentags_cache_DIR = s:vim_tags"Configure the parameters of ctagslet g:gutentags_ctags_extra_args = ['--fields=+niazS'.'--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
Copy the code
With this setup, you don’t even know the tags file is being generated. Once the file is modified, Gutentags does it for you in the background.
Adds the momentum of the corresponding tags file to the current file without affecting other files. Thanks to Vim 8’s asynchrony, you can use cTags whenever you want, and the database is up to date. Note that Gutentags relies on the flags in project_root defined above to determine which project the file is in. If a file is not hosted in.git/.svn and Gutentags cannot find the project directory, it makes sense not to generate tags for that wild file. To avoid this, you can put a blank file named.root in your wild file directory and actively tell Gutentags that this is the project directory.
operation
- Operation:
ctrl+]
: jump intoctrl+o
Jump back to:%
: Jumps to the next label
The document
- Stackoverflow.com/questions/1…
- Vim.wikia.com/wiki/Single…
- Blog.csdn.net/gangyanlian…
- Releases.llvm.org/3.7.0/tools…
- www.skywind.me/blog/archiv…
The document template
Vim template plug-in segmentfault.com/a/119000000… Vim for a particular file loaded template blog.csdn.net/demorngel/a…
The status bar
The plug-in
- Vim-airline:github.com/vim-airline…
- Tagbar:github.com/majutsushi/…
- NERD tree:
Vim-airline is an alternative to Powerline and can work with Tarbar. With these two plugins installed, the status bar, outline preview and taskbar are complete.
The document
- Official documentation for Vim-Airline: github.com/vim-airline…
- Tarbar installation documentation: www.wklken.me/posts/2015/…
window
Class/method/variable related sidebar
- Operation:
- F9 open
- Plug-in:
- majutsushi/tagbar
- Documents: www.wklken.me/posts/2015/…
Above the Tab bar
- Operation:
ctrl+left
Open the file on the right of the file listctrl+right
Open the file on the left of the file listctrl+n
To open the next TABctrl+p
Open the previous TAB
C/C + + format
- Plug-in: github.com/rhysd/vim-c…
- Operation:
- F4, in normal mode, format the file code; In Visual mode, format the selected code
- Configuration file: ~/.clang-format
- Documents: github.com/rhysd/vim-c… Kxp555. Coding. Me / 2017/12/12 /… Blog.csdn.net/softimite_z…
folding
Plug-in: github.com/tmhedberg/S… Action: ZC closes fold and ZO opens fold
The indentation
Operation: < < and > >, = = command to indent the current line, visualization mode select multiple lines, use = command line indentation selected document: yyq123.blogspot.com/2010/10/vim…
Copy and paste
Vim copies to Windows
- Install x11:
yum install libX11 libX11-devel libXtst-devel libXtst libXt-devel libXt libSM-devel libSM libXpm libXpm-devel
- Vim 8
./configure --prefix=/data/luffichen/bin/vim-8.1 --with-features=huge --with-luajit --enable-luainterp=yes --enable-fail-if-missing --enable-pythoninterp=yes --with-x=yes --enable-gui=auto
- Check whether X11 is supported:
grep X11 src/auto/config.h
If you have#define HAVE_X11 1
#define HAVE_X11_XPM_H 1
#define HAVE_X11_SM_SMLIB_H 1
That is, it depends on success make -j4 && make install
vim --version | grep clipboard
Check whether it is supported.- Run Xshell and connect to the server using the SSH protocol with X11 forwarding: file – Default session attributes – tunnel -X11 forwarding select X Display
- Configure SSH,
vi /etc/ssh/sshd_config
Confirm configurationX11Forwrding yes
To allow SSH X forwarding - Install VcXsrv X11 Server, sourceforge.net/projects/vc… The clipboard function of VcXsrv does not seem to support Chinese, so VcXsrv is used.
- Open XLaunch, select Multiple Windows, and display number is 0, start no client, check Clipbord
- Operation:
- Visual mode, execute after selecting the content to copy
+y
To install Luajit:Blog.csdn.net/tao_627/art…