Search This Blog

April 3, 2011

GVim, Vim, Vi key-board short-cuts


  • Switch between tabs

    Ctrl+PageUp, Ctrl+PageDown
    Ctrl + Shift + UpArrowCtrl + Shift + DownArrow

  • Move to Nth tab in gvim
    gt, gT
    Note: The advantage with using gt, gT keys are that you can move to [N]th tab. For eg., if you want to go to 3rd tab type 3gt


  • Open a file in new tab from NERDTree while still remaining in NERDTree

    T will open the selected file in new tab, without changing focus from NERDTree
    t will open the selected file in new tab, and changes focus to that tab


  • Recursively Open all child nodes     

    Activate the NERDTree and navigate to the directory whose all child nodes must open.
    Now press O (capital) to expanded list of child nodes
  

  • Recursively Close all child nodes

    Activate the NERDTree and navigate to the directory whose all child nodes must close.
    Now press X (capital) to collapsed list of child nodes


  • Close all tabs at once with a single command, when I have multiple tabs open

    If no files are modified, then
    :qa
    To save work in all tabs and exit, then
    :wqa
    :xa
    To close all other tabs, except the active one:
    :tabo
    To close all tabs and open buffers
    :qall
    :tabdo :q   (The :tabdo will execute the command passed to it - in this case :q - for all the open tabs)

  • Text object selection

    Select text between Single Quotes
    When cursor is within the single quotes ('), type vi'

    Select text between Paranthesis block ()
    When cursor is within the Paranthesis block (), type vib

    Select text between Curly braces block ()
    When cursor is within the Curly braces block (), type viB

    Note: To make the selections "inclusive" of quotes, parenthesis or braces you can use a instead of i

    More on this can be read at Text object selection
  
  • Create a file or directory in NERDTree
     Activate the NERDTree and navigate to the directory in which the file/directory should be created.    Then press m to bring-up the NERDTree File-system Menu and choose a for "add child node". Now enter the file/directory name and you are done. Note that directory name should end with forward slash - /.

  • Rename a file or directory in NERDTree
    Activate the NERDTree and navigate to the directory in which the file/directory should be renamed. Then press m to bring-up the NERDTree File-system Menu and choose m for "move the current node". Moving is same as Renaming! Now enter the file/directory name and you are done. Note that directory name should end with forward slash - /.

  • Start VIM with NERDTree opened automatically
    Add the line below to your .vimrc:
    NERDTree

  • Auto-open NERDTree in every tab
    Add the two below lines to your ~/.vimrc:
    autocmd VimEnter * NERDTree
    autocmd BufEnter * NERDTree