Skip to content

Instantly share code, notes, and snippets.

@nojima
Last active August 29, 2015 14:05
Show Gist options
  • Save nojima/5019d885171892ec1f9e to your computer and use it in GitHub Desktop.
Save nojima/5019d885171892ec1f9e to your computer and use it in GitHub Desktop.

Vim の設定

Vim のビルド

apt-get で入る Vim は古いので、Linuxでのビルド方法 を参考にして最新版をビルドする。 この際に if_lua を有効にしておく。

sudo apt-get build-dep vim
sudo apt-get install lua5.2 liblua5.2-dev
hg clone https://vim.googlecode.com/hg/ vim
cd vim
./configure --with-features=huge --enable-luainterp --enable-fail-if-missing
make
sudo make install

ctags のインストール

タグジャンプのために ctags をインストールする。普通に apt-get すれば OK.

sudo apt-get install ctags

pylint をインストール

syntastic から pylint を呼び出すので事前にインストールしておく。

sudo pip install pylint

ag のインストール

sudo apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev
git clone https://github.com/ggreer/the_silver_searcher.git ag
cd ag
./build.sh
sudo make install

Vim の設定

" vim: foldmethod=marker sw=2 ts=2 expandtab
" NeoBundle {{{
set nocompatible
filetype off
filetype plugin indent off

if has('vim_starting')
  set runtimepath+=~/.vim/bundle/neobundle.vim/
  call neobundle#rc(expand('~/.vim/bundle/'))
endif
set runtimepath+=/usr/local/go/misc/vim

" Bundles
NeoBundle 'Shougo/vimproc'
NeoBundle 'Shougo/unite.vim'
NeoBundle 'tpope/vim-surround'
NeoBundle 'kana/vim-textobj-user'
NeoBundle 'kana/vim-textobj-indent'
NeoBundle 'kana/vim-textobj-line'
NeoBundle 'vim-jp/cpp-vim'
NeoBundle 'inkpot'
NeoBundle 'plasticboy/vim-markdown'
if has('lua')
  NeoBundle 'Shougo/neocomplete.vim'
endif
NeoBundle 'scrooloose/syntastic'
NeoBundle 'mbbill/undotree'

filetype plugin indent on
" }}}

" Setup {{{
function! MakeDirectories()
  let l:backup_dir = $HOME . '/.vim_backup'
  if !isdirectory(l:backup_dir)
    call mkdir(l:backup_dir)
  endif

  let l:undo_dir = $HOME . '/.vim_undo'
  if !isdirectory(l:undo_dir)
    call mkdir(l:undo_dir)
  endif
endfunction
call MakeDirectories()
" }}}

" Options {{{
syntax enable
colorscheme inkpot
set encoding=utf-8
set shiftwidth=4
set expandtab
set smarttab
set cindent
set backspace=2
set wildmenu
set formatoptions+=mM
set formatoptions-=ro
set number
set laststatus=2
set showcmd
set scrolloff=5
set nocp incsearch
set statusline=%<%f\ %h%m%r%y%=%l,%v\ %LL\ %{(&fenc!=''?&fenc:&enc).'/'.&ff}
set ignorecase
set smartcase
set backup
set backupdir=$HOME/.vim_backup
set hidden
set fileencodings=ucs-bom,utf-8,iso-2022-jp,euc-jp,cp932,utf-16,utf-16le,latin1
set fileformats=unix,dos,mac
set cinoptions=:0,p0,t0
set cinwords=if,else,while,do,for,switch,case
set hlsearch
set t_Co=256
set vb t_vb=
set list
set listchars=tab\ ,trail:-,extends:»,precedes:«,nbsp:%
set synmaxcol=300
if has("persistent_undo")
  set undodir=$HOME/.vim_undo
  set undofile
endif
" }}}

" Keymap {{{
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
nnoremap <Down> g<Down>
nnoremap <Up> g<Up>
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
vnoremap <Down> g<Down>
vnoremap <Up> g<Up>
" }}}

" Misc {{{
runtime macros/matchit.vim
" }}}

" Neocomplete {{{
if has('lua')
  let g:neocomplete#enable_at_startup = 1
  let g:neocomplete#enable_smart_case = 1
  let g:neocomplete#sources#syntax#min_keyword_length = 3
  let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'

  inoremap <expr><C-g> neocomplete#undo_completion()
  inoremap <expr><C-l> neocomplete#complete_common_string()

  inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
  function! s:my_cr_function()
    return neocomplete#close_popup() . "\<CR>"
  endfunction
  inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
  inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
  inoremap <expr><BS>  neocomplete#smart_close_popup()."\<C-h>"
endif
" }}}

" unite.vim {{{
nnoremap <Space>f :<C-u>Unite file file/new<CR>
nnoremap <Space>b :<C-u>Unite buffer<CR>
nnoremap <Space>r :<C-u>Unite file_rec/async<CR>
nnoremap <Space>g :<C-u>Unite grep:. -no-quit<CR>
let g:unite_enable_start_insert = 1
let g:unite_source_grep_command = 'ag'
let g:unite_source_grep_default_opts = '--nogroup --nocolor --column'
let g:unite_source_grep_recursive_opt = ''
" }}}

" markdown {{{
let g:vim_markdown_folding_disabled = 1
" }}}

" syntastic {{{
let g:syntastic_cpp_compiler = 'g++'
let g:syntastic_cpp_compiler_options = ' -std=gnu++11 -DCACHELINE_SIZE=64'
let g:syntastic_mode_map = { 'mode': 'active',
                           \ 'active_filetypes': ['python', 'c++', 'c'] }
" }}}

autocmd FileType python setlocal completeopt-=preview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment