Skip to content

Instantly share code, notes, and snippets.

@nelstrom
Last active September 12, 2015 20:30
Show Gist options
  • Save nelstrom/8d7919e326b5baa24feb to your computer and use it in GitHub Desktop.
Save nelstrom/8d7919e326b5baa24feb to your computer and use it in GitHub Desktop.

Building Vim with patch for :cdo/:ldo/:cfdo/:lfdo commands

I've written about one possible workflow for doing project-wide search/replace in Vim. This relies on a custom :Qargs command, which populates the arglist with each of the files listed in the quickfix list. Having run that command, you can then run :argdo sub/find/replace/gc to substitute across all files in the argument list. If only Vim provided a built-in :cdo command then this workflow would be more straightforward, and wouldn't require the custom :Qargs command.

Good news: Yegappan has implemented :cdo/:ldo/:cfdo/:lfdo commands. You can read the discussion and find the patch on the vim-dev mailing list.

Here are the steps that I used to download Vim source, apply the patch, and build Vim using the patched source code.

Download Vim's source code

Download Vim's source from GitHub and check out a branch:

git clone [email protected]:vim/vim.git
cd vim
git checkout -b cdo-patch

Apply the patch

Download the patch that you want to test and save it to the vim directory. Suppose we're working with a patch called cdo.diff, we can apply the patch by running:

patch -p1 < cdo.diff

Commit any changed files (and new files):

git add -u
git add new/file.c new/file.h
g ci -m 'Apply cdo.diff patch'

Build Vim

Build Vim:

./configure \
  --with-features=huge \
  --enable-rubyinterp \
  --enable-pythoninterp \
  --enable-perlinterp
sudo make && sudo make install

That installs Vim to /usr/local/bin/vim, overwriting the existing binary.

@jcollado
Copy link

It seems that the patch has been already merged to master here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment