callmekohei's blog

callmekoheiのひとりごと

5分でNeovimでF#を書く方法

f:id:callmekohei00:20170404114941p:plain

Summary

5分でNeovimF#Hello Worldしてみる〜

Environment

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12.3
BuildVersion:   16D32

Prepare

terminalを立ち上げる

Finder を立ち上げて

/Applications/Utilities/Terminal.app をダブルクリック

Homebrew をインストー

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

monoをインストー

$ brew install mono

Neovimをインストー

$ brew install neovim

Python3をインストー

$ brew install python3
$ pip3 install --upgrade pip3 setuptools
$ sudo -H pip3 install --upgrade -I neovim

Setting

Neovimの設定( init.vim をつくる )

// create nvim folder and init.vim file
$ mkdir .config/nvim
$ vim   .config/nvim/init.vim

init.vimは、たとえばこんな感じ

"----------------------------------------------------------
" Plugin manager ( Shougo/dein.vim )
"----------------------------------------------------------

let s:dein_dir = $HOME . '/.config/nvim/dein'
let s:toml     = $HOME . '/.config/nvim/dein.toml'

let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'

if !isdirectory(s:dein_repo_dir)
  execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
endif

    execute 'set runtimepath+=' . s:dein_repo_dir

if dein#load_state(s:dein_dir)
    call dein#begin(s:dein_dir)
    call dein#load_toml(s:toml, {'lazy': 0})
    call dein#end()
    call dein#save_state()
endif

if dein#check_install()
    call dein#install()
endif

filetype plugin indent on
syntax   enable


"----------------------------------------------------------
" Neovim's Python provider
"----------------------------------------------------------
let g:python_host_prog  = '/usr/local/bin/python'
let g:python3_host_prog = '/usr/local/bin/python3'

"----------------------------------------------------------
" General
"----------------------------------------------------------
" Tab
set shiftwidth=4            "vimが自動でインデントを行った際、設定する空白数
set tabstop=4               "<TAB>を含むファイルを開いた際、<TAB>を何文字の空白に変換するかを設定
set softtabstop=4           "キーボードで<TAB>を入力した際、<TAB>を何文字の空白に変換するかを設定
set expandtab               "タブ文字を空白に設定する。shofttabstopとセットで使用すると便利

" Clipbord
set clipboard+=unnamedplus  " use clipboard ( see : help clipboard )

set nowrap
set number
set noswapfile

"----------------------------------------------------------
" Seek
"----------------------------------------------------------
set wrapscan
set ignorecase
set smartcase
nnoremap <silent> <C-l> :nohlsearch<CR>

"----------------------------------------------------------
" Appearance
"----------------------------------------------------------
colorscheme birds-of-paradise

" English menu display
source $VIMRUNTIME/delmenu.vim
set    langmenu=none
source $VIMRUNTIME/menu.vim

if has("multi_lang")
    language en_gb
endif

"----------------------------------------------------------
" Char code
"----------------------------------------------------------
set encoding=utf-8
set fileencodings=utf-8,iso-2022-jp,euc-jp,sjis

"----------------------------------------------------------
" Key binding
"----------------------------------------------------------
inoremap <S-Tab> <BS>

" hjkl in insert mode
" see : https://github.com/neovim/neovim/wiki/FAQ#my-ctrl-h-mapping-doesnt-work
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>

pluginの設定 ( dein.toml をつくる )

// create dein folder and dein.toml file
$ mkdir .config/nvim/dein
$ vim   .config/nvim/dein.toml

dein.tomlは、たとえばこんな感じ

#----------------------------------------------------------
# Shougo ware
#----------------------------------------------------------

[[plugins]]
repo = 'Shougo/dein.vim'

[[plugins]]
repo = 'Shougo/denite.nvim'

[[plugins]]
repo = 'Shougo/deoplete.nvim'
hook_add = '''
    let g:deoplete#enable_at_startup = 1
    let g:deoplete#max_list = 1000
    set previewheight=5
'''

[[plugins]]
repo = 'callmekohei/deoplete-fsharp'

#----------------------------------------------------------
# Color scheme
#----------------------------------------------------------

[[plugins]]
repo = 'ronny/birds-of-paradise.vim'

[[plugins]]
repo = 'cespare/vim-toml'


#----------------------------------------------------------
# Quickrun
#----------------------------------------------------------

[[plugins]]
repo = 'thinca/vim-quickrun'
hook_add = '''
    set splitright
    let g:quickrun_config = {
    \
    \     '_' : {
    \           'hook/output_encode/enable'       : 1
    \         , 'hook/output_encode/encoding'     : 'utf-8'
    \         , 'hook/time/enable'                : 1
    \         , 'hook/time/format'                : "\n*** time : %g s ***"
    \         , 'hook/time/dest'                  : ''
    \         , "outputter/buffer/split"          : 'vertical'
    \         , 'outputter/buffer/close_on_empty' : 1
    \     }
    \     , 'fsharp': {
    \           'exec'   :  [ 'fio %s:p:r.fsx' ]
    \         , 'command':  'fio'
    \     }
    \ }

    au FileType qf nnoremap <silent><buffer>q :quit<CR>
'''

F#を実行してみる!

$ nvim abc.fsx

F#のコード

"hello" |> stdout.Write

escをおして:Quickrunと入力しリターン

// 右側に表示される
hello

感想

5分では無理か・・・ (^_^;