» tagged pages
» logout
Vim
Return to Vim

Vim Tips

(or Cancel)

(Editing anonymously: to be credited for your changes, login or register a new account)

other page actions:

Tags Applied to this Topic

2 people have tagged this page:

Vim Tips

Wednesday, January 10, 2007

Tip #1464 - ONKYO TX-SR602B Stereo and Home Theater Surround Sound Receiver REFURBISHED

Hello! the class site. All advise to call at on<a href="www.electronicsvirtualstore.info">www.electronicsvirtualstore.info</a>, <a href="www.electronicsvirtualstore.info">here much interesting!!!</a>

Tuesday, January 09, 2007

Tip #1463 - copy multiple lines/words to a specified position

Sometimes, I often copy manlines/words from different places to a specified position, for example:
    1.  foo
    2.  bar
    3.  blah
    4.  aaaaaaaaaaaa
    5.  bbbbbbbbbbbb
    6.  ccccccccccccc
I want to copy line 1, 3, 4 under line 6:
    1.  bar
    2.  bbbbbbbbbbbb
    3.  ccccccccccccc
    4.  foo
    5.  blah
    6.  aaaaaaaaaaaa

I worked out  the following map to make it eaiser :
    :vmap gy y:call CopyToLastEditPos()<CR>

    function CopyToLastEditPos()
        let cmd = 'gi<C-O>gp'
        if visualmode()==# 'V'
            let cmd = cmd . '<C-O>k<C-E>'
        endif
        let cmd = cmd . '^[`>'
        :exec 'norm ' . cmd
    endfunction

then first, you need to enter insert mode under line 6, then return to normal mode, go and select lines seperately that need to be copied in visual mode, then type "gy", the line will be copied to under line 6.  Hope it can save your time. Thanks!

NOTE: you need to press Control-v Control-o to input <C-O>, press Control-v Control-e to input <C-E>, press Control-v Esc to input ^[

Monday, January 08, 2007

Tip #1462 - Jamie-olive.com

I always know it

Sunday, January 07, 2007

Tip #1461 - Petsdishes.com - Dishes for pets

Pamper your pooch and enhance your decor with Art Itself&#039;s beautiful hand painted designer dog dishes. We offer a variety of designs, colors and sizes to meet your needs.

Sunday, January 07, 2007

Tip #1460 - video poker tightpoker.com strategy

The whole idea behind playing selective, aggressive poker is to get yourself into a situation where you have an excellent chance of winning. When you get there, why do so many of <a href="http://www.casinosuperweb.com/gamestrip.html">game strip poker swf free</a> you suddenly decide you have to cleverly slow-play, or smooth call, or some <a href="http://www.casinosuperweb.com/casdownl.html">casino download free video poker</a> other play in which you fail to maximize the edge you so patiently waited to create? They might all fold, you say. Yes, and they might not.

Sunday, January 07, 2007

Tip #1459 - HistParl.Com - History of Parliament

The History of Parliament is a major academic project to create a scholarly reference work describing the members, constituencies and activities of the Parliament of England and the United Kingdom.

Saturday, January 06, 2007

Tip #1458 - motion on steroids


:noremap L llll
:noramap H hhhh

and maybe
:noremap J jjjj
:noremap K kkkk

Yes, old meaning of H,J,K,L has been changed. Now when you are moving around your text, press Shift to get the cursor accelerated.

Or use acceleration (repeat l,h,j,k in the mappings) to your taste. I used 10x acceleration, but than slowed it down till 4x.

Friday, January 05, 2007

Tip #1457 - Eveything Chinese Food

Chinese food, is a unique, tasty and very common cuisine which usually consists of two main ingredients.  The first being a carbohydrate source such as rice or noodles. The second component that is used in chinese food can be vegetables, fish or meat.

Friday, January 05, 2007

Tip #1456 - A set of two commands and one function to provide user-preferred options setting

Some plugins inadvertently(?) set global options. I have the following code at the top of my vimrc file and set all options to my preferred values using the SetOption command. Whenever I want to reset options I do :ResetOptions which resets all user-defined options previously set by SetOption.

let s:option_preferences = []

fun! ResetOption(options)
    if empty(a:options)
        let options = s:option_preferences
    else
        let options = a:options
    endif
    for name in options
        let name0 = 'g:'. name .'_default'
        if exists(name0)
            exec 'let &'. name .' = '. name0
        endif
    endfor
endf

command! -nargs=* ResetOption :call ResetOption([<f-args>])
command! -nargs=+ SetOption let s:tmlargs=[<f-args>]
            \ | for arg in s:tmlargs[1:-1]
                \ | if arg =~ '^[+-]\?='
                    \ | exec 'set '.s:tmlargs[0] . arg
                \ | else
                    \ | exec 'let &'.s:tmlargs[0] .'='. arg
                \ | endif
                \ | call add(s:option_preferences, s:tmlargs[0])
            \ | endfor
            \ | exec 'let g:'. s:tmlargs[0] .'_default = &'. s:tmlargs[0]
            \ | unlet s:tmlargs


Examples:
Add and remove specific options:
:SetOption cpo +=my -=M

Set the value:
:SetOption ts 4
:SetOption ts =4

Just cache the predefined value so that it can be restored later on (in this example a later reset would be the same as :set tw&):
:SetOption tw

Reset specific options:
:ResetOption ts tw

Reset all user-set options:
:ResetOption


In order to monitor the options setting, I display changed values in &statusline. (The following code is based on some tip by somebody else or a vimrc I found years ago on the web. Don't know who originally came up with this.)

set statusline=%1*[%{winnr()}:%02n]%*\ %2t\ %(%M%R%H%W%k%)\ %=%{TmlStatusline()}\ %3*<%l,%c%V,%p%%>%*

fu! TmlStatusline()
    let opt = "<". &syntax ."/". &fileformat .">"

    if !&backup     | let opt=opt." no-bak" |endif
    if !&et         | let opt=opt." no-et"  |endif
    if &list        | let opt=opt." list"   |endif
    if &paste       | let opt=opt." paste"  | endif
    if !&expandtab  | let opt=opt." tab"    | endif

    if &ts != g:ts_default | let opt=opt.' ts='.&ts    | endif
    if &sw != g:sw_default | let opt=opt.' sw='.&sw | endif
    if &tw != g:tw_default          | let opt=opt.' tw='.&tw         | endif
    if &wm != g:wm_default | let opt=opt.' wm='.&wm | endif
    if &enc != g:enc_default     | let opt=opt.' enc='.&enc       | endif
    if &ve != g:ve_default                 | let opt=opt.' ve='. &ve        | endif
    if &fo != g:fo_default                 | let opt=opt.' fo='. &fo        | endif
    if &cpo != g:cpo_default               | let opt=opt.' cpo='. &cpo      | endif
    if &bin                         | let opt=opt.' [bin]'           | endif
    if &foldlevel != s:foldlevel    | let opt=opt.' F'.&foldlevel    | endif
    
    let opt=opt." | ".strftime("%d-%b-%Y %H:%M")
    
    return opt
endf

It could have been this one by Thomas Bader:
http://www.trash.net/~thomasb/files/vim/dotvimrc.html

Thursday, January 04, 2007

Tip #1455 - Jumps to a local/global definition by same key

When you want to jump to a definition of a variable,
what do you do?
Use C-] or gd?
C-] finds only global variables (and functions. Ctags extracts
only global objects).
On the other hand, gd detects only local variables.
I think it's a bit complicated to choice them by a situation.
So I wrote this function:

