超メモ帳(Web式)@復活

小説書いたり、絵を描いたり、プログラムやったりするブログ。統失プログラマ。


SPONSORED LINK

vim + zshを設定


自宅PCのUbuntuvimが設定していなかったので自分メモ。vimの日本語環境設定とzshのインストールと設定まで。

vimの日本語設定


.vimrcに次の設定を書いて、再読み込み。

" 文字コードの自動認識
if &encoding !=# 'utf-8'
  set encoding=japan
  set fileencoding=japan
endif
if has('iconv')
  let s:enc_euc = 'euc-jp'
  let s:enc_jis = 'iso-2022-jp'
  " iconvがeucJP-msに対応しているかをチェック
  if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
    let s:enc_euc = 'eucjp-ms'
    let s:enc_jis = 'iso-2022-jp-3'
  " iconvがJISX0213に対応しているかをチェック
  elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
    let s:enc_euc = 'euc-jisx0213'
    let s:enc_jis = 'iso-2022-jp-3'
  endif
  " fileencodingsを構築
  if &encoding ==# 'utf-8'
    let s:fileencodings_default = &fileencodings
    let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
    let &fileencodings = &fileencodings .','. s:fileencodings_default
    unlet s:fileencodings_default
  else
    let &fileencodings = &fileencodings .','. s:enc_jis
    set fileencodings+=utf-8,ucs-2le,ucs-2
    if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
      set fileencodings+=cp932
      set fileencodings-=euc-jp
      set fileencodings-=euc-jisx0213
      set fileencodings-=eucjp-ms
      let &encoding = s:enc_euc
      let &fileencoding = s:enc_euc
    else
      let &fileencodings = &fileencodings .','. s:enc_euc
    endif
  endif
  " 定数を処分
  unlet s:enc_euc
  unlet s:enc_jis
endif
" 日本語を含まない場合は fileencoding に encoding を使うようにする
if has('autocmd')
  function! AU_ReCheck_FENC()
    if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0
      let &fileencoding=&encoding
    endif
  endfunction
  autocmd BufReadPost * call AU_ReCheck_FENC()
endif
" 改行コードの自動認識
set fileformats=unix,dos,mac
" □とか○の文字があってもカーソル位置がずれないようにする
if exists('&ambiwidth')
  set ambiwidth=double
endif


まるまる下記のサイトからコピペです。

ずんWiki - vim


いちおーこれで日本語が使えるようになりました。

zshのインストールと設定


まずはインストール。

$sudo apt-get install zsh


次に.zshrcファイルの設定を行っていきます。最初にzshを立ち上げると設定支援ツールが起動します。

$zsh

This is the Z Shell configuration function for new users, zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q) Quit and do nothing. The function will be run again next time.

(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.

(1) Continue to the main menu.

      • Type one of the keys in parentheses ---


[1]を選択するとメインメニューに移動。[0]を選択するとコメントだけの.zshrcを作成して終了。


メインメニューです。

Please pick one of the following options:

(1) Configure settings for history, i.e. command lines remembered
and saved by the shell. (Recommended.)

(2) Configure the new completion system. (Recommended.)

(3) Configure how keys behave when editing command lines. (Recommended.)

(4) Pick some of the more common shell options. These are simple "on"
or "off" switches controlling the shell's features.

(0) Exit, creating a blank ~/.zshrc file.

(a) Abort all settings and start from scratch. Note this will overwrite
any settings from zsh-newuser-install already in the startup file.
It will not alter any of your other settings, however.

(q) Quit and do nothing else. The function will be run again next time.

      • Type one of the keys in parentheses ---

メインメニュー。(1)ヒストリーを設定。(2)補完機能を設定する。(3)キー操作を設定する。(4)シェルオプションを設定する。(0)空の.zshrcファイルを設定して終了する。(a)設定を破棄して終了。(q)何もせずに終了する。



まずはヒストリーの設定から。1を押してヒストリー設定を表示。

History configuration
=====================

# (1) Number of lines of history kept within the shell.
HISTSIZE=1000 (not yet saved)
# (2) File where history is saved.
HISTFILE=~/.histfile (not yet saved)
# (3) Number of lines of history to save to $HISTFILE.
SAVEHIST=1000 (not yet saved)

# (0) Remember edits and return to main menu (does not save file yet)
# (q) Abandon edits and return to main menu

      • Type one of the keys in parentheses ---

(1)ヒストリーサイズを設定する。(2)ヒストリーファイル名を設定する。(3)ヒストリーの保存数を設定す>る。(0)メインメニューに戻る。(q)設定を破棄してメインメニューに戻る。



とりあえずデフォルト設定でいいので、1,2,3をそれぞれ選択してenter、0でメインメニューに戻る。

次に補完機能を設定。メインメニューで2を選択。

The new completion system (compsys) allows you to complete
commands, arguments and special shell syntax such as variables. It provides
completions for a wide range of commonly used commands in most cases simply
by typing the TAB key. Documentation is in the zshcompsys manual page.
If it is not turned on, only a few simple completions such as filenames
are available but the time to start the shell is slightly shorter.

You can:
(1) Turn on completion with the default options.

(2) Run the configuration tool (compinstall). You can also run
this from the command line with the following commands:
autoload -Uz compinstall
compinstall
if you don't want to configure completion now.

(0) Don't turn on completion.

      • Type one of the keys in parentheses ---

(1)補完機能を有効にする。(0)補完機能を無効にする。



1を選択して0でメインメニューに戻る。

次にキー操作を設定する。3を選択。

Default editing configuration
=============================

The keys in the shell's line editor can be made to behave either
like Emacs or like Vi, two common Unix editors. If you have no
experience of either, Emacs is recommended. If you don't pick one,
the shell will try to guess based on the EDITOR environment variable.
Usually it's better to pick one explicitly.

# (1) Change default editing configuration
bindkey -e (not yet saved)

# (0) Remember edits and return to main menu (does not save file yet)
# (q) Abandon edits and return to main menu

      • Type one of the keys in parentheses ---

 

デフォルトではemacsのキー設定になっている。自分はviキーバインドを使いたいので変更する。1を選択し
てキーマップを選択。

Pick a keymap (set of keys) to use when editing.
Type:
(e) for Emacs keymap (recommended unless you are vi user)
(v) for Vi keymap
(n) not to set a keymap (allow shell to choose)
(k) to keep the current setting, (e):

      • Type one of the keys in parentheses ---

(e)emacsモード。(v)viモード。(n)設定しない。(k)現在の設定を変更しない。



vを選択して、0で戻る。

ここまで設定したらメインメニューで0を設定して全体の設定を保存。



zshをログインシェルにするように設定。zshのパスを確認。

$which zsh
/usr/bin/zsh


ログインシェルを変更

$chsh
パスワード:
yuki のログインシェルを変更中
新しい値を入力してください。標準設定値を使うならリターンを押してください
ログインシェル [/bin/bash]: /usr/bin/zsh


ログインシェルが変更されたか確認

$grep yuki /etc/passwd
yuki:x:1000:1000:yuki User,,,:/home/yuki:/usr/bin/zsh


ここまで出来たらOK.


■参考文献

zsh最強シェル入門

zsh最強シェル入門

 
プライバシーポリシー免責事項