It's been a while since I wrote this article before. Still, sometimes good things fly, and with a feeling of gratitude, The vimrc has changed considerably from the time when the article was created, and I am sorry that the content is still old, so I added it. The settings of each plug-in are also described, so I hope you can refer to them. If you set it all up, it will be like this.
After joining the company, I rewrote all vim settings for neovim. ~~ If you want to build an environment now, let's do it with neovim that moves smoothly. ~~ The plug-in support status of vim8 has changed, and it works with vim8 except for deoplete. But I'm neovim because I want to use deoplete.
See past articles for installing neovim.
I wrote it for Ubuntu, but it's almost the same on mac. You should be able to go by replacing ʻapt-getwith
brew`
Zsh + neovim preferences on Ubuntu
If you want to write Python in vim, some plugins are a must. The Pragins introduced this time are as follows.
dein.vim Shougo/dein.vim
A plugin manager that assists in installing and updating plugins is essential for managing many plugins.
I used to use neobundle
, the predecessor of dein.vim
, but I changed jobs. Now that you can create config files with * .toml
, plugin dependencies and lazy load settings are much more readable than they were in the neobundle
era.
Dark Mimuou is the Vimmer I have been most indebted to. I'm not the only one who thinks so.
let s:dein_dir = expand('$CACHE/dein')
if dein#load_state(s:dein_dir)
call dein#begin(s:dein_dir)
call dein#load_toml('~/.vim/rc/dein.toml', {'lazy': 0})
call dein#load_toml('~/.vim/rc/dein_lazy.toml', {'lazy': 1})
call dein#load_toml('~/.vim/rc/dein_neo.toml', {'lazy': 1})
call dein#load_toml('~/.vim/rc/dein_python.toml', {'lazy': 1})
call dein#load_toml('~/.vim/rc/dein_go.toml', {'lazy': 1})
call dein#load_toml('~/.vim/rc/dein_frontend.toml', {'lazy': 1})
call dein#end()
call dein#save_state()
endif
Along with the bloated dein settings, the plugin settings are managed by toml.
Dein.toml
without lazy loading
Dein_lazy.toml
that is tied to multiple file types and is lazy loaded
Dein_ {filetype} .toml
for lazy loading associated with a single file type
It is said.
denite.nvim
Mainly used as a file launcher. But that's not all. denite
is an integrated platform for listing, filtering and manipulating everything.
In my case, the main thing is to display the file list in the project → narrow down → open, and ~~ Grep search for the character string in the file ~~ (Since the contents of the system grep command are output to QuickFix, I am currently using it. Not). Displaying a function list is a sub-use.
It is highly versatile because it can handle not only files but also everything. There is a lot of customization such as sort order, switching of search engine and Grep command, operation of selected target.
Not only is the main unit operating at high speed, but the flow of denite start → narrow down → open
makes it possible to jump files and lines as if it reflects your thoughts as it is. There is no doubt that the speed of editing will accelerate if you master it.
On the other hand, denite
tends to be complicated to set up. You will need to customize it for your body while reading the help. The detonation velocity will not be reached immediately after the insco.
"Prefix for Denite
nmap [denite] <Nop>
map <C-j> [denite]
"File search in the project
nmap <silent> [denite]<C-P> :<C-u>Denite file_rec -highlight-mode-insert=Search<CR>
"Search for files being expanded in the buffer
nmap <silent> [denite]<C-B> :<C-u>Denite buffer -highlight-mode-insert=Search<CR>
"Functions in the file/Search for classes, etc.
nmap <silent> [denite]<C-O> :<C-u>Denite outline -highlight-mode-insert=Search<CR>
"file under dotfiles_rec start
nmap <silent> [denite]<C-V> :<C-u>call denite#start([{'name': 'file_rec', 'args': ['~/.dotfiles']}]) -highlight-mode-insert=Search=Search<CR>
"Move up and down<C-N>, <C-P>
call denite#custom#map('normal', '<C-N>', '<denite:move_to_next_line>')
call denite#custom#map('normal', '<C-P>', '<denite:move_to_previous_line>')
call denite#custom#map('insert', '<C-N>', '<denite:move_to_next_line>')
call denite#custom#map('insert', '<C-P>', '<denite:move_to_previous_line>')
"Move input history<C-J>, <C-K>
call denite#custom#map('insert', '<C-J>', '<denite:assign_next_text>')
call denite#custom#map('insert', '<C-K>', '<denite:assign_previous_text>')
"Horizontally split open`<C-S>`
call denite#custom#map('insert', '<C-S>', '<denite:do_action:split>')
"Vertically split open`<C-I>`
call denite#custom#map('insert', '<C-I>', '<denite:do_action:vsplit>')
"Tab open`<C-O>`
call denite#custom#map('insert', '<C-O>', '<denite:do_action:tabopen>')
" file_Enable fuzzy match when searching rec and exclude specified files from the search target
call denite#custom#source(
\ 'file_rec', 'matchers', ['matcher_fuzzy', 'matcher_project_files', 'matcher_ignore_globs'])
"Specifying files that are not searched
call denite#custom#filter('matcher_ignore_globs', 'ignore_globs',
\ [ '.git/', '.ropeproject/', '__pycache__/',
\ 'venv/', 'images/', '*.min.*', 'img/', 'fonts/'])
Since denite has the highest usage rate of all plugins, it uses key bindings that can be hit as quickly as possible. As a result, I settled on <C-J> <C-*>
.
I think that moving up and down when searching for denite is completely a matter of taste.
deoplete.nvim
It is an auto-completion plugin. And again, it is the dark power of the Dark Mimuou. I mentioned the auto-completion system in my head because this plugin sets it apart from other auto-completion plugins.
For example, there is a plugin called jedi-vim
for Python auto-completion plugin, but this is a plugin that only implements Python auto-completion.
In contrast, deoplete
provides only the base of completion functionality, and each language's own completion adds completion using an external plugin source
(it seems to be called) that follows the interface of deoplete
. It will be in the form of
Python auto-completion is added with deoplete-jedi
, which will be described later.
When I write it in this way, I think that what Dark Mimuou is making is not a plug-in but an ecosystem.
Currently under construction
vim-airline
It makes you look fashionable by playing with the status bar. When asked if it would have a great impact on editing, it's not that much. However, in order to raise the tension of editing, you need something cool like "I am editing with a cool editor."
It changes colors in Normal, Insert, and Visual modes, displays the Git branch being edited, displays virtualenv in env, and displays other cursor position information. Fashionable.
"Define the display name of the mode(The default is abbreviated because it is long and squeezes the width.)
let g:airline_mode_map = {
\ '__' : '-',
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : 'V',
\ 'V' : 'V',
\ '' : 'V',
\ 's' : 'S',
\ 'S' : 'S',
\ '' : 'S',
\ }
"Cool with power line
let g:airline_powerline_fonts = 1
"Specify a color theme and look cool
let g:airline_theme = 'badwolf'
"The tab bar is cool
let g:airline#extensions#tabline#enabled = 1
"Custom selection matrix display(The default is long and squeezes the width, so minimize it)
let g:airline_section_z = airline#section#create(['windowswap', '%3p%% ', 'linenr', ':%3v'])
"Show the currently activated virtualenv to see if it recognizes the virtulenv(vim-extension of virtualenv)
let g:airline#extensions#virtualenv#enabled = 1
"Of the line changed from git HEAD+-Hide(vim-gitgutter extension)
let g:airline#extensions#hunks#enabled = 0
"Display errors and warnings from the Lint tool(ALE extension)
let g:airline#extensions#ale#enabled = 1
let g:airline#extensions#ale#error_symbol = 'E:'
let g:airline#extensions#ale#warning_symbol = 'W:'
I basically wrote it to be cool. However, since the file name becomes invisible, things that put pressure on the width are excluded as much as possible.
nerdtree
It is an explorer that is often attached to the left of the IDE.
I thought I wouldn't need a file explorer if I had denite
. Humans can't remember many things, and there are quite a few times when you want to see files in a hierarchical structure.
If you can't find the file name to type in denite
right away, opennerdtree
and you will find a list of safe files.
If you use nerdtree-git-plugin and fugitive
described later. The file edit status is displayed on nerdtree
.
Don't say, "That's Atom or VsCode, I'll take it from the beginning." My heart breaks.
vim-fugitive
Basically, I'm not a person who feels uncomfortable if I'm not in vim all the time, but I usually go back and forth between the terminal and vim with Ctrl + z, so is that necessary? I was thinking.
However, there is an overwhelming advantage over operating it in the terminal, which is the : Gdiff
and: Gblame
commands of fugitive
.
: Gdiff
is used when you think that it was better before editing.
In such a case, I am doing the operation of displaying the git diff and pulling the original code from there.
Return to terminal → Diff display → Copy → Return to vim and paste
But
Execute ": Gdiff "-> Yank-> Paste
Will be. Significant speed improvement.
As for : Gblame
, while looking at the code, you can see what happened like this on the spot with a single: Glame
and you can also refer to the log information.
And the same is true for : Gdiff
, with vim syntax highlighting applied. fast.
nmap [figitive] <Nop>
map <Leader>g [figitive]
nmap <silent> [figitive]s :<C-u>Gstatus<CR>
nmap <silent> [figitive]d :<C-u>Gdiff<CR>
nmap <silent> [figitive]b :<C-u>Gblame<CR>
nmap <silent> [figitive]l :<C-u>Glog<CR>
I don't use commands other than the above because they are operated by tig.
vim-gitgutter
Code additions, deletions, and changes from git's HEAD are displayed in the leftmost gap (gitter). I used to think it was a hindrance, but once I used it, I couldn't let go of it.
deoplete-jedi
Add Python auto-completion to the deoplete
mentioned above.
Behind the scenes, it seems to use Python's static analysis library jedi
(not related to Star Wars?) To pass the analysis results to deoplete
.
Currently under construction
vim-quickrun
You can run Python programs on vim.
My usage is to output to Buffer if there is no error in the execution result, display it to QuickFix if there is an error, and jump the code as it is.
Note that asynchronous execution cannot be supported by itself, so you need to add vimproc.vim and set it with vim-quickrun
.
In addition, there is a similar plugin that performs asynchronous execution called asyncrun with the function of vim itself instead of vimproc, but it seems that it reads around the path well. I just installed it and didn't use it because it didn't give me.
"Asynchronous execution with vimproc
"Display with buffer on success and QuickFix on failure
"Adjusting the size of the result display, etc.
let g:quickrun_config = {
\ '_' : {
\ 'runner' : 'vimproc',
\ 'runner/vimproc/updatetime' : 40,
\ 'outputter' : 'error',
\ 'outputter/error/success' : 'buffer',
\ 'outputter/error/error' : 'quickfix',
\ 'outputter/buffer/split' : ':botright 8sp',
\ }
\}
"Close the previous display contents at the time of execution&Save and then run
let g:quickrun_no_default_key_mappings = 1
nmap <Leader>r :cclose<CR>:write<CR>:QuickRun -mode n<CR>
It is convenient to add the existing execution result close and file save to the key binding. Not to mention vimproc.
~~neomake~~
Python has a syntax rule called pep8
and a static analysis command called linter to detect it automatically. neomake
executes the linter asynchronously and displays the execution result as a marker on vim.
In my case, I am running flake8
, which detects pylint
in addition to pep8
.
Originally, I used a similar plugin syntastic, but since it does not support asynchronous execution, I switched to neomake
. I did.
ALE
I've been using neomake for a while, but when working on a large project, I often see a lot of lag (a few seconds) in reflecting linter. Therefore, when I tried ALE, which I had been paying attention to for a long time, I switched to it because of its high-speed processing, sloppy appearance, abundant functions, and itching, and README was polite.
"Mark to be displayed on the error line
let g:ale_sign_error = '⨉'
let g:ale_sign_warning = '⚠'
"Message format displayed when hovering over the error line
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
"Always display error display column
let g:ale_sign_column_always = 1
"Run lint when opening a file
let g:ale_lint_on_enter = 1
"Run lint when saving file
let g:ale_lint_on_save = 1
"Don't lint editing
let g:ale_lint_on_text_changed = 'never'
"Don't show lint results in location list and QuickFix
"It's quite annoying when it's out, and it's a problem to be able to rewrite QuickFix
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0
let g:ale_open_list = 0
let g:ale_keep_list_window_open = 0
"Enable linter
let g:ale_linters = {
\ 'python': ['flake8'],
\}
"ALE prefix
nmap [ale] <Nop>
map <C-k> [ale]
"Jump to error line
nmap <silent> [ale]<C-P> <Plug>(ale_previous)
nmap <silent> [ale]<C-N> <Plug>(ale_next)
To be honest, if you look at the README, it's mostly written, but I'll post it for the time being.
vim-virtualenv
If you're developing in Python, you'll probably find yourself using virtualenv in many situations. In that case, you will need to refer to libraries etc. installed only with virtualenv on vim. This plugin is for such a situation. If you activate virtualenv and start vim, vim will start with the virtualenv library loaded.
vim-python-pep8-indent
vim's autoindent doesn't comply with pep8 conventions. If you install this plugin, it will automatically perform pep8 compliant line breaks at the time of line breaks. Convenient.
#Ordinary autoindent
format_str = format('Somehow:{}Kanya:',
a, b)
#pep8 compliant autoindent
format_str = format('Somehow:{}Kanya:',
a, b)
jedi-vim
It is a plugin that does various things using jedi. At the beginning of building the Python environment, I didn't use it because auto-completion was done with deoplete-jedi. However, when performing a tag jump with the same spelling while doing a tag jump using ctags, it was troublesome to select the target from the tag jump, so I introduced it for code reference. Therefore, most of the functions are crushed and only the code reference is left. After all it is convenient to be able to fly to the reference source with one shot. However, I feel that vim is getting heavier because of this, so I'm investigating if there is a better way.
"I will do key binding settings and auto-completion without permission, so crush it
let g:jedi#auto_initialization = 0
let g:jedi#auto_vim_configuration = 0
let g:jedi#smart_auto_mappings = 0
let g:jedi#completions_enabled = 0
"Register key bindings for code references
let g:jedi#goto_command = "<Leader>d"
gen_tags.vim
There are various auto-generated plugins for ctags, but one of them is crazy in that it supports asynchronous execution by job and gtags. If you don't know ctags, please search for various introductory articles.
let g:gen_tags#ctags_auto_gen = 1
let g:gen_tags#gtags_auto_gen = 1
Just enable autosave. Easy.
vim-test + vim-dispatch
anko-m/vim-test tpope/vim-dispatch
We have introduced a test plugin separately from QuickRun. Please refer to the following article for details. Prepare a Vim test environment quite seriously (for Python)
gtags.vim + vim-qfreplace
vim-scripts/gtags.vim thinca/vim-qfreplace
In ctags, even if the declaration source can be obtained, the reference destination cannot be obtained, so GNU global is adopted separately. Get a reference in gtags.vim and replace it with qfreplace. In short, it's a refactoring tool.
Please refer to the following article for the search by GNU global. Try vim code jump with gtags
.vimrc
~~ I really want to list the excerpted vimrc for each plugin, but I'm exhausted so I'll update it when I have time again. ~~ See below for vimrc. lighttiger2505/.dotfiles
It's been a month since I worked at ~~ vim, and now I have a much more practical environment than my hobby level, so I'd like to take this opportunity to introduce it. ~~ I've been working on vim for half a year, but it's still a long way off. I will devote myself. If you're reading this article, I'm a better vim. I'm sure there are people who say that, so I'd be happy if you could tell me.
Recommended Posts