Tuesday, July 27, 2010

vim stuff

Try these examples:

  • Enter :help to browse help. Scroll down the help page to see the quickref and tutor links, and the table of contents.
  • Enter :help pattern for help on the topic pattern (for example).
  • :h pattern is the same (the :help command can be abbreviated).

Command completion can be used when entering a help topic:

  • Type :h patt then press Ctrl-D to list all topics that contain "patt".
  • Type :h patt then press Tab to scroll through the topics that start with "patt".
  • If you have set the 'wildmenu' option (e.g. by using :set wildmenu), then :h patt followed by opens a menu on the statusline, with all help topics containing "patt". You can select any item in the menu with the arrow keys or more presses of the key to fill in the rest of your command line.

Links:

  • Enter :h to open the main help page.
  • Type /quick to search for "quick" (should find the quickref link).
  • Press Ctrl-] to follow the link (jump to the quickref topic).
  • After browsing the quickref topic, press Ctrl-T to go back to the previous topic.
  • You can also press Ctrl-O to jump to older locations, or Ctrl-I to jump to newer locations.

Searching:

  • Search within a help file using / like you would when searching any file.
  • Search all the help files with the :helpgrep command, for example:
:helpgrep \csearch.\{,12}file
\c means the pattern is case insensitive.
The pattern finds "search" then up to 12 characters followed by "file".
You will then see the first match. To see other matches for the same pattern, use:
:cnext
:cprev
:cnfile
:cpfile
:cfirst
:clast
and even
:cc
which brings you back to the current match after you scrolled the helpfile, or
:copen
which will list out all the matches in a separate window. Read up on these commands with the :help entry for each of them!

Each week (or more often if you prefer), read a new section from the :help page to learn something new!

