mieki256's diary



2016/08/07() [n年前の日記]

#2 [ubuntu][raspberrypi] Vimを設定

Vimを設定して、少しでもPythonを書きやすい状態にしたい。

Ubuntu 16.04 LTS上でVimをインストール。 :

sudo aptitude install vim

NeoBundleをインストール。 :

_NeoBundle とやらをインストールすると、Vimのプラグイン管理が楽になるという話を見かけた。開発停止と書かれているのが気になるけど…。一応入れてみる。

インストールするためには git が必要。
sudo aptitude install git

github からインストール用のスクリプトファイルをダウンロードして実行。
curl https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh > install.sh
sh ./install.sh

インストールすると、「 ~/.vimrc に以下を書け」とメッセージが表示されるので、指示に従って ~/.vimrc に記述。

ちと注意。以下にメモした記述は、パスが自分の環境用に変更されてる版なので、他の環境でそのままコピペして使わないこと。あくまでインストール時に表示されたものをコピペして ~/.vimrc に書く。
"NeoBundle Scripts-----------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath^=/home/mieki256/.vim/bundle/neobundle.vim/

" Required:
call neobundle#begin(expand('/home/mieki256/.vim/bundle'))

" Let NeoBundle manage NeoBundle
" Required:
NeoBundleFetch 'Shougo/neobundle.vim'

" Add or remove your Bundles here:
NeoBundle 'Shougo/neosnippet.vim'
NeoBundle 'Shougo/neosnippet-snippets'
NeoBundle 'tpope/vim-fugitive'
NeoBundle 'ctrlpvim/ctrlp.vim'
NeoBundle 'flazz/vim-colorschemes'

" You can specify revision/branch/tag.
NeoBundle 'Shougo/vimshell', { 'rev' : '3787e5' }

" Required:
call neobundle#end()

" Required:
filetype plugin indent on

" If there are uninstalled bundles found on startup,
" this will conveniently prompt you to install them.
NeoBundleCheck
"End NeoBundle Scripts-------------------------

この状態でVimを起動すると、~/.vimrc 内で記述されたプラグインが自動でインストールされる。

起動画面が出た直後から裏でこっそりインストール処理が進むようで、その間は何の操作もできなくなってちょっと焦るけど、我慢して待つ。そのうち操作できるようになる。

そういえば、~/.cache 以下のどこかのフォルダが root で作られてしまって、中にファイルを書き込めない状態になってエラーが出てたような気がする。該当フォルダを、sudo chown 自分:自分のグループ ~/.cache/hoge/fuga して所有者を変更してどうにか。

NeoBundleを使ったプラグインのインストール方法。 :

~/.vimrc 内の、call neobundle#begin と call neobundle#end の間に NeoBundle hoge/fuga 等を記述してvimを起動すると、自動でインストールされるらしい。

luaが有効になったVimをインストールしたい。 :

補完用のプラグインとして _NeoComplete とやらが有名らしいので使ってみたいけど、使うためには lua が有効になった Vim が必要らしい。

ところが、Ubuntu 16.04上で、sudo aptitude install vim でインストールした Vim は lua が無効になっていて。
$ vim --version | grep lua
+dialog_con      -lua             +rightleft       +writebackup
「-lua」と表示されてるから、無効状態。困った。

_ ubuntuで簡易的にvimにluaを入れる - Qiita によると、vim-gnome をインストールすれば、luaが有効になった版が入ってくれるらしい。
$ sudo aptitude install vim-gnome
$ vim --version | grep lua
+dialog_con_gui  +lua             +rightleft       +writebackup
リンク: gcc   -L. -Wl,-Bsymbolic-functions (以下略)
ホントだ。luaが有効になってる版が入ったっぽい。とりあえずこれで様子見してみる。

Python用に設定。 :

以下を参考にして設定。

_Python用Vimの設定
_Pythonを快適に編集できるようvimを設定する - 玉虫色に染まれ!
_NeoBundleを用いたVimプラグイン管理と色設定メモ - Qiita
_vimにNeoBundleとNeoCompleteを入れる - KayaMemo
_Shougo/neobundle.vim: Next generation Vim package manager

結果的に、以下のような ~/.vimrc になった。
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath^=/home/mieki256/.vim/bundle/neobundle.vim/

" Required:
call neobundle#begin(expand('/home/mieki256/.vim/bundle'))

" Let NeoBundle manage NeoBundle
" Required:
NeoBundleFetch 'Shougo/neobundle.vim'

" Add or remove your Bundles here:
NeoBundle 'Shougo/neosnippet.vim'
NeoBundle 'Shougo/neosnippet-snippets'
NeoBundle 'tpope/vim-fugitive'
NeoBundle 'ctrlpvim/ctrlp.vim'
NeoBundle 'flazz/vim-colorschemes'
NeoBundle 'Shougo/neocomplete.vim'

" You can specify revision/branch/tag.
NeoBundle 'Shougo/vimshell', { 'rev' : '3787e5' }
"
" Required:
call neobundle#end()

" Required:
filetype plugin indent on

" If there are uninstalled bundles found on startup,
" this will conveniently prompt you to install them.
NeoBundleCheck

filetype plugin on
autocmd FileType python setl autoindent
autocmd FileType python setl smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd FileType python setl tabstop=8 expandtab shiftwidth=4 softtabstop=4
set ignorecase
set smartcase
set incsearch
set hlsearch

set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8,cp932

"Note: This option must be set in .vimrc(_vimrc).  NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 2
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'

" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
    \ 'default' : '',
    \ 'vimshell' : $HOME.'/.vimshell_hist',
    \ 'scheme' : $HOME.'/.gosh_completions'
        \ }

" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
    let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'

" Plugin key-mappings.
inoremap <expr><C-g>     neocomplete#undo_completion()
inoremap <expr><C-l>     neocomplete#complete_common_string()

" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
  return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
  " For no inserting <CR> key.
  "return pumvisible() ? "\<C-y>" : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"

" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1

" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap <expr><TAB>  pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"

" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags

" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
  let g:neocomplete#sources#omni#input_patterns = {}
endif
"let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'

" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'

長過ぎる。コレ、別ファイルに分割できないのでしょうか?

さておき。本当は jedi-vim なるプラグインを入れると Python用としてグッドな感じになるらしい。が、そこまでやってない。

どうやらそもそも開発停止になった NeoBundle とやらを使うより、後継っぽい dein とやらを使ってプラグイン管理したほうがいいらしいのだけど…。移行するための解説記事を眺めてみたら設定内容がたくさんあって「ギャーッ!」って感じで…。最初から設定し直したほうがいいのかなコレ。

ちなみに、ここまでは Raspberry Pi3 上でも同様に設定できました。とメモ。

それにしても、昔どこかで見かけた「アイツら一生vimの設定弄ってるぞ」的なdisがなんだかシャレになってないなと言う気分になってきたりもして。あるいは _「奥が深い症候群」 を思い出す。管理が簡単になるはずのプラグインを入れても、コレか…。Vimは、奥が深い。

以上です。

過去ログ表示

Prev - 2016/08 - Next
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

カテゴリで表示

検索機能は Namazu for hns で提供されています。(詳細指定/ヘルプ


注意: 現在使用の日記自動生成システムは Version 2.19.6 です。
公開されている日記自動生成システムは Version 2.19.5 です。

Powered by hns-2.19.6, HyperNikkiSystem Project