Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away