[Vim] [Python] Bugs around jedi-vim and multibyte characters?

I wrote the details on my blog, but I changed the Python development environment from PyCharm to Vim.

I've been to Vimmer for a year without using external plug-ins, but I got lost and put in a plug-in (minimum).

This time I put in a famous place called jedi-vim which is very convenient as a plugin around Python, but I found a bug-like behavior so I will write it.

I googled, but I didn't see anyone with the same symptoms, so my environment may be strange. I also think there is a possibility of plug-in batting.

If you know the countermeasures, I would appreciate it if you could teach me.

environment

phenomenon

Completion does not work if Japanese (multibyte characters) is included

autocomp.gif

In the above image, the .format after"Powerman {}"is not saved.

If you put it in a variable like s =" Powerman {} ", the completion will work after s..

Variable renaming fails when Japanese (multibyte characters) is included

rename.gif

After renaming, I want it to be " Powerman {} ". Format (hoge), but it has become " Powerman {hogeformat (num) .

Impressions of introducing

The Vim mode of the IDE is also good, but I felt that being able to use Vim itself is a considerable advantage. However, I got the impression that if you do a little complicated variable renaming with the inclusion notation, it will not work, and in terms of storage function and refactoring, the code analysis of IDE (PyCharm) will be better.

I think this is a matter of taste, so I'll continue to develop it with Vim first.

.vimrc

"------- Preferences --------"
set ttyfast
set t_Co=256
set hidden
set autoread
set history=2000
set noswapfile
set backspace=start,eol,indent
set ambiwidth=double
set shortmess+=I
set nrformats=
set backup
set backupdir=$HOME/vimbackup

set smartindent
set tabstop=4
set autoindent
set expandtab
set shiftwidth=4
set showmatch
set matchtime=1
set formatoptions-=c
set smarttab
set clipboard=unnamed,autoselect

"Include hyphens in words
set isk+=-

"Exclude Japanese when checking spelling
set spelllang=en,cjk

"Release paste mode when exiting insert mode
autocmd InsertLeave * set nopaste

"syntax markdown
au BufRead,BufNewFile *.md set filetype=markdown

set encoding=utf-8
set fileencodings=ucs-bom,utf-8,euc-jp,iso-2022-jp,cp932,utf-16,utf-16le
"set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8
set fileformats=unix,dos,mac

"------- Look&Feel -----"
set ruler
set number
syntax on
filetype on
filetype plugin on
filetype indent on
set title
set showcmd
set cmdheight=2

set list
set listchars=tab:>-,trail:-,nbsp:%,extends:>,precedes:<,eol:<
set display=lastline
set pumheight=10

"colorscheme distinguished
"colorscheme railscasts
"colorscheme grb256
"colorscheme darcula
"colorscheme molokai
colorscheme badwolf
au BufNewFile,BufRead *.ejs set filetype=html


"------- Cursor -----"
"Change the cursor shape in insert mode
let &t_SI.="\e[6 q"
let &t_EI.="\e[2 q"
"Adjust the timeout time because the cursor shape does not return immediately
set ttimeoutlen=10
"Countermeasure for the phenomenon that the cursor disappears when exiting the insert mode(For some reason this cures)
inoremap <ESC> <ESC>
set mouse=a

"------- StatusLine -----"
"http://blog.ruedap.com/2011/07/12/vim-statusline-git-branch-name
"I needed a plugin, so I don't set it now. Set the following instead
"http://qiita.com/sizucca/items/40f291463a40feb4cd02
"Automatic character count
augroup WordCount
    autocmd!
    autocmd BufWinEnter,InsertLeave,CursorHold * call WordCount('char')
augroup END
let s:WordCountStr = ''
let s:WordCountDict = {'word': 2, 'char': 3, 'byte': 4}
function! WordCount(...)
    if a:0 == 0
        return s:WordCountStr
    endif
    let cidx = 3
    silent! let cidx = s:WordCountDict[a:1]
    let s:WordCountStr = ''
    let s:saved_status = v:statusmsg
    exec "silent normal! g\<c-g>"
    if v:statusmsg !~ '^--'
        let str = ''
        silent! let str = split(v:statusmsg, ';')[cidx]
        let cur = str2nr(matchstr(str, '\d\+'))
        let end = str2nr(matchstr(str, '\d\+\s*$'))
        if a:1 == 'char'
            "here(Number of line feed codes*Line feed code size)To'g<C-g>'Subtract from the number of characters in
            let cr = &ff == 'dos' ? 2 : 1
            let cur -= cr * (line('.') - 1)
            let end -= cr * line('$')
        endif
        let s:WordCountStr = printf('%d/%d', cur, end)
    endif
    let v:statusmsg = s:saved_status
    return s:WordCountStr
endfunction

"Show commands in status line
set showcmd
"Always show status line
set laststatus=2
"File number display
set statusline=[%n]
"Host name display
set statusline+=%{matchstr(hostname(),'\\w\\+')}@
"File name display
set statusline+=%<%F
"Check display of changes
set statusline+=%m
"Show if read-only
set statusline+=%r
"If it is a help page[HELP]Displayed as
set statusline+=%h
"If it is a preview window[Prevew]Displayed as
set statusline+=%w
"File format display
set statusline+=[%{&fileformat}]
"Character code display
set statusline+=[%{has('multi_byte')&&\&fileencoding!=''?&fileencoding:&encoding}]
"File type display
set statusline+=%y

