2012年2月
« 1月    
 12345
6789101112
13141516171819
20212223242526
272829  

カテゴリー

vimでmessagesをクリップボードにコピーするkey mapping

" messagesをクリップボードに
map <C-r>m :redir @*:silent messages:redir END

ref.
http://vim-users.jp/2011/06/hack220/

python doctestで日本語を使うときはprintを使うと化けない

pythonのdoctestが凄くいい。
コメントに書くと、テストが簡単に実行できる。

ただ、以下のテストを実行してみるとわかるのですが、
日本語の扱いに難有り。テスト結果としての文字列をu’\u308f’みたいに書かないといけない。
環境はpythonは2.7.1、windows7です。

# encoding: utf-8    
def doctestJapan(no):
    """
    >>> doctestJapan(0)
    u'tiro finale'
    >>> doctestJapan(1)
    こんなの絶対おかしいよ
    >>> doctestJapan(2) # わけがわからないよ
    u'\u308f\u3051\u304c\u308f\u304b\u3089\u306a\u3044\u3088'
    >>> doctestJapan(3)
    u'わけがわからないよ'
    """
    if no == 0:
        return u'tiro finale'
    elif no == 1:
        print u'こんなの絶対おかしいよ'
    elif no == 2:
        return u'わけがわからないよ'
 
if __name__ == "__main__":
    import doctest
    doctest.testmod()

こんな実行結果

**********************************************************************
File "C:\Users\xxxxxx\.vim_junk\2012\2012-02-08-071611.py", line 10, in __main__.doctestJapan
Failed example:
    doctestJapan(2)
Expected:
    u'わけがわからないよ'
Got:
    u'\u308f\u3051\u304c\u308f\u304b\u3089\u306a\u3044\u3088'
**********************************************************************
1 items had failures:
   1 of   4 in __main__.doctestJapan
***Test Failed*** 1 failures.

上記を見ると、ふつうにu’わけがわからないよ’と書いた部分はテストが通っていない。
ただ、「こんなの絶対おかしいよ」の部分は文字列をprintした結果でテストしているので、
うまくいっている。

結論:doctestで日本語を使うときは、printを指定して望みどおりに表示されているかを確認すると吉。

qfixhowmで外部ブラウザとしてChromeを指定する

windows7環境で、Chromeを指定する方法。

" 外部ブラウザ
let QFixHowm_OpenURIcmd        = '!start ' . $HOMEPATH . '\AppData\Local\Google\Chrome\Application\chrome.exe %s --disk-cache-dir="R:\Temp\Chrome"'

環境変数$HOMEPATHが設定されていない場合は、適宜読み替えて設定する。
–disk-cache-dirは個人的な設定(RAMDISKにキャッシュを置いている)なので、なくてもOK。
その前の%sはurlを渡しているところなので必須。

qfixhowmでg,dした時のカーソル位置が]の左ではなく右側にあって欲しい

vimテクニックバイブルで紹介されていたqfixhowmというプラグインを使い始めています。

メモの記録や、TODO管理などで便利すぎてたまりません。
もう少し使い込んだら自分の使い方のをまとめようと思いますが、
まずは細かな設定のメモ。

qfixhowmでg,dした時のカーソル位置が]の左ではなく右側にあって欲しい

通常のマッピング

    n  g,d          * :<C-U>call qfixmemo#InsertDate('Date')<CR>

右を動かすように上書き

    nmap g,d :<C-U>call qfixmemo#InsertDate('Date')<CR><Right>
    nmap g,T :<C-U>call qfixmemo#InsertDate('Time')<CR><Right>

自分はLeaderにfをマッピングしているので、実際にはfd,fTのコマンドとして利用しています。

Vimテクニックバイブル ~作業効率をカイゼンする150の技
Vimサポーターズ
技術評論社
売り上げランキング: 12628

vimprocを使えるようにするメモ (windows7 64bit)

下準備。
vundleでvimprocのインストール
vundleでvimshellのインストール

ココからが難しいとこ

Mingw-toolsのインストール(makeのインストール)

http://jaist.dl.sourceforge.net/project/mingw/Installer/mingw-get-inst/mingw-get-inst-20111118/mingw-get-inst-20111118.exe

インストールディレクトリをMinGW-toolsに指定、コンパイラはインストールせずにMSYS Basic Systemだけインストール。コンパイラは次にダウンロードする64bit版を使うので。

C:\MinGW-tools\msys\1.0\bin pathに追加

Mingw-64bitのインストール

http://jaist.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-bin_i686-mingw_20111220.zip

解凍したファイルを移動して、C:\mingw-w64\ に名前変更

C:\mingw-w64\bin pathに追加

C:\mingw-w64\bin\x86_64-w64-mingw32-gcc.exe を gcc.exeに名前変更

※上記のMingw-tools、及びMingw-64bitは以下を参考に最新をダウンロードするといい。
http://umeji.blogspot.com/2011/10/mingwwindows64bitvimprocdll.html

コマンドプロンプトを起動して、こんな感じで出る

c:\>make -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
 
This program built for i686-pc-msys
 
c:\>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw-w64/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.0/lto
-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../build/gcc/src/configure --target=x86_64-w64-mingw32 --
prefix=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --with-sysroot=/c
/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --enable-languages=all,obj
-c++ --enable-fully-dynamic-string --disable-multilib
Thread model: win32
gcc version 4.7.0 20111220 (experimental) (GCC)

vimprocのコンパイル

c:\>cd c:\Users\xxxxxx\.vim\bundle\vimproc
 
c:\Users\xxxxxx\.vim\bundle\vimproc>make -f make_mingw.mak
gcc -O2 -Wall -shared -o autoload/proc.dll autoload/proc_w32.c -lwsock32
autoload/proc_w32.c:31:0: warning: "WINVER" redefined [enabled by default]
In file included from c:\mingw-w64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.0/../..
/../../x86_64-w64-mingw32/include/stdio.h:9:0,
                 from autoload/proc_w32.c:22:
c:\mingw-w64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-ming
w32/include/_mingw.h:240:0: note: this is the location of the previous definitio
n
autoload/proc_w32.c:32:0: warning: "_WIN32_WINNT" redefined [enabled by default]
 
In file included from c:\mingw-w64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.0/../..
/../../x86_64-w64-mingw32/include/stdio.h:9:0,
                 from autoload/proc_w32.c:22:
c:\mingw-w64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-ming
w32/include/_mingw.h:244:0: note: this is the location of the previous definitio
n
autoload/proc_w32.c: In function 'vp_pipe_open':
autoload/proc_w32.c:499:33: warning: cast from pointer to integer of different s
ize [-Wpointer-to-int-cast]
autoload/proc_w32.c:501:33: warning: cast from pointer to integer of different s
ize [-Wpointer-to-int-cast]
autoload/proc_w32.c:504:37: warning: cast from pointer to integer of different s
ize [-Wpointer-to-int-cast]
autoload/proc_w32.c: In function 'ExitRemoteProcess':
autoload/proc_w32.c:648:33: warning: cast to pointer from integer of different s
ize [-Wint-to-pointer-cast]
autoload/proc_w32.c: In function 'vp_open':
autoload/proc_w32.c:949:9: warning: cast from pointer to integer of different si
ze [-Wpointer-to-int-cast]
In file included from autoload/proc_w32.c:44:0:
autoload/proc_w32.c: At top level:
autoload/vimstack.c:42:19: warning: 'vp_stack_null' defined but not used [-Wunus
ed-variable]

動作確認

vimを再起動して、:VimShellを起動、lsを表示してエラーが出なければOK