`
If you find these tutorials useful, Please consider making a donation.

TheFrugalComputerLinuxLogo.png
TheFrugalComputerGuy.png
Vim 10
netrw







Vim (31) netrw pt1 - Intro to netrw

Netrw is file explorer plugin for vim and comes installed on Vim 7.0 and higher. If you are using the popular plugin nerdtree, some of the things in these next few videos may not work for you.

Typing vim and then a directory name opens the netrw file explorer. Typing vim . opens the the directory you are currently in with vims netrw file explorer.

Press :q to quit out of the Vim file explorer

The hidden files are shown by default because Vim is often used to update hidden configuration files.

The standard vim cursor movement and commands work in netrw k for up "j" for down and "" for find.
Pressing "-" will also take you up a directory

Pressing enter when your cursor is on a directory name, takes you into that directory.
Pressing enter when your cursor is on a file will open that file with the Vim file editor.

Pressing enter when your cursor is on ../ will take you up a directory.

Quitting out of the Vim file editor will return you to a bash prompt (Not back to the netrw plugin) and in the directory where you entered Vim.





 






Vim (32) netrw pt2

We go back into the netrw file explorer plugin and look at the banner at the top of the window.

We see what version we are using, what directory we are in, and how it is sorted - As well as how to change the sort order.

We then look at the Quick Help and see the commands:

D to delete a file
s to change the sort order of the directory
x special (opens the file in your operating systems default text editor)
R to rename a file
% to create a new file
d to create a new Directory
i style, shows the file information in 3 different styles, date and time information, in columns, in a tree view
qf is for quick file information
r reverses the sort order

We create a new directory and move a file into that new directory using the "R" to rename the file.





 






Vim (33) netrw pt3 copy/vimrc

We use netrw to copy some files to a new directory by:
1) marking the target directory (with "mt")
2) Mark the file to copy (with "mf")
3) Copy the files (with "mc")

If you want to move a file, use rename as shown in video 32.

We then look at o, v, and p.

o will open a file in a horizontal split window.
v will open a file in a vertical split window.
To change the vertical split to the right side type:
:let g:netrw_altv=1

p opens a preview window similar to o, but the cursor remains in the file explorer window.
The preview split can be changed to vertical by typing:
:let g:netrw_preview=1

You can split into a file explorer window by typing:
:Vex

Toggle on/off hidden/dot files with:
gh

Toggle on/off hidden/dot files with:
I

Download the .vimrc file from:
https://thefrugalcomputerguy.com/linux/seriespg.php?ser=10002#Vid33





 






Vim (34) Netrw Fix and Fuzzy Find

We use netrw to create a directory with the lower case "d" and then we rename a file to change the directory it is in with an upper case "R" and adding the directory to the filename path.

When we try and quit out, we get the error "No write since last change"

To get around that error by typing ":qa!"

To prevent this error from happening again, we add this line to our .vimrc:

autocmd FileType netrw setl bufhidden=delete

We look at using :find to find files to open for edit in Vim.

We add some lines to our .vimrc that allows us to do a fuzzy find in our directory path meaning we can search for all the files that end with .txt by typing find *.txt

Download the .vimrc file from:
https://thefrugalcomputerguy.com/linux/seriespg.php?ser=10002#Vid34





 






Vim (35) vimgrep

Vimgrep is similar to the find command.

There are a few differences between find and vimgrep.

We need to tell vimgrep where we want it to search the percent sign % means the current open document and **/* means the current working directory.
(Note: You must have your .vimrc file updated with the lines from video 34 for this to work like it does in this video)

Vimgrep will also return the number of times that search argument was found.

All found search arguments can be found in the quickfix list by typing :cope (for c open) or :cw (for c window)

We can use k and j to move up and down to and pressing enter will take us to that spot in the document.

We can also use :cnext, :cprev, :cfirst, and :clast to jump to the

The shortcut for vimgrep is vim