VIM - HVboom/HowTo-DigitalOcean GitHub Wiki

Description

Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems.

Vim is often called a "programmer's editor," and so useful for programming that many consider it an entire IDE. It's not just for programmers, though. Vim is perfect for all kinds of text editing, from composing email to editing configuration files.

Despite what the above comic suggests, Vim can be configured to work in a very simple (Notepad-like) way, called evim or Easy Vim.

💬 copied from the package description

Setup VIM

sudo pkg install vim

VIM default resource file

  • Create a global vi resource file /usr/local/share/bash/.vimrc:

    set autoindent
    set expandtab
    set tabstop=2
    set softtabstop=2
    set shiftwidth=2
    set backspace=indent
    
    set showmode
    set showmatch
    set hlsearch    " highlight search
    set incsearch   " Incremental search, search as you type
    set ignorecase  " Ignore case when searching
    set smartcase   " Ignore case when searching lowercase
    set number
    " set mouse=a
    set showcmd
    set guioptions+=T
    set gtl=%t
    set gtt=%F
    
    filetype plugin indent on
    syntax on
    
    set title
    
    map ,wx  :'a,.w! $HOME/tmp/XXX<CR>
    map ,wy  :'a,.w! $HOME/tmp/YYY<CR>
    map ,wz  :'a,.w! $HOME/tmp/ZZZ<CR>
    map ,rx  :r $HOME/tmp/XXX<CR>
    map ,ry  :r $HOME/tmp/YYY<CR>
    map ,rz  :r $HOME/tmp/ZZZ<CR>
    
    map ,dos :%s/\r//<CR>
    map ,d   :set fileformat=dos<CR>:w<CR>
    map ,u   :set fileformat=unix<CR>:w<CR>
    
    " trim on save
    function! TrimWhiteSpace()
        %s/\s\+$//e
    endfunction
  • This script is automatically copied to the user directory, if it does not exists (see /usr/local/share/bash/profile)

    ...
    # copy default VIM options
    if [ ! -e "$HOME/.vimrc" ]
    then
      cp "$globalSettings/.vimrc" "$HOME"
    fi
    ...
  • The editor is automatically used as a substitution von VI (see /usr/local/share/bash/.alias)

    ...
    # use VIM, if installed
    if [ -x `which vim` ]
    then
      alias vi='vim'
      alias view='vim -R'
    fi
    ...
  • You can edit the copied version, e.g. to trim trailing spaces of ruby files on save

    ...
    autocmd BufWritePre *.rb :call TrimWhiteSpace()
⚠️ **GitHub.com Fallback** ⚠️