LoginSignup
1
2

More than 5 years have passed since last update.

ようやくOSXでvimの基本設定をした

Posted at

OSXで、Xcodeを使うまでもない、ちょっとしたコーディングをしたいことがある。そんな時はvimだ。

とはいえ、OSXのvimの標準設定は、僕の趣味に合わない。

今まで、まあ、たまにしか使わないから、と放置していたのだが、思い立って、普段のLinux(RHEL6/7)でのvimの設定に近づけることにした。と言っても、気になる部分だけ。

まずは、Linux環境の.vimrcをコピー。

set tabstop=4
set noautoindent
autocmd FileType * set formatoptions-=ro

しかし、まだ根本的なところが違う気がする。

まず、最後にカーソルがあった行を保持してくれないのが困るな。というわけでRHELの/etc/vimrcから該当行をコピーさせていただく。

if has("autocmd")
  augroup redhat
  autocmd!
  " In text files, always limit the width of text to 78 characters
  " autocmd BufRead *.txt set tw=78
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
  " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
  autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
  " start with spec file template
  autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
  augroup END
endif

えーと、それから、色をつけるのは、

syntax on

OK。これでバッチリ。

$ cat -n ~/.vimrc 
     1  set tabstop=4
     2  set noautoindent
     3  autocmd FileType * set formatoptions-=ro
     4  
     5  " Only do this part when compiled with support for autocommands
     6  if has("autocmd")
     7    augroup redhat
     8    autocmd!
     9    " In text files, always limit the width of text to 78 characters
    10    " autocmd BufRead *.txt set tw=78
    11    " When editing a file, always jump to the last cursor position
    12    autocmd BufReadPost *
    13    \ if line("'\"") > 0 && line ("'\"") <= line("$") |
    14    \   exe "normal! g'\"" |
    15    \ endif
    16    " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
    17    autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
    18    " start with spec file template
    19    autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
    20    augroup END
    21  endif
    22  
    23  syntax on
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2