6月 222009
 

Vim Tips & Plugins などまとめ。

Windows & gvim tips

・クリップボード
    Ctrl-insert コピー
    Ctrl-delete カット
    Shift-insert ペースト
 
・vim 上のタブとして開く
    レジストリを弄る。
    /HKEY_CLASSES_ROOT/Applications/gvim.exe/shell/edit/command
    "インストール先のパス\gvim.exe" -p --remote-tab-silent "%1"
 
・Diffエラー
    http://nanasi.jp/articles/howto/diff/vimdiff_in_windows.html
 
・ファイル選択ダイアログからファイル選択
    :bro e
    :bro tabe
 
・開いてるファイルのディレクトリ
    C-x

vim tips

・文字コード変換
    :e ++enc=utf-8
    :set fenc=utf-8
    :set fenc=sjs
 
・折り畳み
    ビジュアルモードでくくって zf
    折り畳む&開く za

vim プラグインリスト

・project
    http://www.vim.org/scripts/script.php?script_id=69
 
・FavEx
    http://nanasi.jp/articles/vim/favex_vim.html
 
・The NERD tree
    http://www.vim.org/scripts/script.php?script_id=1658
 
・The NERD Commenter
    http://www.vim.org/scripts/script.php?script_id=1218
 
・bufexplorer
    http://www.vim.org/scripts/script.php?script_id=42
 
・mru
    http://www.vim.org/scripts/script.php?script_id=521
 
・eregex
    http://www.vector.co.jp/soft/unix/writing/se265654.html
 
・grep
    http://www.vim.org/scripts/script.php?script_id=311
 
・taglist
    http://www.vim.org/scripts/script.php?script_id=273
 
・neocomplcache
    http://github.com/Shougo/neocomplcache/tree/master
 
・CD
    http://nanasi.jp/articles/vim/cd_vim.html
 
・commentout
    http://nanasi.jp/articles/vim/commentout_source.html
 

入力から補完までディレイが欲しかったから neocomplcache.vim をちょっと弄ったメモ。

neocomplcache は入力中に自動で補完候補をだしてくれる凄く便利なプラグイン。

便利だなーと使ってたけど、だんだんとインサートモードで上下移動する際、補完候補をぐるぐると辿り続けるシュールな状態に耐えられなくなった。
インサートモードでカーソル移動すんなって話かもしれないけど。

こんな感じの設定とかしてみたけど、あまし変わらず。

let g:NeoComplCache_EnableSkipCompletion = 1
let g:NeoComplCache_SkipInputTime = '0.5'

なので、ソースを弄ってみた。

autoload/neocomplcache.vim

 32         " Auto complete events
 33         "autocmd CursorMovedI * call s:complete()
 34         autocmd CursorHoldI * call s:complete()
 35         set updatetime=500

入力止めて 500 ms で補完表示するようになった。

一応、だいたい期待する動作になったけど set updatetime=500 が周りに影響しそうでやめた。
他にやり方がありそうだナー。

もう少し使い込んでみつつ他のも試してみるかー。

作者さんから頂いたアドバイスを元に

neocomplcache.vim 2.6.1

"------------------------------------------------
" neocomplcache settings
let g:AutoComplPop_NotEnableAtStartup = 1
let g:NeoComplCache_EnableAtStartup = 1
let g:NeoComplCache_SmartCase = 1
let g:NeoComplCache_TagsAutoUpdate = 1
let g:NeoComplCache_EnableInfo = 1
let g:NeoComplCache_EnableCamelCaseCompletion = 1
let g:NeoComplCache_MinSyntaxLength = 3
let g:NeoComplCache_EnableSkipCompletion = 1
let g:NeoComplCache_SkipInputTime = '0.5'
inoremap <expr><Up> pumvisible() ? neocomplcache#close_popup()."\<Up>" : "\<Up>"
inoremap <expr><Down> pumvisible() ? neocomplcache#close_popup()."\<Down>" : "\<Down>"

こんな感じの設定したところシュールな状態は解消され、実に快適になった。

ありがとうございましたー!

6月 192009
 

teraterm の User Keys 設定をしたメモ。

これもまた vim で S-Right など割り当てたい為。

teraterm設定

teraterm インストールフォルダまで移動。

KEYBOARD.CNF をエディタで開く。

以下、Shift + Right, Shift + Left の設定。

