NERDTree] How can I map double click to NERDTreeCustomOpen? - vim

This might be a simple question for NERDTree users.
I'm trying to use NERDTree, and I found two ways to open files in NERDTree window, press <CR> as enter and double-click the file with the mouse (same as with pressing o).
I wanted to open new file in the window at vertical right side (keep original file opened), and finally I could customize NERDTreeCustomOpenArgs. However, the way to open files with double-click seems to be different, so I want to remap double-click to NERDTreeCustomOpen, not to NERDTree-o.
I've tried to map the double-click as shown here and here, but it has not worked for me.

Related

Vim, how to make Netrw to replace current open file instead of split opening new window, when you press preview or create new file commands?

Recently I've been using netrw. I've put these four lines on my .vimrc:
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_winsize = 25
map <C-n> :Lexplore <CR>
And I can easily toggle Lexplore and browse through the files to edit them. In this mode when I press Enter on any file on left hand side Netrw, it replaces the file in the right hand side window with new file; exactly what I want.
Problems start when I want to preview a file with "p" command on netrw or create a new file with "%" command. In former case (Preview) it split to the new window but I want it again to replace the file in right hand side window just like when I press Enter to to edit the file. And in latter case (creating a new file) it replaces the Lexplore (Netrw in the left hand side) instead of replacing the file on the right hand side window.
Is there any way that I can fix these issues? I've tried a lot of Netrw commands but nothing gives me what I want.
The "p" netrw command is mostly just pedit. So, assuming you don't already have a preview window, just press <cr> atop the file you want to preview and then :set pvw. That will make the window holding the file the preview window.
The second issue concerns "%" to create a new file. I'll think this over, but I think perhaps the better behavior is as you suggest -- keep the Lexplore window but open the new file in the editing window.
Please try version 171e of netrw which you can find at my website.
I believe this is related to a bug in vim. Once you use :Lexplore it apparently changes the g:netrw_chgwin option permanently, so whenever you try to pres <CR> in any netrw window, it will always open in a new window.

how to make Taglist window cannot be placed by opened file

I like Taglist in Vim very much. However, when I open a new file or click the file name in the BufferExplor, the file will display in the Taglist window. Is there method to keep the Taglist window cannot be used to display the file opened? When I open a file, how to use a new window in the Vim?
Thank you!
When you're inside the TagList window, don't use :edit. Either use a command list :split or :vsplit to open the file, or move to another window first (via <C-W><C-W> etc.) The typical layout is a small TagList sidebar to the left, and a big editing area right of it. Move there first.
As to plugins like BufferExplorer, they either need to be able to recognize those "special" windows, or again you have to use the "open in split window" command in them. I personally use custom mappings to toggle such plugins, so that there is only one at a time displayed in the sidebar, thereby avoiding this issue.

NERDTree and vim-windows

I like to have two or three vertical windows with code and a NERDTree to the left, among other things. From any of these windows I'd like to instantly jump to the NERDTree window, and when I choose to edit a file, I'd like that file to show up in the window I was in.
Are these things possible with the current state of the NERDTree plugin? It seems to me that :NERDTreeToggle is supposed to do the first thing I ask for according to the help, but no matter how I open a file, it always shows up in the window right next to my NERDTree.
Try :NERDTreeFocus to jump to the NERDTree window from any open window. This was added relatively recently, it seems:
https://github.com/scrooloose/nerdtree/pull/132

In Vim, is it possible to open a file in specify opened split window?

Recently, I use Vim as my editor while programming Ruby, but I don't know if I can do that in Vim. Let's say in my Vim, I already have 2 vertical split windows named A and B like this:
And then I hit gf to jump to the source file xyz.rb if I park the cursor under the require statement, but it will show in the same window A by default.
Is there any shortcuts or quick combo that I can open or show the source file xyz.rb in the opened B split window? (and even if the window B doesn't exist yet, create one automatically)
I've check the manual, and it does has some ways to show xyz.rb in different horizontal split window or a new tab, but is it possible if I want to show it in specify opened split window B.
thanks :)
The functionality you describe is already present in the form of a 'preview window'.
You could map a key (e.g. gf) to something like
:exec 'pedit ' . expand('<cfile>')
This will open the filename under the cursor in the preview window. A new preview window will be opened if none exists. See :he preview-window for more information.
Use ^Wz (or :pclose) to close the preview window

How to jump back to NERDTree from file in tab?

I usually:
Choose the needed file.
Open it in a tab(t character, by default).
But how I can jump back to NERDTree to open one more file in a tab?
Temporary solution I use now in my .vimrc file:
map <F10> :NERDTree /path/to/root/of/my/project
But it's not very useful to start navigation again and again from the root directory.
Ctrl-ww
This will move between open windows (so you could hop between the NERDTree window, the file you are editing and the help window, for example... just hold down Ctrl and press w twice).
Ctrl+ww cycle though all windows
Ctrl+wh takes you left a window
Ctrl+wj takes you down a window
Ctrl+wk takes you up a window
Ctrl+wl takes you right a window
NERDTree opens up in another window. That split view you're seeing? They're called windows in vim parlance. All the window commands start with CTRL-W. To move from adjacent windows that are left and right of one another, you can change focus to the window to the left of your current window with CTRL-w h, and move focus to the right with CTRL-w l. Likewise, CTRL-w j and CTRL-w k will move you between horizontally split windows (i.e., one window is above the other). There's a lot more you can do with windows as described here.
You can also use the :NERDTreeToggle command to make your tree open and close. I usually bind that do t.
If you use T instead of t there is no need to jump back because the new tab will be opened, but vim's focus will simply remain within NERDTree.
You can focus on a split window using # ctrl-ww.
for example, pressing:
1 ctrl-ww
would focus on the first window, usually being NERDTree.
Since it's not mentioned and it's really helpful:
ctrl-wp
which I memorize as go to the previously selected window.
It works as a there and back command. After having opened a new file from the tree in a new window press ctrl-wp to switch back to the NERDTree and use it again to return to your previous window.
PS: it is worth to mention that ctrl-wp is actually documented as go to the preview window (see: :help preview-window and :help ctrl-w).
It is also the only keystroke which works to switch inside and explore the COC preview documentation window.
ctrl-ww Could be useful when you have limited tabs open. But could get annoying when you have too many tabs open.
I type in :NERDTree again to get the focus back on NERDTree tab instantly wherever my cursor's focus is. Hope that helps
The top answers here mention using T to open a file in a new tab silently, or Ctrl+WW to hop back to nerd-tree window after file is opened normally.
IF WORKING WITH BUFFERS: use go to open a file in a new buffer, silently, meaning your focus will remain on nerd-tree.
Use this to open multiple files fast :)
You can change the tabs by ctrl-pgup and ctrl-pgdown. On that tab you came from the NERDTree is still selected and you can open another tab.
In more recent versions of NERDTree you can use the command :NERDTreeFocus, which will move focus to the NERDTree window.
gt = next Tap
gT = previous Tab
if you want you can enable the mouse support editing ~/.vimrc file.
put set mouse=a
after that you enable files click in NERDTree.
All The Shortcuts And Functionality is At
press CTRL-?

Resources