continue to use vim, forget about learning emacs
Wednesday, 16. August 2006, 17:29:48
For me, I just need a simple editor, editor that does editing / coding jobs and also I can customize features that I want to use, such as do shortcut key mapping, add in plugins which I like to have. Just like firefox, just like fluxbox, lightweigth but flexible. I find emacs too complecated, I don't want to read news, mails, I just want to do some coding and scripting. I dislike the combo key of emacs. I have to press so much key to do a simple thing. Control something meta something, what the heck is meta man, alt. Again I can't find a way to get tabview working in emacs. If you know, show me how.
Therefore I stop learning up emacs. On other hand, I look into what vim can do to fulfil my needs.
Bellow are my simple needs:
1. Auto indent
2. Auto complete
3. Tabs
4. Define own shortcut key
5. Syntax with different colors
6. Plugins to enable more features that I haven't think of
Vim 7 can fulfil all my needs, maybe emacs also can, but vi is easy, available on every unix/linux/bsd. Not agree? show me with your emacs power. With a simple .vimrc in home directory, it works. I am still changing the .vimrc to makes my key map better to serve my humble needs. Bellow are my current .vimrc
" syntax color and scheme syntax enable colorscheme evening " correct the backspace set backspace=2 " indent and others plugin based on filetype filetype plugin indent on " indent setting set smarttab autoindent set tabstop=8 set expandtab set sw=4 " turn of the highlighter by default set hlsearch! " key mapping " tab navigation :map <F3> :tabprevious <cr> :map <F4> :tabnext <cr> :map <C-Tab> :tabnext <cr> :map <F2> :tabnew . <cr> " others :map <F5> : set nu! <CR> :map <F6> : set hlsearch! <CR> :map <F9> : shell <CR> " indent :map <F7> <ESC> ggv<S-g>=
First two line, I enable syntax coloring, and also use a nice scheme, black background, white text. Migrate from vim 6 to vim 7, backspace becomes not functioning the way I want it, set backspace=2 fix that. filetype plugin indent on enable all the plugin and indentation base on different file format. You can check out what is the rules and how it set up the rules to make indentation and other plugins works at
/usr/share/vim/vim70
In this folder, contains couple of sub folders such as indent, plugins, syntax etc. Take a look at them, it is all scripts for vim. You can add more plugins, find more plugins and tips at the official website (http://www.vim.org/)
Next four lines is for indentation, tabstop is when you press tab at insert mode it leaves how many blanks, sw is the blanks it leaves when you do indentation. set hlsearch! is to highlights the keyword you select. I donno why by default it is turn on, I have no idea to turn it off elsewhere by default, so I did that at here.
Tab navigation is the best part which vim opens files into tabviews and I map the key for navigate between the tabs. set nu! is to toggle the line number besides the code for better reference. Without putting ! it works to enable, with ! it allows toggle. The last line is to do indentation for the source code. When I press F7, the source code will be indented nicely.
If you understand how the key mapping works, you can easily define your own key mapping. First of all, You have to understand vim have 3 simple modes ( maybe more, but I concentrate on 3 simple one)
1. Normal
2. Visual
3. Edit
When you in normal mode, which is the default mode, you cannot insert text, but you can navigate around, search for string to match, copy , cut and paste text. When you want to edit or insert text, you can type "i" ( without quote) in normal more and it will leads you to edit mode. After that if you want to return back to normal mode, you need to press ESC. Thats it you need to know for the mode switching. Visual mode is lessly use, it is when you want to highlight strings to perform copy (yank) or indentation. To enter visual mode, you press "v" (without quote) in normal mode. When you want to exit vim and save your file, you must first come back to normal mode, press ESC and type
":x" (without quote, it is colon and character x)
Vim supports a lots of command when you are in the normal mode, one of them is to exit and save shows at above. Most of the commands start with ":", key mapping is also start with ":". You can do key mapping when your are using vim. The reason why we put all key maps into .vimrc is because you want it to run everytime you use vim. So "map" is a command, it uses to map a key to series of actions.
I map F6 to another command call hlsearch and it allows toggle with ! , CR is actually carry return, which is to execute the commands. So it becomes like this:
:map <F6> : set hlsearch! <CR>
Lets look at another example:
:map <F7> <ESC> ggv<S-g>=
I map F7 to do the list actions. They are press ESC to go back to normal mode in case it is at another mode. Then gg is to go to the first position of the opened file. v is to get in visual mode. S-g is Shift g which force the cursor to go to last line. This leads the entire file is selected, and last action =, performs the indentation.

The snapshot above is the console vim with tabviews.
By default if you open multiple files with vi, it will not open in tabs view, you need to do -p like
vim -p file1 file2 file3
Sometimes I may forget to type -p, seems I always like to open with tabviews, I can insert an alias to .bashrc
alias vi="vim -p"
Next time when I type vi with list of filename, it will automatically open in tabs.
Auto Complete:
Another best feature of vim is auto complete, type to type something halfway and press Control p. It will list down all the possible words in list. This is useful when you are searching for the functions of c/c++. Okay, I know Emacs can do that too.

There are more plugins in http://www.vim.org including tetris game
Summary:
If you are vim user, and thinking of switching to Emacs or you already switched to emacs. Its time to come back for vim. If you are nano, gedit, kate user, I have an advice for you. Vim is not as simple as the editor you use, but it is not difficult to learn up compare to emacs. Give it a try, type vimtutor in your terminal. If you are windows user, don't worry, go download gvim for windows, it works fine. If you are EMACS user, and read until this line, heh! I am glad you are still reading. Show me how EMACS can do better
Ref :
1. http://www.vim.org/
2. http://www.ukuug.org/events/linux2004/programme/paper-SMyers/Linux_2004_slides/vim_tips/
3. http://mysurface.no-ip.org/blog/?cat=15