7 comments:

  1. #delete spesific line non interactively
    for i in ls /home/fish/public_html/*xml; do vim -c "argdo 9,15d" -c "xall" $i; done

    ReplyDelete
  2. script type
    utility

    description
    Whenever you start Vim (but no more than daily) the script will open a
    help window with a Vim tip. You must download the tips separately, from
    http://vim.sourceforge.net/tips/tip_download.php

    After installation, you can get the next tip with

    :TipOfTheDay

    (usual abbreviation rules apply) or go to the top of the tips file with

    :help vimtips.txt

    install details
    1. Unpack totd.zip into a directory in your |runtimepath|. For most users,
    this typically means ~/.vim or $HOME/vimfiles or $VIM/vimfiles . This will
    create files
    plugin/totd.vim (the plugin)
    doc/totd.txt (the docs)
    plugin/vimtips/vimtips.txt (skeleton tips file)

    2a. The easiest thing may be to restart vim, either right now or whenever you
    get around to it. Then totd.vim will automatically run |:helptags|, edit the
    tags file, and open the skeleton vimtips file.

    2b. If you want to finish the installation right now, without restarting vim,
    simply source the totd.vim file and get a tip:

    :source path/to/totd.vim
    :TipOfTheDay

    3. The totd.vim plugin will open the skeleton vimtips file in a help window.
    Follow the URL there to download a real vimtips file.

    4. As with any plugin that comes with documentation, you should run

    :helptags path/to/doc

    so that you can read the documentation with

    :help totd
    :help Tip

    ReplyDelete
  3. vim Tips
    Arguments

    vim xxx yyy zzz – open one or more files
    (-R: open as read-only; +n: skip to line n; +/xxx: skip to string xxx;)
    Modes

    esc – goto command mode
    i – goto insert mode
    Colon Commands

    :w – save
    :w myfile – save as myfile
    :q – quit
    :r myfile – paste myfile at the cursor of the current file
    :e myfile – edit myfile, close current file
    :f – show file properties
    :n – open next vi file in arguments list
    :!xxx – run xxx in the shell
    :!!xxx – replace current line with result of shell command xxx
    :!}xxx – replace current paragraph with the result shell command xxx
    :map – show key mappings
    :map key cmd – map vi cmd to key
    :. – show line numbers
    :set nonumber – turn off line numbering
    :s/old/new/ – search and replace
    :%s/search/&/g – search and count matches
    :1,$ s/old/new/g – global replace
    :g/^$/d – delete all blank lines
    :/xxx – search down for xxx
    :?xxx – search up for xxx
    n – repeat last search(find next)
    Control Commands

    Ctrl-b – page up
    Ctrl-f – page down
    Ctrl-u – half page up
    Ctrl-d – half page down
    Editing

    a – append after cursor
    A – append after current line
    i – insert before cursor
    r – replace at cursor
    ~ – transpose case of text at cursor
    R – replace from cursor to end of new text
    o – open newline after cursor
    O – open newline before cursor
    u – undo last action
    Ctrl+R – redo last action
    U – undo current line
    yy – copy current line
    yn – copy n lines from current line
    y/string/ copy from the cursor positon to the string’s position, searching forward
    y?string? copy from the string’s position to the cursor, searchingbackward
    p – paste
    ddp – cut and paste current line
    dd – delete current line
    dw – delete current word
    d$ – delete from cursor to end of line
    D – delete from cursor to end of line
    cc – change current line
    cw – change current word
    c$ – change from cursor to end of line
    C – change current line
    Cursor Movement

    h/j/k/l – move up/down/left/right
    w – move forward word-by-word
    b – move backward word-by-word
    W – same as w but only uses space as delimiter
    B – same as b but only uses space as delimiter
    e – move to end of current word
    } – move forward one paragraph
    { – move backward one paragraph
    ) – move forward one line
    ( – move backward one line
    ^ – first non-blank character
    0 – start of current line
    $ – end of current line
    1G – top of the file
    G – bottom of the file
    % – find match of current brace in the cursor
    References

    vi Manual
    vi Reference Card
    vi Tutorial: Copying, Cutting, and Pasting
    vi Long Reference
    vi Editor Guide
    Vim Tips Wiki
    vi/vim Notes
    Using the vi Editor
    vim scripts and plugins
    Best vim Tips Roundup
    The New and Improved Vim Editor
    Simulating Arrays with Vim

    http://vim.wikia.com/wiki/VimTip1220
    http://www.oreillynet.com/onlamp/blog/2006/08/make_your_vimrc_trivial_to_upd_1.html
    http://hea-www.harvard.edu/~fine/Tech/vi.html
    http://www.dc.turkuamk.fi/docs/soft/vim/vim_ref9.html
    http://vim.wikia.com/wiki/Numbering_lines_and_interpolating_sequences
    http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell
    http://www.washington.edu/computing/unix/viqr.html
    http://www.ungerhu.com/jxh/vi.html

    http://code.google.com/p/mrxvt/wiki/FaqKeys
    http://vim.dindinx.net/vim7/html/term.txt.php
    http://vimdoc.sourceforge.net/htmldoc/term.html
    http://polarhome.com/vim/manual/v72/term.html
    http://www.macfreek.nl/mindmaster/Backspace_and_Delete_key_reversed
    http://wkweb3.cableinet.co.uk/linux/LDP/HOWTO/Text-Terminal-HOWTO-16.html
    http://www.softpanorama.org/Utilities/screen.shtml
    http://vimdoc.sourceforge.net/htmldoc/map.html
    http://www.geocities.com/yegappan/vim_keymap.html
    http://linux.about.com/od/ttl_howto/a/hwtttl17t04.htm
    http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_2)

    ReplyDelete
  4. credit to:
    http://sweatte.wordpress.com/syntax/vim-tips/

    Control Commands

    Ctrl-b – page up
    Ctrl-f – page down
    Ctrl-u – half page up
    Ctrl-d – half page down

    Cursor Movement

    h/j/k/l – move up/down/left/right
    w – move forward word-by-word
    b – move backward word-by-word
    W – same as w but only uses space as delimiter
    B – same as b but only uses space as delimiter
    e – move to end of current word
    } – move forward one paragraph
    { – move backward one paragraph
    ) – move forward one line
    ( – move backward one line
    ^ – first non-blank character
    0 – start of current line
    $ – end of current line
    1G – top of the file
    G – bottom of the file
    % – find match of current brace in the cursor

    ReplyDelete
  5. apt-get install ctags
    ctags -R *
    ctags -R .
    cat tags
    vim *.c
    :TlistOpen

    ## vim for c coder
    ~/.vimrc
    set cindent
    set tabstop=4
    set shiftwidth=4
    set expandtab
    filetype plugin on

    ReplyDelete
  6. ## http://vim.wikia.com/wiki/Indenting_source_code

    [15:06] is "cindent == set tabstop=8" ???
    [15:06] == Vampire [~Vampire@unaffiliated/vampire] has left #vim []
    [15:06] fishcooker: no.
    [15:06] cindent is cindent.
    [15:06] tabstop is tabstop :)
    [15:07] cindent honours tabstop
    [15:07] dependend on "expandtab" :)
    [15:07] and "shiftwidth" :)
    [15:15] == Axioplase has changed nick to Axioplase_
    [15:24] thkoehler thanks 4 quick response, then how to make cindent indents not more 4spaces
    [15:25] set shiftwidth to 4
    [15:25] tabstop only says "when there are tabstop many spaces, use a tab instead"
    [15:26] shiftwidth is the indent in spaces used for cindent
    [15:26] if expandtab is set, spaces will not be replaced by a tab
    [15:27] :retab will force the current settings of expandtab and tabstop on the file :)
    [15:37] thkoehler, cindent doesn't care about 'tabstop'. 'tabstop' only decides how a tab is displayed. 'softtabstop' and 'expandtab' decide what happens when you press the key, and 'shiftwidth' and 'expandtab' decide what happens when you indent.
    [15:39] spiiph: softtabstop is only used when set to a value different than the default value of 0 :)
    [15:39] Yes
    [15:39] But then the value of 'tabstop' is used when you hit
    [15:40] == Vampire [~Vampire@unaffiliated/vampire] has left #vim []
    [15:40] spiiph: yes, and the value of tabstop is then also used when automatic indent happens
    [15:41] No
    [15:41] no?
    [15:41] No
    [15:43] spiiph: well, yes it is :)
    [15:43] or are we talking about something different?
    [15:43] No, you're wrong. :)
    [15:44] I just started "vim -u NONE", then ":cindent", then created a function, and there was a indent of one tab (8 spaces)
    [15:45] That's an incorrect conclusion. :h 'shiftwidth, :set shiftwidth?
    [15:45] then I set "tabstop" to "4", created another function, which had then a indent of two tabs (=8 spaces)
    [15:45] so, the shiftwidth of 8 is being used
    [15:45] as well as the tabstop setting
    [15:45] you're talking about shiftwidth
    [15:46] I was trying to alk about this part of tabstop
    [15:46] s/alk/talk/
    [15:47] maybe, in the process, we managed to confuse fishcooker completely :)
    [15:49] LoL
    [15:49] Okay, but that's just how the indentation is composed, and not the size of the indent, which I thought you meant.
    [15:50] spiiph: sorry, didn't mean to confuse anyone :)

    :g/quit/d => delete all lines contain quit
    :g/join/d

    ReplyDelete
  7. ## delete all line
    # /join #vim @irc.freenode.net

    ggdG
    :%d

    ReplyDelete