LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Blogs > omgiamlinux
User Name
Password

Notices



Rate this Entry

Day 2: Getting jiggy with it (VIM)

Posted 10-27-2011 at 09:38 PM by omgiamlinux
Updated 10-27-2011 at 09:40 PM by omgiamlinux

ref: http://ss64.com/vi.html



VIM CODE FOLDING http://smartic.us/2009/04/06/code-folding-in-vim/
$ vim ~/.vimrc
Code:
"folding settings
set foldmethod=indent   "fold based on indent
set foldnestmax=10      "deepest fold is 10 levels
set nofoldenable        "dont fold by default
set foldlevel=1         "this is just what i use
za - fold/unfold the entire node
zr - unfold some nested folds one layer at a time
zm - fold all at level of cursor
zM - Fold everything (minimize)
zR - Unfold everything (restore)
zo - Open fold at cursor
zO - Opens ALL folds at cursor



^ - move to first character on line


::Advanced Command List

nG Goes to the nth line in the file!

f_ Search till the next occurance of '_'
t_ Search till before next occurance of '_'

Example:
Problem - Indents are all messed up.
Code:
    it "should have the right title" do
            get 'home'
                  response.should have_selector("title",
                                                                        :content => "Ruby on Rails Tutorial Sample App | Home")
                      end
  end
Solution
1) Set cursor to where the indent should be for the "get 'home'" line.
2) dtg to set the indent proper.
3) jdtr to do the next down line.
4) f(j to setup in a good spot on the next line down
5) dt: to set that lines indet right.
etc. etc...

Wait, that's a lot of work, most IDE's do that automatically. And randomly. How can vim do that?

= - fix the indents for something. Specify a motion such as 'to the end' eg =G or 'to the start' =gg of 'fix endents for Bracketed block whilc on a bracket char' =%

:set paste - prevents some bug when you try to paste and comments go crazy



commenting:

visual block select with CTRL-V then I# (insert # in the begining)

uncommenting:

visual block select with CTRL-V then X (delete the first symbol on the line)

Please note uppercase I and X.



Show line numbers:

:set number




:: About vim

At first glance, vi appears to be a scrapy means of implimenting a text editor in a shell window.
This is not even remotely the case. Vi, or at least vim, rivals text mate in everyway.
This is possible because:
1) Vim is extensible. Anybody can write a vim plugin or syntax scheme
2) vim has millions of keystroke combos that allow you to work with out needing to move a hand to the mouse.
3) Someday Vim will work with a web cam that has eye tracking, allowing you to jump to specific words.

Vim is the future


color scheme
http://programmers.stackexchange.com...ramming-in-vim
:colorscheme evening
:colorscheme slate
:colorscheme elflord


Rails tips:
Site: http://whynotwiki.com/Editing_Ruby_code_in_vim

":w !ruby -c" - Check ruby syntax of file

Configuring vim with rails
http://oldwiki.rubyonrails.org/rails...seVimWithRails




Plugins for rails

Vid: http://www.youtube.com/watch?v=30P8DSNOZuU
rails.vim - http://www.vim.org/scripts/script.php?script_id=1567
$ wget http://www.vim.org/scripts/download_...p?src_id=13800


NERD tree - http://www.vim.org/scripts/script.php?script_id=1658
$ wget http://www.vim.org/scripts/download_...p?src_id=11834
Posted in VIM dedication
Views 342 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement

Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration