Thursday, July 29, 2010

Nerd tree Tips

SkyHi @ Thursday, July 29, 2010
Question:
Is there an easy way to add a file in nerd tree? Currently I go into my shell, add the file and then refresh the tree.

Solution:

Activate the NERDTree and navigate to the directory in which the new file should live. Then press m to bring up the NERDTree Filesystem Menu and chose a for "add child node". Then simply enter the file's (or directory's name) and you're done.


How to copy (or duplicate) an entire folder in Vim using NERDTree?

NERDTree Menu. Use j/k/enter and the shortcuts indicated
==========================================================
> (a)dd a childnode
(m)ove the curent node
(d)elete the curent node
(c)copy the current node
m + c on the folder would duplicate it

How to jump back to NERDTree from file in tab?

ctrl-ww  http://stackoverflow.com/questions/1656591/how-to-jump-back-to-nerdtree-from-file-in-tab

Better Solution:

I've just started using the NERDTree vim plugin for my project.

I can't find the documentation for switching between opened tabs. Can anyone tell me the shortcut key[s] ?

Thanks...



==Answer==

An additional option (and my personal choice)beyond the ones listed by Michael Madsen:

gt = next tab

gT = previous tab

A quick check in :h tabs reveals it's CTRL-Page Down to cycle between tabs. You can also use the :tabnext command (:tabn for short).



==Answer==

I like to bind my vim navigation keys to switching between tabs. Here are the lines from my .vimrc file:

map   :tabn map   :tabp map   :tabnew 

That way, I can switch between tabs using the left and right buttons just like I normally would move the cursor, except I just hold the Control key as well.

  • Control+l moves to the next tab
  • Control+h moves to the previous tab
  • Control+n creates a new tab




Renaming or copying files and folder using NERDTree on Vim
NERDTree Menu. Use j/k/enter and the shortcuts indicated
==========================================================
> (a)dd a childnode
(m)ove the curent node
(d)elete the curent node
(c)copy the current node

Moving is the same as renaming.


vim and NERD Tree extension - adding a file

Activate the NERDTree and navigate to the directory in which the new file should live. Then press m to bring up the NERDTree Filesystem Menu and chose a for "add child node". Then simply enter the file's (or directory's name) and you're done.

OR

from vim you can run shell commands. So in this case I use:

:!touch somefile.txt

and then hit 'r' to reload the nerdtree window.

The other thing to do is to just start the new file from within vim.

:e somefile.txt

One handy thing for this is that in my .vimrc I auto change the cwd to the directory my current file is in:

" Auto change the directory to the current file I'm working on

autocmd BufEnter * lcd %:p:h

This way if I'm editing a file and want another one in the same place the path is changed right there. Opening any file from NERDTree sets the directory to the one that file is in


Changing drive letter in NERDtree

I started using NERDtree plugin on a a windows platform. I can't seem to find a way to change the drive letter. Going up all the way on the directory tree doesn't lead to the drive letter. Any ideas? (Yes, I know, it's going to be a simple answer)

:NERDTree "drive letter":\


REFERENCES
http://www.8t8.us/vim/vim.html








How do I insert text at beginning of a multi-line selection in VI/VIM?

For commenting blocks of code, I like the NERD Commenter plugin.

Select some text:

Shift-V
...select the lines of text you want to comment....

Comment:

,cc

Uncomment:

,cu

Or just toggle the comment state of a line or block:

,c

,c |NERDComToggleComment|
Toggles the comment state of the selected line(s). If the topmost selected line is commented, all selected lines are uncommented and vice versa.

,cc |NERDComComment|
Comments out the current line or text selected in visual mode.

,cn |NERDComNestedComment|
Same as |NERDComComment| but forces nesting.

,cm |NERDComMinimalComment|
Comments the given lines using only one set of multipart delimiters if
possible.

,cs |NERDComSexyComment|
Comments out the selected lines ``sexily''

,c$ |NERDComEOLComment|
Comments the current line from the cursor to the end of line.

,cA |NERDComAppendComment|
Adds comment delimiters to the end of line and goes into insert mode between them.



VIM: Close file without quiting VIM application?

This deletes the buffer (which translates to close the file)

:bd


http://stackoverflow.com/questions/256204/vim-close-file-without-quiting-vim-application/290110#290110




vim indenting a block of code inward and outward

Ctrl + v

>> - increase indent of selected block

<< - decrease indent of selected block

REFERENCES

http://stackoverflow.com/questions/253380/how-do-i-insert-text-at-beginning-of-a-multi-line-selection-in-vi-vim
http://segfault.in/2010/01/vim-plugins-nerd-commenter/
http://spf13.com/feature/vim-plugins-nerd-commenter
http://www.codealias.info/technotes/5_essential_vim_plugins_for_programmers
http://spf13.com/post/the-15-best-vim-plugins
http://stackoverflow.com/questions/2366711/vim-indenting-a-block-of-code-inward-and-outward
http://www.zalas.eu/tag/vim
http://my.opera.com/subjam/blog/vim-tips
http://vimzone.pixelblaster.ro/