"------- netrw -----"
"http://blog.tojiru.net/article/234400966.html  
"netrw is always tree view
let g:netrw_liststyle = 3
"With CVS.Do not show files starting with
let g:netrw_list_hide = 'CVS,\(^\|\s\s\)\zs\.\S\+'
" 'v'When opening a file with, open it on the right side.(The default is the left side, so replace it)
let g:netrw_altv = 1
" 'o'When opening a file with, open it at the bottom.(The default is the upper side, so replace it)
let g:netrw_alto = 1


"------- Search --------"
set incsearch
set ignorecase
set smartcase
set wrapscan
set hlsearch
":Change grep command to ack
set grepprg=ack\ --nogroup\ --column\ $*
set grepformat=%f:%l:%c:%m

"------- & command --------"
nnoremap & :&&<CR>
xnoremap & :&&<CR>


"Find the current selection
xnoremap * :<C-u>call <SID>VSetSearch()<CR>/<C-R>=@/<CR><CR>
xnoremap # :<C-u>call <SID>VSetSearch()<CR>?<C-R>=@/<CR><CR>
function! s:VSetSearch()
  let temp = @s
  norm! gv"sy
  let @/ = '\V' . substitute(escape(@s, '/\'), '\n', '\\n', 'g')
  let @s = temp
endfunction

"Set the file name included in the quickfix list in the argument list
command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
function! QuickfixFilenames()
  let buffer_numbers = {}
  for quickfix_item in getqflist()
    let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
  endfor
  return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
endfunction


"------- plugins --------"
runtime macros/matchit.vim

" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
"Text alignment with ga
Plug 'junegunn/vim-easy-align'

"Python auto-completion
Plug 'davidhalter/jedi-vim'

"Kill Ring-like guy
Plug 'LeafCage/yankround.vim'

"Expand the selection with v, C-Return selection with v
Plug 'terryma/vim-expand-region'

" C--Press twice to comment out the selection at once
Plug 'tomtom/tcomment_vim'

"Open the URL under the cursor with a browser with gx(If it is not a URL, open the search result)
Plug 'tyru/open-browser.vim'

"Various edits that surround the text
Plug 'tpope/vim-surround'

"Automatic insertion of closing parentheses
Plug 'cohama/lexima.vim'

"Indent visualization
Plug 'Yggdroot/indentLine'

"Candidate interface
Plug 'kien/ctrlp.vim'

"CtrlP extension plugin.Function search
Plug 'tacahiroy/ctrlp-funky'

"CtrlP extension plugin.Command history search
Plug 'suy/vim-ctrlp-commandline'

"CtrlP extension plugin Includes 3 features
Plug 'sgur/ctrlp-extensions.vim'

"Use ag from vim
Plug 'rking/ag.vim'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Initialize plugin system
call plug#end()


"------- plugin settings --------"
" ctrlp
" let g:ctrlp_match_window = 'order:ttb,min:20,max:20,results:100'
" .(Dot)Search for files starting with
let g:ctrlp_show_hidden = 1
"Use only file search
let g:ctrlp_types = ['fil'] 
"Extended specification of CtrlP
let g:ctrlp_extensions = ['funky', 'commandline', 'yankring'] 
"C-CtrlPMenu is now launched with p
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlPMenu'
"Enable CtrlPCommandLine
command! CtrlPCommandLine call ctrlp#init(ctrlp#commandline#id())
"Enable CtrlP Funky
let g:ctrlp_funky_matchtype = 'path' 
let g:ctrlp_cache_dir = $HOME.'/.cache/ctrlp'
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_max_files           = 100000
let g:ctrlp_mruf_max            = 500
let g:ctrlp_yankring_limit = 100
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/]\.?(git|hg|svn|cache|emacs\.d|node_modules)$',
  \ 'file': '\v\.(exe|so|dll|dmg|tar|gz|c4d|DS_Store|zip|mtl|lxo|psd|ai|eps|pdf|aep|jpe?g|png|gif|tif|swf|svg|obj|fbx|mov|mp[3-4])$',
  \ 'link': 'some_bad_symbolic_links',
  \ }

" jedi-vim
"Disable docstring pop-up
autocmd FileType python setlocal completeopt-=preview

" indentLine
"Disable with any file type
let g:indentLine_fileTypeExclude = ['help', 'markdown']

"------- Keymap -----"
inoremap <C-c> <ESC>
noremap <C-c><C-c> :nohlsearch<Cr><Esc>
set whichwrap=b,s,h,l,<,>,[,],~
let mapleader = "\<Space>"
nnoremap <Leader>s :w<CR>
nnoremap <Leader>/ /\v
nnoremap <Leader>?  ?\v
nnoremap Y y$
nnoremap + <C-a>
nnoremap - <C-x>
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
nnoremap j gj
nnoremap k gk
nnoremap gj j
nnoremap gk k
nnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l>
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
set pastetoggle=<f5>
map <f6> :!open -a textedit %<CR>
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
"Expand your selection
vmap v <Plug>(expand_region_expand)
"Return selection
vmap <C-v> <Plug>(expand_region_shrink)
"Open the URL under the cursor in your browser
let g:netrw_nogx = 1 " disable netrw's gx mapping.
nmap gx <Plug>(openbrowser-smart-search)
vmap gx <Plug>(openbrowser-smart-search)

Summary

It's been a few days since I started installing external plugins, so I can't deny the possibility that I'm doing something strange around the settings, but I'd like to find a way to fix it.

Original article

Vim: Create a Python development environment --kick the base

Recommended Posts

[Vim] [Python] Bugs around jedi-vim and multibyte characters?
Image characters and post to slack (python slackbot)
Extendable skeletons for Vim using Python, Click and Jinja2
Small and nifty Vim Plugins useful in Python / Django