Build a GVim-based Python development environment on a Windows 10, 64-bit PC. In 1st, the environment required to operate GVim was installed. In Part 2, we will make basic settings for GVim.
In the previous article, I created a GVim config file in a locally created Git repository. However, this method was not very good when trying to use the same settings on other PCs. This time, I will create a configuration file repository on GitHub and clone it. First, delete the previously created repository C: \ Users \ daizu \ AppData \ Local \ vim74-daizu \ vimfiles
. Next, open the page of your account on GitHub and create a new vimfiles repository. Clone this repository to your PC. This time, I will put the configuration file directly under the home directory. Open a command prompt, go to C: \ Users \ daizu
, and then
$ git clone https://github.com/daizutabi/vimfiles
will do. A vimfiles
directory has been created under the home directory C: \ Users \ daizu
. Create a dotfiles
directory under this directory, and create files in it with the names _vimrc
and _gvimrc
. Then link these to your home directory. Open a command prompt with administrator privileges
$ mklink c:\Users\daizu\_vimrc c:\Users\daizu\vimfiles\dotfiles\_vimrc
$ mklink c:\Users\daizu\_gvimrc c:\Users\daizu\vimfiles\dotfiles\_gvimrc
will do.
_gvimrc
The settings for _gvimrc
are described below.
[Font] If you set a monospaced Japanese font to guifontwide
, the display will be beautiful.
python
set guifont=Consolas:h10
set guifontwide=IPAGothic:h10
[Cursor color] If you change the cursor color when IME is ON, it will be easier to identify the current input mode. At the same time, I personally like to turn off the blinking cursor.
python
highlight CursorIM guifg=NONE guibg=#00DD00
set guicursor=a:blinkon0
[Toolbar / Menu bar] Not displayed because it is an obstacle.
python
set guioptions-=T
set guioptions-=m
_vimrc
It is undergoing trial and error. Gather information on the net, such as basic Vim settings and how to use plugins using Neobundle Currently, this is the case.
Below, I would like to introduce the points that I stumbled upon.
[Quickrun]
When I output a character string including Japanese in Python, the characters are garbled, so I set it as follows. (There is also a method to set the environment variable PYTHONIOENCODING
to ʻutf-8`. However, there are various side effects, so the following measures are taken.)
_vimrc
let g:quickrun_config = {
\ '_' : {
<<<Omission>>>
\ 'hook/output_encode/enable' : 1,
\ 'hook/output_encode/encoding' : 'cp932',
\ },
\}
[Python execution environment]
Use Quickrun to execute the Python file. However, there are times when you want to run it as a normal script, and there are times when you want to run a test or Doctest. Therefore, I set g: quickrun_config
as follows.
python
let g:quickrun_config['python'] = {
\ 'command' : 'python',
\ 'outputter/buffer/filetype' : 'python_result'
\}
let g:quickrun_config['python.pytest.doctest'] = {
\ 'command' : 'py.test',
\ 'cmdopt' : '--doctest-modules',
\ 'tempfile': '$HOME/.vim/temp/__tmp__.py',
\ 'outputter/buffer/filetype' : 'doctest_result'
\}
let g:quickrun_config['python.nose.doctest'] = {
\ 'command' : 'nosetests',
\ 'cmdopt' : '--with-doctest',
\ 'tempfile': '$HOME/.vim/temp/__tmp__.py',
\ 'outputter/buffer/filetype' : 'doctest_result'
\}
let g:quickrun_config['python.pytest'] = {
\ 'command' : 'py.test',
\ 'cmdopt' : '-s -v',
\ 'tempfile' : '$HOME/.vim/temp/__tmp__.py',
\ 'outputter/buffer/filetype' : 'pytest_result'
\}
If you run Quickrun an unsaved file being edited, a temporary file with the extension .tmp
is created by default and passed to the execution command. There is no problem in normal Python execution, but nose and pytest seem to require the extension to be .py
, so ``` tempfile` is explicitly specified.
'outputter / buffer / filetype' `` is specified because the syntax color will be used later.
Under the vimfiles directory, describe the settings when creating after / ftplugin / python.vim and editing the Python file. Currently, it is as follows.
setlocal completeopt-=preview
setlocal omnifunc=jedi#completions
nnoremap <silent> <buffer> <Leader>w :<C-u>WatchdogsRun<CR>
nnoremap <silent> <buffer> <Leader>tt :<C-u>Pytest file<CR>
nnoremap <silent> <buffer> <Leader>tf :<C-u>Pytest function<CR>
nnoremap <silent> <buffer> <Leader>tc :<C-u>Pytest class<CR>
nnoremap <silent> <buffer> <Leader>tm :<C-u>Pytest method<CR>
nnoremap <silent> <buffer> <Leader>tn :<C-u>QuickRun -type python.nose.doctest<CR>
nnoremap <silent> <buffer> <Leader>td :<C-u>QuickRun -type python.pytest.doctest<CR>
nnoremap <silent> <buffer> <Leader>tp :<C-u>QuickRun -type python.pytest<CR>
nmap <buffer> ,p <Plug>(operator-autopep8)
nmap <buffer> ,pp <Plug>Autopep8Line
nmap <buffer> <F8> <Plug>Autopep8Entire
The blind spot was
python
setlocal omnifunc=jedi#completions
is. Do this in _vimrc
python
set omnifunc=jedi#completions
If you do, the default settings loaded for each file type will be overwritten the moment you open the Python file, although they are set correctly when _vimrc
is loaded. You need to specify ʻomnifunc` in after / ftplugin / python.vim to override the default settings.