function! GoDefinition()
  let pos = getpos(".")
  normal! gd
  if getpos(".") == pos
    exe "tag " . expand("<cword>")
  endif
endfunction
nnoremap <C-]> :call GoDefinition()<CR>

This function first does gd to try to find a local definition
of a variable under the cursor, and if it failed then probably
the variable is a global variable, try :tag.

This way, you can jump to the definition of both local and
global variable by same key sequence.

Monday, January 01, 2007

Tip #1454 - Shows what function the cursor is in. (for C/C++)

This is a function to show what C/C++ function/struct/class
the cursor is in.

I think this method is fast enough for practical use,
but not complete.
Any feedback is appreciated.

function! GetProtoLine()
  let ret       = ""
  let line_save = line(".")
  let col_save  = col(".")
  let top       = line_save - winline() + 1
  let so_save = &so
  let &so = 0
  let istypedef = 0
  " find closing brace
  let closing_lnum = search('^}','cW')
  if closing_lnum > 0
    if getline(line(".")) =~ '\w\s*;\s*$'
      let istypedef = 1
      let closingline = getline(".")
    endif
    " go to the opening brace
    normal! %
    " if the start position is between the two braces
    if line(".") <= line_save
      if istypedef
        let ret = matchstr(closingline, '\w\+\s*;')
      else
        " find a line contains function name
        let lnum = search('^\w','bcnW')
        if lnum > 0
          let ret = getline(lnum)
        endif
      endif
    endif
  endif
  " restore position and screen line
  exe "normal! " . top . "Gz\<CR>"
  call cursor(line_save, col_save)
  let &so = so_save
  return ret
endfunction

function! WhatFunction()
  if &ft != "c" && &ft != "cpp"
    return ""
  endif
  let proto = GetProtoLine()
  if proto == ""
    return "?"
  endif
  if stridx(proto, '(') > 0
    let ret = matchstr(proto, '\w\+(\@=')
  elseif proto =~# '\<struct\>'
    let ret = matchstr(proto, 'struct\s\+\w\+')
  elseif proto =~# '\<class\>'
    let ret = matchstr(proto, 'class\s\+\w\+')
  else
    let ret = strpart(proto, 0, 15) . "..."
  endif
  return ret
