Build a GVim-based Python development environment on Windows 10 (2) Basic settings

Introduction

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.

Creating a GitHub repository for GVim configuration files

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.

Settings for Python files

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.

Recommended Posts

Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a GVim-based Python development environment on Windows 10 (1) Installation
Build Python environment on Windows
Build a Python development environment on your Mac
Build python environment on windows
Create a Python virtual development environment on Windows
Build a Python development environment on Raspberry Pi
Create a comfortable Python 3 (Anaconda) development environment on windows
Build a Python development environment on Mac OS X
Build a Python development environment using pyenv on MacOS
Install Python development environment on Windows 10
Build a python3 environment on CentOS7
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Build a python environment on MacOS (Catallina)
Creating a python virtual environment on Windows
Build a Python + OpenCV environment on Cloud9
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
python basic on windows ②
Build a python environment with ansible on centos6
Build a Python environment on Mac (Mountain Lion)
[Python] Build a Django development environment with Docker
Build a Kubernetes environment for development on Ubuntu
Set up a Python development environment on Marvericks
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Python + Kivy development on Windows
Django environment development on Windows 10
[ev3dev × Python] Build ev3dev development environment
Build a Python environment offline
Build a Django development environment using pyenv-virtualenv on Mac
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build a local development environment for Laravel6.X on Mac
Build a machine learning Python environment on Mac OS
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
Notes on creating a python development environment on macOS Catalina
How to build a Django (python) environment on docker
Build a Python environment on your Mac using pyenv
Build a machine learning application development environment with Python
Procedure for building a CDK environment on Windows (Python)
Create a decent shell and python environment on Windows
How to build a Python environment on amazon linux 2
Create a Python development environment on OS X Lion
Build a machine learning environment natively on Windows 10 (x64)
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Building a Python environment on Mac
Build a python machine learning study environment on macOS sierra
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Prepare Python development environment on Ubuntu
Anaconda python environment construction on Windows 10
Building a Python environment on Ubuntu
Create a Python environment on Mac (2017/4)
Build a Python development environment in Eclipse (add HTML editor)
[Python3] Development environment construction << Windows edition >>
Create a Linux environment on Windows 10
Python development environment construction on macOS
Build a python data analysis environment on Mac (El Capitan)
Create a python environment on centos
Emacs settings for Python development environment
How to build a python2.7 series development environment with Vagrant
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Until building a Python development environment using pyenv on Ubuntu 20.04