Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
40

From Vim's documentation, :x and ZZ are equivalent; they only save the file if it has been modified, then quit Vim: Write current file, if modified, and quit (same as ":x"). (Note: If there are several windows for the current file, the file is written if it was modified and the window is closed). :wq on the other hand writes the file and quits Vim (...


30

There is DirDiff.vim plugin (GitHub) to diff and merge two directories recursively. It performs a recursive diff on two directories and generate a diff "window". Based on that window you can perform various diff operations such as opening two files in Vim's diff mode, copy the file or directory recursively to the other, or remove the directory tree ...


20

Update 2015-06-25: I've scrapped the "shell" method, as it was too dysfunctional. It stopped insert mode and left zombie processes. Look at this posts's revision history is you really want to see it anyway. I've made a plugin out of this: auto_autoread.vim. At the moment, it's effectively the same as the code below, but I would recommend you use the plugin ...


19

There are a few lightweight ways to do this. Check for a file of given name and source it if filereadable(".vimscript_file") so .vimscript_file endif The file is hidden in the example but that's optional. Local .vimrc files (not the same as the plugin) set exrc This is similar to 1. but the file will be called ".vimrc". A common suggestion to ...


16

You cannot use y, p etc., to copy files in netrw - it comes with its own commands. See :h netrw-mc: MARKED FILES: COPYING netrw-mc {{{2 (See netrw-mf and netrw-mr for how to mark files) (Uses the global marked file list) Select a target directory with mt (netrw-mt). Then change ...


15

I use localvimrc for this purpose. Put a .lvimrc with your project settings inside your project and these settings will override settings in .vimrc. By default, you will be asked if you want to source this file, eg: localvimrc: source /home/martin/code/.lvimrc? ([y]es/[n]o/[a]ll/[q]uit) This is to prevent sourcing random (untrusted) vimrc files. If you ...


13

Assuming you have Vim 8 you can use :filter :browse filter /pattern/ oldfiles For more help see: :h :browse :h :filter :h oldfiles :h new-items-8


10

Special characters (see :h cmdline-special) and filename modifiers (see :h filename-modifiers) are expanded on the command line, so: :diffsplit Path/to/other/directory/%:t


9

The list of valid filename characters is given by the isfname variable. From :he 'isfname': 'isfname' 'isf' string (default for MS-DOS, Win32 and OS/2: "@,48-57,/,\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=" for AMIGA: "@,48-57,/,.,-,_,+,,,$,:" for VMS: "@,48-57,/,.,-,_,+,,,#,$,%,<,&...


9

As akshay pointed out, Vim's documentation explains, that :x and ZZ are equivalent and only save a file if the associated buffer has been changed. Whereas :wq saves the buffer to the corresponding file, even if it is unchanged. In both cases, the contents of the buffer will be saved to disk. Obviously the outcome is the same, so why bother, right? But wait....


9

I would do this from the command line mode: Select the file you need in netrw Open command the line and type - :!mv <C-R><C-F> ../<C-R><C-F> Here <C-R><C-F> inserts file name under cursor, so you don't have to type the file name.


9

You're looking for globpath(). If it returns a non empty string, then there is at least a match. if !empty((globpath(&rtp, '/autoload/FooBarBaz.vim')) You may also want to check filereadable() if you suspect you may not be able to open the file. BTW, I'd have used filter() in your solution (I hate debugging vim loops) -> if !empty(filter(split(&rtp,...


9

What you're looking for is :Vexplore. From your question, it sounds like you started off knowing only about :Sexplore and understandably thought that that was the basic command for bringing up the vim file explorer (which is called netrw). However, the basic command is just :Explore, and :SExplore is actually just a variant of that. The basic :Explore ...


8

Vim comes with a built-in file explorer called netrw. If you have a reasonaby recent Vim, the following command will give you the kind of feature you are missing: :Lexplore See :help netrw.


8

I prefer to type / because extra/////slashes///are//ignored. Also, the arrow keys are poison. :)


8

Simply press the right arrow key.


8

This is because vim does not evaluate variable names or functions with most commands. In your case, vim thinks you literally want to read the contents of a file called g:filePath into the buffer. What you want can be accomplished with the :execute command. This command takes a string as an argument, and will then run that string as a command. In your ...


7

I set the following two options to ensure that Vim's current working directory is always the same as the current buffer's. set autochdir " Changes the cwd to the directory of the current " buffer whenever you switch buffers. set browsedir=current " Make the file browser always open the current ...


7

Yes, vim has a :cd command, which either prints the current directory or changes the current directory. In the help is this - note the last lines: :cd[!] {path} Change the current directory to {path}. If {path} is relative, it is searched for in the directories listed in |'cdpath'|. ...


7

A similar question was just asked on the Vim reddit here. I started using ctrlp-cmatcher myself quite awhile ago which I find to be much more intelligent at matching the right file. Note that it does require a compiled component. Otherwise you'll have to try some of the approaches in the article.


7

You can use the relatively popular file-line plugin. Note that this plugin seems relatively unmaintained, and there exists several forks. I have a personal fork where I've made some minor updates and fixed a couple of small bugs, see here.


7

You can use vim's file name completion feature for this. To use it, press CTRL-xCTRL-f in insert mode. For more on this, see :help compl-filename. Do note that it isn't recursive, so you must complete the path level by level. (first app/, then poit/, etc.)


7

You can do this by setting the 'path' option to include **, and then using the :find command: :set path=.,,** :find filename.cpp The section on File Searching in the documentation describes how the ** path wildcard works.


6

Vim's 'path' option allows you to specify directories which commands like gf and :find will search for a file. If you only want this functionality to trigger for a specific set of files, then you could use an autocmd to automatically "redirect" your :edit command to the file in one of the 'path' directories. set path+=~/ function! FindInPath(name) let ...


6

Yes, but currently(2015) not out-of-the-box, because the built-in file-manager of vim doesn't natively support remote browsing. . Update Q3@2016: There are several work-arounds, with varying degrees of comfort/compatibility/effort. All together they add up to a nice solution, but they can all also be used individually: Setup a user-level afuse/sshfs ...


6

The solution to this type of problem is the :execute command: :execute '0read' g:filepath See :help :execute


6

Commands like read don't evaluate your variables, it takes the argument to be a literal (a file named g:filePath). The execute command, however, takes string arguments, concatenates them and executes the result as if it were a command invocation. You can therefore 'wrap' your command: turn the read command into a string and pass is together with the variable ...


6

From :help gf: Trailing punctuation characters ".,:;!" are ignored. So I suppose the dot at the end is not considered as part of the filename but as punctuation. I don't know if it can be done with fewer keystrokes, but to open this file while the cursor is on B, I would type: viWF.<c-w>f viW = visually select characters inside big word F. = ...


6

:set fileignorecase will treat file names and directories as case insensitive. It's on by default for some systems like OS X which comes built in with a case insensitive (but case preserving) file system. You can also read the help on it for more: 'fileignorecase' 'fic' boolean (default on for systems where case in file names is normally ...


6

You can take advantage of the way vim execute command when applied over a range. Select your lines and do: :'<,'>call system('mkdir -p '. fnamemodify(fnameescape(getline('.')),':h:p').' && touch '.fnamemodify(fnameescape(getline('.')),':p')) This will apply the command call system(...) over every line you've selected. The command is ...


Only top voted, non community-wiki answers of a minimum length are eligible