[User Keys]
User1=843,0,$1b[1;2D
User2=845,0,$1b[1;2C

結構ピンポイントでメモってるサイトがなくてだいぶハマッたハマった。

参考文献

(b) Defaultで解釈するEsc文字列。

 

Mac のターミナルに Shift-Right (Left) など認識させるメモ。
vim のショートカットキーに割り当てる目的。

ターミナルの設定する

ターミナルの環境設定 → 設定 → キーボード → +を押す

キー に右矢印, 修飾キーに shift, 文字列を下記のシェルへ送信を選択。

送信文字列

\033[1;2C

\033 は ESC キーを押すと出る。それ以外は直接入力する。

mac_term_s_right

ついでに Crtl-右矢印, Ctrl-左矢印についても値を変更。

control 右矢印 \033[1;5C
control 左矢印 \033[1;5D

いやーしかしこれはハマったなー。

参考文献

(b) Defaultで解釈するEsc文字列。

6月 182009
 

普通のエディタも vim にしてこうかと思い、とりあえず MacVim を入れた。

最初から日本語使えるし、見た目キレイだし、いまのとこ文句なし!

だったのだけど、iminsert の挙動がどうも微妙。

いまは、MacVim-kaoriya 使ってる。

 

setrlimit(2), getrlimit(2) メモ。

コマンドラインから ulimit -n 1024 などとせず、プログラム上から設定するやつ。
limits.conf 以上の値を割り当てようとすると失敗するぽい。

サンプルソース

#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
 
#ifndef RLIM_INFINITY
#define RLIM_INFINITY ((unsigned int)0xffffffff)
#endif
 
int main()
{
	struct rlimit rl;
	rl.rlim_cur = 0; /* ソフトリミット */
	rl.rlim_max = 0; /* ハードリミット */
 
	/* 現在設定されている値を取得する */
	if( getrlimit( RLIMIT_NOFILE, &rl ) ){
		puts( "getrlimit error." );
		return 0;
	}
	printf( "before open_files:%d\n", rl.rlim_cur );
 
	/* 制限なし状態かチェック */
	if( rl.rlim_cur == RLIM_INFINITY ){
		printf( "infinity:%d\n", rl.rlim_cur );
	}
 
	/* 試しに新しい値をセットしてみる */
	rl.rlim_cur = 512;
	/*rl.rlim_cur = 2048;*/
	if( setrlimit( RLIMIT_NOFILE, &rl ) ){
		puts( "setrlimit error." );
		return 0;
	}
 
	/* さっき設定した値を取得する */
	rl.rlim_cur = 0;
	getrlimit( RLIMIT_NOFILE, &rl );
	printf( "after open_files:%d\n", rl.rlim_cur );
	return 0;
}

他にもスタックだったりcoreファイルサイズだったり色々変更できる。
詳しくは Manpage of GETRLIMIT で。

あんまし使わないけど知ってると便利っすなー。

6月 142009
 

すぐ忘れる脳の為に、よくやる MySQL 設定メモ。

configure オプション

./configure \
--prefix=/usr/local/mysql-5.1.35 \
--with-unix-socket-path=/usr/local/mysql-5.1.35/tmp/mysql.sock \
--with-charset=utf8 \
--with-extra-charsets=all \
--enable-thread-safe-client \
--with-plugins=ndbcluster, innobase, partition \
--with-readline \
--with-debug=full

with-readline = 日本語入力など。
with-debug = デバッグしたいときなど。

my.cnf

max_connections=300
connect_timeout=86400
interactive_timeout=86400
debug=d:t:o,/usr/local/mysql-5.1.35/tmp/mysqld.trace

max_connections = 接続受付数
connect_timeout = 接続タイムアウトまでの秒数
interactive_timeout = 接続先から何も要求がない状態タイムアウトまでの秒数
debug = デバッグトレースなど。

 

git clone を ssh 越しにやったらエラーが出たので対処メモ。

エラーまでの軌跡

サーバ作業:

$ mkdir -p repos/test/bare
$ cd repos/test/bare
$ git --bare init

クライアント作業:

$ git clone machine:/home/user/repos/test/bare/ testdir
Initialized empty Git repository in /Users/user/Documents/projects/repos/test/testdir/.git/
bash: git-upload-pack: command not found
fatal: The remote end hung up unexpectedly

git-upload-pack なんてコマンドねーよって言われた。

クライアント側のパスはどう考えても問題なさそう。
サーバ側もパスは通ってるはずなんだけどナーと調べていくと、
どうも .bash_profile ではなくて .bashrc でパス通してあげる必要があるっぽい。

.bashrc でパス通す

サーバ作業:

$ vi ~/.bashrc
PATH=$PATH:/usr/local/git/bin

Mac 固有の問題なのかなー。

 

Git インストールでエラーが出たので対処メモ。

エラーまでの軌跡

$ wget http://kernel.org/pub/software/scm/git/git-1.6.3.2.tar.gz
$ tar zxvf git-1.6.3.2.tar.gz
$ cd git-1.6.3.2
$ ./configure --prefix=/usr/local/git-1.6.3.2
$ make
GIT_VERSION = 1.6.3.2
    * new build flags or prefix
    CC fast-import.o
builtin.h:6 から include されたファイル中,
                 fast-import.c:143 から:
cache.h:16:18: error: zlib.h: そのようなファイルやディレクトリはありません
In file included from builtin.h:6,
                 from fast-import.c:143:
cache.h:21: error: expected ‘)’ before ‘strm’
cache.h:22: error: expected ‘)’ before ‘strm’
cache.h:23: error: expected ‘)’ before ‘strm’
fast-import.c:280: error: ‘Z_DEFAULT_COMPRESSION’ undeclared here (not in a function)
fast-import.c: In function ‘store_object’:
...

どうやら zlib 関連がないっぽい。

ないならインストールしましょう

$ su -
# yum -y install zlib-devel
...
Complete!
# exit

もう一度試みる

$ make
$ sudo make install

成功した。

 

内部向けDNSサーバ構築したメモ。

BIND インストール&設定する

DNSサーバー構築(BIND) を参考に。