Translate

VIMカスタム


.vimrc



set nocompatible
set number
set title
set ruler
set tabstop=4
set shiftwidth=4
set noexpandtab
set backspace=indent,eol,start
set mouse=a

" インデント定義済みマクロ(定義済みならここで終了)
" -----------------------------------------------------
if exists("b:did_indent") | finish | endif
let b:did_indent = 1

setlocal indentexpr=GetBashIndent()
setlocal nolisp
setlocal autoindent

" 関数を一度だけ定義する(定義済みならここで終了)
" -----------------------------------------------------
if exists("*GetBashIndent") | finish | endif

" 開きインデントを許可する関数
" ----------------------------
function! s:is_li_start(pline, cline)
return a:pline =~ '\v^\s*(if|select|until|while|for|function)|\w+\s*\(\s*\)'
endfunction

" 閉じインデントを許可する関数
" ----------------------------
function! s:is_li_end(pline, cline)
return a:pline =~ '\v^\s*(done|fi|\})'
endfunction

" ブランク行かどうか
" ------------------
function! s:is_blank_line(line)
return a:line =~ '^$'
endfunction

" ブランクでない前方の行番号を探す
" --------------------------------
function! s:prevnonblank(lnum)
let i = a:lnum
while i > 1 && s:is_blank_line(getline(i))
let i -= 1
endwhile
return i
endfunction

" BASH スクリプト用インデント
" ---------------------------
function GetBashIndent()
let list_ind = 4

" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)

" At the start of the file use zero indent.
if lnum == 0 | return 0 | endif

let ind = indent(lnum) " 現在のインデント量
let pline = getline(lnum) " 直前の最終行
let cline = getline(v:lnum) " 現在行

if s:is_li_start(pline, cline)
return ind + list_ind
elseif s:is_li_end(pline, cline)
return ind - list_ind
else
return indent(v:lnum)
endif
return ind
endfunction
" -----------------------------------------------------



0 件のコメント:

コメントを投稿