I am using Vim80 on Windows 10. Using Netrw command , by default it will open up my %HOME% path. I want to open specific disk drive on my computer like F: using netrw. I have searched through similar questions on Stack Overflow and found answers like using :Ex F: or :cd F:\ but it does not change the default directory. What is the netrw vim command that will enable me to change the drive I am working on?
You are searching for the wrong thing, Netrw has no default directory, it just opens your active directory.
So if you open a cmd navigate fo F: and then run vim, you will have what you want.
But i know that is not the workflow in windows. so you can change the "starting directory" properity on the shortcut to your vim.
right click on vim Icon -> property/shortcut/Start in
as Doktor OSwaldo stated Netrw doesn't have a default directory. However an alternative approach i've used sometimes is to clone my Vim shortcut by going to the file location:
Then cloning the shortcut under a new name:
Then i simply enter the directory (or drive) i want vim to open with netrw by default, like so:
Then i can find vim in the windows menu easily:
Which allows me to start up my vim instance like this:
I tend to do this per project which gives me nice project oriented searching available from the windows menu. Anyway, i hope this helps although i understand it was slightly different to what you wanted ideally. If i were you i would create a shortcut per drive so you could search vim and see results like:
vim
vim-f-drive
vim-c-drive
vim-d-drive
Related
I'm following a tutorial on Uniswap forking (just to learn how this works) and I'm stuck a particular step.
How does one go from:
vim migrations/2_deploy_contracts.js
to
I'm only able to see:
How do I see the folders and directories ?
The user in that particular video is using the NERDTree plugin for Vim. Vim is very powerful and extensible, and it's possible to load a variety of extensions written in Vimscript to customize the interface, add editor features (such as LSP support), or various other functionality.
They're also using a custom colorscheme which is probably based on the Solarized palette. You can also load a custom colorscheme with the :colorscheme ex command.
There is another thing to notice, besides mentioned NerdTree plugin.
I think you are running your command from the wrong place.
vim migrations/2_deploy_contracts.js
This command tries to open the file set by relative path, or creates a new file, if that does not exist. As we see from your screenshots - the file exists in the tutorial, but it does not exist on your machine (the [+] mark after the filename on the second screenshot shows that).
My guess you need to cd to the right directory first (tutorial project root) and then only run your vim command to open the file.
As for your question about seeing the files and directories, you can do it without NerdTree plugin, using built-in netrw. Just type :Ex in vim normal mode.
I'm starting to use vim's native explorer (:E). My doubt: when I press c to "make browsing directory the current directory" nothing happens.. When I used nerdTree and did the same operation (:NERDTreeCWD), that directory was placed at the top of the exporer and the directories upper were "hidden".
It just seems pressing c is not doing anything..
NOTE: Im using the tree view on explorer, instead of the default one. I pressed i to change the view.
Im using 7.4.52
The netrw command works different than NERDTree's. It doesn't apply to the directory under the cursor, but to the one currently being browsed. So if you want to make a subdir the current one, first go into it (via <Enter>), then press c.
To expand on Ingo's answer. If you always want netrw to make the current browsing directory the current vim directory, you can set the option let g:netrw_keepdir=0 in your .vimrc.
This allows you to use netrw to browse directories and use vim to operate in that directory. For example, you can use vim's command :e <filename> to create a new file instead of netrw's command % <filename>.
To learn more about netrw I recommend reading the help pages :help netrw-quickhelp
As a newbie in vim I am full of silly questions. :D
Running gvim on Windows 7 64bit, I am careful to avoid complex plugins but try to start from whatever existing to be familiar with the tool.
So now I cannot find a way to lookup files on D drive, how to switch in Netrw? Do I have to mount it like in Linux?
Also, how to quit Netrw but still stay in gvim?
Last question, is nerdtree really much better than netrw?
A way to lookup files on D drive
The plugin is triggered by :editing a directory, so this is what you'll do:
:edit D:\
You could also :cd D:\ first, and then :edit ., or use the dedicated :Ex, :Sex, etc. command(s) that the plugin provides.
How to quit Netrw but still stay in gvim
In Vim, everything is a buffer displayed in a window. Unlike in IDEs, plugins have to "fake" their user interface as special buffers. So, you leave the netrw buffer like any other: Start :edit file, or :enew for a new one, or :bdelete, or :bnext, or ...
Is nerdtree really much better than netrw
The main differentiator is that NERDTree defaults to a hierarchical file listing in a left-hand sidebar (similar to Windows Explorer). You can have that in netrw, too (let g:netrw_liststyle = 3). There's feature parity in other areas, too (e.g. bookmarks), while some things are unique to NERDTree (fancier tree visualization, customizable action menu). netrw provides transparent access to remote file systems, which NERDTree doesn't. You can even use both in parallel!
I'd recommend to read NERDTree's help, and once you run into something that netrw doesn't do well, remember NERDTree and put it to the test.
The command :Ex D: should show you a listing of drive D:. Just press :, type Ex D:, Enter.
:q or :close should close any window or tab, including netrw.
You may wish to review the netrw documentation.
Is there a way to make Vim work like notepad++ with explorer plugin or other text editors as pspad, ultraedit and editplus?
that is
keep a fileexplorer always left (left sidebar of 15% width)
and opens all files in the content window (85% of width) and every file in a new tab (above).
I checked nerdtree and vimexplorer plugin but could not find any way to do what I want.
Check out NERD Tree. This isn't the best screenshot, but it'll give you an idea of what to expect:
To your question there is definitely many ways you can possibly get the outcome. When you mentioned NERDTree does not work the way you want, I believe you have not tried it out well enough. I would recommend you read the documentation of the NERDTree plugin. Derek's answer just shows you that with NERDTree and minibufexplorer.
One solution I could suggest is have a windows file explorer open beside your gvim window. Follow instructions in the vim.wikia page to open files in a tab when you double click on the file. If you are using Mac, MacVim has an option to open new files in a tab by default.
Now that I have provided a solution, let me remind you that Vim is unlike most of the other editors you might have used earlier. Look at the answer titled "Your problem with Vim is that you don't grok vi.", here. Vim is different, learn to grok it.
Now the point of tabs in Vim. Tabs in Vim are different, look at an answer in SO here. Tabs in vi are more like workspaces. In Linux or Mac you have the concept of workspaces where you can place your application windows together. For example assume I am working on developing a website. In one workspace I would keep my code editor, my web browser and probably a terminal. And for all my personal stuffs I would you another workspace. Like for my social stuffs I would have another workspace with my twitter client, my chat messenger and a browser for facebook. Similarly in Vim use tabs as workspaces for your different files. You might be editing couple of files. Group the ones you edit, use window splits which vim is best for. This is my vim layout:
.
I havent used tabs but use NERDTree, minibufexplorer and serves my need. I don't have to use my mouse at all, it makes my editing more efficient. Take some time reading good articles about Vim. You will see that you actually don't need most of the GUI stuffs many other editors gloat about. Try using Command-T plugin for opening files. You will find it a lot more efficient.
Read the following to get a better idea about tabs, buffers and windows in Vim:
http://jonathan.jsphere.com/post/9927807318/taming-vim-4-buffers-windows-tabs
http://blog.interlinked.org/tutorials/vim_tutorial.html
I personally use a combination of minibufexplorer and NERDTree, and it works very well for me. minibufexplorer keeps a window at the top with all the files I've opened, which I can switch between using ctrl-tab. NERDTree is open on the left, and choosing a file opens it in my main editor window, and lists it in the minibufexplorer window.
VIM includes netrw, which is already a filebrowser and I like it a lot more than NERDTree.
I have included the function below in my local .alias file.
Thus, from a terminal or console execute vc (mnemonics for V.im C.ommander) and you'll get a nice double pane browser with ssh, ftp, file execution and a large array of capabilities.
In SH alike shells try:
vc ()
{
local TARGET='';
[ -z "$#" ] && TARGET=. || TARGET="$#";
vim \
-c "set cursorline" \
-c vsplit \
-c "normal gh" \
-c "let &titlestring=\"netrw\"" \
-c "set acd" "$TARGET";
return 0
}
Enjoy!
PS:// If you need netrw filetype definitions (i.e., executing a movie player for movie files and so forth, i'll publish mine)
Sorry to ask such a novice question but I am looking for a way to handle multiple files. I dont want to type huge file paths to open every file using :tabnew and :e commands
Fuzzy Finder is a handy plugin to quickly find and open files.
Basically you have to only type a few letters like test and you'll get a pop-up menu to open in your current path :
footest.c
bartest.h
footest.h
...
It is a bit slow when used on NFS but it is useful if you don't want to type long path and file names.
Alternatively if you don't want to use any plugin, by default gvim/vim includes a file browser called netrw.
To start it, just type :e . you'll get the content of your current directory, you can then navigate through the directory structure quite easily. (There is even commands to delete, rename, etc like a standard file explorer)
:help netrwfor more information.
A couple of tips that you might be interested in:
You can configure Vim so that the
current directory "follows" the
directory of the file you are
currently editing. That way you can
edit another file from the same
directory without having to type the
full path. This can be achieved by
putting either set autochdir or
autocmd BufEnter * lcd %:p:h in
your .vimrc
You can use wildcards with tab
completion. e.g. to edit
a_file_with_a_long_name.txt you could
do :e a*long and then press
Tab followed by
Return.
Usually, vim supports buffers for that. Use :badd to add buffer, :bdelete to remove it and :ls (or :buffers) to list all opened buffers. I believe, GVim supports these features too.
For example, if you wanna edit all .rb files in your app/controllers/pages dir (in the case of Rails project), you type vim app/controllers/pages/*.rb in your terminal and then edit the first file (buffer) in the vim window. When you've done with all changes, save changes as usual with :w (note: do not use q! option - this will close all your buffers you've opened) and then use :bn<tab> (or fully, :bnext) or :bprevious to switch to the next file (buffer). When you run :bnext on the last buffer, you'll be dropped to the first one.
You can open a directory in Vim, search for the file o directory you are looking for with '/' and type [enter] to open it.