endfunction

" You may want to call WhatFunction in the statusline
set statusline=%f:%{WhatFunction()}\ %m%=\ %l-%v\ %p%%\ %02B


This function works well in the following testcase:

void draw()
{
    // When cursor is here, WhatFunction() shows "draw"
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

typedef struct {
    int ident;  // { <- braces in comments are ignored thanks to %. Great!
    int version;    // here it shows "} HEADER"
} HEADER;

# define EX(a, b, c, d)  a
enum CMD_index
#endif
{
EX(CMD_append, "append", ex_append); // here "enum CMD_index..."
};

class Sys {
public:
    load() {
        // NG: here, it shows "Sys" instead of "load"...
    }
};

class Camera : public Object
{
public:
    void init();
};

void Camera::init()
{
    // here WhatFunction shows "init"
}

Saturday, December 30, 2006

Tip #1452 - History of the USA

History Happens is a collection of music videos about characters from American history. Our goal is to inform and inspire young people that an individual can make a difference-as evidenced by the many acts of courage, endurance and passion that make up the American story.

Friday, December 29, 2006

Tip #1449 - Kodak Digital Camera Tripod

Help to choose a camcorders. What standard to choose? <a href="http://www.camcorders-online-store.info/deeppurple.html">http://www.camcorders-online-store.info/deeppurple.html</a>, <a href="http://www.camcorders-online-store.info/adventofozzie.html">Adventures of Ozzie and Harriet, Vol. 2</a>

Thursday, December 28, 2006

Tip #1448 - Yourproducerman.com - news

good work

Wednesday, December 27, 2006

Tip #1446 - Mushroomsscouncil.com - Everything about mushrooms

cool:))

Wednesday, December 27, 2006

Tip #1445 - Rtmse.com - Rats and Mice

good website

Monday, December 25, 2006

Tip #1443 - Quick switch buffers in one window

Some times we use tag-jump or some other things to jump from current buffer to another one, But when we want to go back we may found some problems. Yes, may be you can use Ctrl - o to solve this, to jump to a old position, but may be you would like to enhance this, like Visual-Studio's, which use the Ctrl-Tab to swap between two buffers. Here is the tip:

Copy this to your _vimrc
" --ex_GotoLastEditBuffer--
function! g:ex_GotoLastEditBuffer() " <<<
    " check if buffer existed and listed
    let bufnr = bufnr("#")
    if buflisted(bufnr) && bufloaded(bufnr) && bufexists(bufnr)
        silent exec bufnr."b!"
    else
    echohl WarningMsg
    echomsg a:msg
    echohl None
        
call g:ex_WarningMsg("Buffer: " .bufname(bufnr).  " can't be accessed.")
    endif
endfunction " >>>

Saturday, December 16, 2006

Tip #1442 - Olympus Camedia D-380 2MP Digital Camera

Your hard work paid off!!!visit My

Friday, December 15, 2006

Tip #1441 - Wiha 71505 T5 Torx 1/4 Dr 1 Oal Hex Insert Bit

Hi, I would like to recommend this site to everyone:
<a href="http://www.best-on-line-power-tools-store.info/plastair.html">http://www.best-on-line-power-tools-store.info/plastair.html</a>, <a href="http://www.best-on-line-power-tools-store.info/dewdw006k.html">DEWALT DW006K 24-Volt Heavy Duty 1/2&amp;quot; Drill/Hammerdrill Kitß</a>
This is the place for people who is looking for useful things.

Thursday, December 14, 2006

Tip #1440 - Let "Open in tabs" as easy as Textpad, UltraEdit, PSPad, Editplus

The 'tab pages' is a highlight feature in Vim 7. However it's not easy to use it in Windows.

See tips #1314 and #1225, I find lot of people just need the functionality as simple as the one with Textpad, UE,PSPad, Edit+.

I don't think deleting .DLL or changing Windows Registry is suitable for Vi greenhorns. Besides those solution will modify original context menu or default installation procedure.

See my solution:
***************************************************
-- Open 'Start-->Run', enter 'SendTo'
-- Click 'OK' you'll open a shortcut folder. Add a shortcut to gVim.
-- Edit 'Target' box in the property page of gVim's shortcut:"C:\Program Files\Vim\vim70\gvim.exe" -p --remote-tab-silent "%*"
***************************************************

Now select some files and click 'Send To-->gVim' in the context menu. You can open other files into new tabs in the exact same Vim instance.

Looking forwards to your comments here or by email: javacard@hotmail.com

Page 1 | Next >>
Username:
Password:
(or Cancel)