noise

計算機科学や各種設定のメモ

Vimメモ

今日はエンコード用のスクリプトを操作するためのVimScriptを書いた。
VimScriptはほとんど書いたことないので苦労した。
以下、覚書。

ノーマルモードでの一連の処理をスクリプトとして行う

:execute "normal! /project_name\<CR>f\"f\"h\<C-a>"
:execute "normal! /:trim_cmd\<CR>f\"di\""

execute "〜"とするのはなどの特殊文字のため。

検索後にハイライトされたものを消す。

:noh

Vimシェルで動作するシェルをPowerShellに指定

if !has('unix')
  set shell=powershell.exe
  set shellcmdflag=-c
  set shellquote=\"
  set shellxquote=
endif

エンコード用の.projファイルを操作

function! InitProjFile()
  execute "normal! mA"
  execute "normal! /:project_name\<CR>f\"f\"h\<C-a>"
  execute "normal! /:trim_cmd\<CR>f\"di\""
  noh
  let lastlinenumber = line("$")
  let i = 0
  while i < lastlinenumber
    let l_src = getline(i)
    if match(l_src, '\v^\s*#.*$') < 0 && match(l_src, '\v^\s*(:project_name|:source_type|:width|:height|\{|\})') < 0
      "let l_dst = substitute(l_src, '\v^(.*)$', '#\1', "")
      let l_dst = "#" . l_src
      call setline(i, l_dst)
    endif
    let i += 1
  endwhile
  execute ":normal `A"
  execute ":delmarks A"
endfunction

エンコード用の.projファイルを読み込んだときにのショートカットキー拡張

autocmd BufNewFile,BufRead *.proj nnoremap <C-k> :w<CR>:silent :!Invoke-Item %<CR>
autocmd BufNewFile,BufRead *.proj nnoremap <C-i> :w<CR>:silent :!Invoke-Item %; pushd C:\〜\aviutl100; ./aviutl.exe %:p:r.avs; popd<CR>
autocmd BufNewFile,BufRead *.proj nnoremap <C-,> :call InitProjFile()<CR>

ファイルごとにビューの設定を保存・読み込みする

autocmd BufWinLeave ?* silent mkview
autocmd BufWinEnter ?* silent loadview

Undoファイル生成を抑制

set noundofile

KaoriyaのVimを使うとundoファイルというものがデフォルトで作成されるので抑制。

改行時にコメントアウト記号生成の抑制

autocmd FileType * setlocal formatoptions-=ro