nedeľa 12. februára 2012

Vim install and configuration

You may have noticed we are editing/viewing files more and more. For these purposes I use "vim" editor. 
After minimal install, you can try to type "vi" in CLI. You will see kind of light,skimmed version of real "vim". We can make our work much more efficient with real "vim".

cd /usr/ports/editors/vim-lite - I use light version
make install clean
rehash

Now you can try to run vim with "vim" command. Notice you still have "vi" and "vim" command. I used to use old "vi" command, so we need to associate "vi" command with "vim" editor. One way how to do that is via alias. Put this in ".tcshrc":
alias vi /usr/local/bin/vim
setenv EDITOR vim - not necessary but why not

Log out and log in back and "vi" command should run "vim" editor.

That's nice, we have "vim" but to utilize vim's features for which we've installed "vim", we need to create config file with some parameters.
cd - go to home dir.
vi .vimrc - if ".vimrc" doesn't exist, vim will create new file
Put these lines into it:
set nocompatible - to stop vim acting weird
set number - show numbered lines
syntax on - distinguish syntax (very useful)
set backspace=start,eol,indent - make backspace work normally
set ignorecase - no case sensitve search
set incsearch - search on fly
set hlsearch - highlighted search
hi linenr ctermfg=darkgrey - color of line numbers
hi search ctermfg=red ctermbg=yellow - color of searched items

Now, after saving ".vimrc" and restarting "vim", all above should work. Essential controls in "vim":
a - insert mode (you can start typing)
i - replace mode (you can start typing)
/[string] - search in text
:w - save file, but not quit
:wq - save file with quit
:q! - force quit

It takes a while to get used to use "vim" but it's worth.

Žiadne komentáre:

Zverejnenie komentára