• Stars
    star
    110
  • Rank 314,908 (Top 7 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ”ͺ Fast within-file word replacement for Vim

scalpel

Intro

Scalpel provides a streamlined shortcut for replacing all instances of the word currently under the cursor throughout a file.

In normal mode pressing <Leader>e (mnemonic: "edit") will display a prompt pre-populated with the current word and with the cursor placed so that you can start typing the desired replacement:

:Scalpel/\v<foo>//

Press <Enter> and Scalpel will prompt to confirm each substitution, starting at the current word (unlike a normal :%s command, which starts at the top of the file).

Scalpel works similarly in visual mode, except that it scopes itself to the current visual selection rather than operating over the entire file.

Screencasts that show Scalpel in action:

Note that :Scalpel just calls through to an underlying scalpel#substitute function that does the real work, ultimately calling Vim's own :substitute. As such, be aware that whatever changes you make to the command-line prior to pressing <Enter> must keep it a valid pattern, or bad things will happen.

The mapping can be suppressed by setting:

let g:ScalpelMap=0

Or overridden:

" Use <Leader>s instead of default <Leader>e:
nmap <Leader>s <Plug>(Scalpel)

In any case, Scalpel won't overwrite any pre-existing mapping that you might have defined for <Leader>e, nor will it create an unnecessary redundant mapping if you've already mapped something to <Plug>(Scalpel).

The :Scalpel command name can be overridden if desired. For example, you could shorten it to :S with:

let g:ScalpelCommand='S'

Then your Scalpel prompt would look like:

:S/\v<foo>//

The command can be entirely suppressed by setting g:ScalpelCommand to an empty string:

let g:ScalpelCommand=''

Finally, all plug-in functionality can be deactivated by setting:

let g:ScalpelLoaded=1

in your ~/.vimrc.

Installation

To install Scalpel, use your plug-in management system of choice.

If you don't have a "plug-in management system of choice" and your version of Vim has packages support (ie. +packages appears in the output of :version) then you can simply place the plugin at a location under your 'packpath' (eg. ~/.vim/pack/bundle/start/scalpel or similar).

For older versions of Vim, I recommend Pathogen due to its simplicity and robustness. Assuming that you have Pathogen installed and configured, and that you want to install Scalpel into ~/.vim/bundle, you can do so with:

git clone https://github.com/wincent/scalpel.git ~/.vim/bundle/scalpel

Alternatively, if you use a Git submodule for each Vim plug-in, you could do the following after cd-ing into the top-level of your Git superproject:

git submodule add https://github.com/wincent/scalpel.git ~/vim/bundle/scalpel
git submodule init

To generate help tags under Pathogen, you can do so from inside Vim with:

:call pathogen#helptags()

FAQ

Why use Scalpel rather than a built-in alternative?

Scalpel is a lightweight plug-in that provides subtle but valuable improvements to the experience you'd get by using Vim's built-in functionality.

Compared to writing a :substitute command manually:

  • Scalpel is quickly activated by a mapping.
  • Scalpel prepopulates the search pattern with the word currently under the cursor.
  • Scalpel avoids a jarring jump to the top of the file, instead starting replacements at the current location.

Compared to a mapping such as "*Ncgn":

  • Scalpel allows you to preview the location at which each change will occur instead of performing the change blindly.

Website

The official Scalpel source code repo is at:

http://git.wincent.com/scalpel.git

Mirrors exist at:

Official releases are listed at:

http://www.vim.org/scripts/script.php?script_id=5381

License

Copyright (c) 2016-present Greg Hurrell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Development

Contributing patches

Patches can be sent via mail to [email protected], or as GitHub pull requests at: https://github.com/wincent/scalpel/pulls

Cutting a new release

At the moment the release process is manual:

  • Perform final sanity checks and manual testing.
  • Update the scalpel-history section of the documentation.
  • Regenerate the documentation:
docvim README.md doc/scalpel.txt
  • Verify clean work tree:
git status
  • Tag the release:
git tag -s -m "$VERSION release" $VERSION
  • Publish the code:
git push origin main --follow-tags
git push github main --follow-tags
  • Produce the release archive:
git archive -o scalpel-$VERSION.zip HEAD -- .

Authors

Scalpel is written and maintained by Greg Hurrell <[email protected]>.

Other contributors that have submitted patches include (in alphabetical order):

  • Keng Kiat Lim

This list produced with:

:read !git shortlog -s HEAD | grep -v 'Greg Hurrell' | cut -f 2-3 | sed -e 's/^/- /'

History

1.1 (12 June 2020)

  • Automatically escape characters that may have special meaning for /\v (patch from Keng Kiat Lim, #11).

1.0.1 (6 March 2019)

  • Prefer execute() when available to avoid potential nested :redir issues.

1.0 (3 January 2019)

  • Perform multiple replacements per line even when 'gdefault' is on.

0.5 (28 July 2018)

  • Fix problem with Visual mode operation on older versions of Vim (GitHub issue #8).

0.4 (23 July 2018)

  • Fix problem with replacement patterns containing the number 1 (GitHub issue #7).

0.3 (10 May 2018)

  • Fix compatibility with older versions of Vim that don't implement getcurpos().

0.2 (13 June 2016)

  • Support visual mode.
  • Do not show "N substitutions on N lines" messages.

0.1 (29 April 2016)

  • Initial release.

More Repositories

1

command-t

⌨️ Fast file navigation for VIM
Lua
2,707
star
2

wincent

πŸ’Ύ Dot-files
Vim Script
1,110
star
3

ferret

πŸ€ Enhanced multi-file search for Vim
Vim Script
678
star
4

clipper

βœ‚οΈ Clipboard access for local and remote tmux sessions
Go
592
star
5

terminus

πŸ–₯ Enhanced terminal integration for Vim
Vim Script
452
star
6

vim-university

A curriculum for leveling up your Vim
Shell
242
star
7

loupe

πŸ” Enhanced in-file search for Vim
Vim Script
145
star
8

corpus

πŸ“ A note-management application
Vim Script
91
star
9

git-cipher

πŸ” Tools for storing encrypted content in Git
Ruby
82
star
10

masochist

β›“ Website infrastructure for over-engineers
Hack
79
star
11

vim-clipper

Clipper integration for Vim
Vim Script
40
star
12

wikitext

🌐 Fast wikitext-to-HTML translator
Ruby
34
star
13

vcs-jump

πŸ€ΎπŸ»β€β™€οΈ Jump to interesting places with a Git or Mercurial repo
Vim Script
30
star
14

docvim

Documentation generator for Vim plug-ins
Haskell
26
star
15

yak-layout

Yak keyboard layout and optimizer
JavaScript
25
star
16

relay-2-simpler-faster-more-predictable

"Relay 2: simpler, faster, more predictable" presentation given at the Silicon Valley ReactJS Meetup on August 17th, 2016
HTML
21
star
17

base16-nvim

base16 color schemes in Lua for Neovim
Lua
19
star
18

pinnacle

πŸ” Highlight group manipulation for Vim
Vim Script
17
star
19

replay

πŸ” Convenient re-run of last recorded Vim macro
Vim Script
17
star
20

presentation-template

Simple starting template for slideshow presentations built using reveal.js, highlight.js and HTML
HTML
12
star
21

synergy

Lightweight iTunes controller for Mac OS X
Objective-C
11
star
22

vim-docvim

Syntax highlighting for Docvim comments
Vim Script
11
star
23

passage

πŸ”‘ macOS keychain caching proxy
Go
11
star
24

cv

πŸ“œ Curriculum vitae
JavaScript
10
star
25

prefnerd

Monitors changes to the OS X defaults database
Ruby
9
star
26

hextrapolate

Number base conversion tool
JavaScript
7
star
27

gerrit-best-practices-tech-talk

Slides from a tech talk at Causes on the subject of best practices for Gerrit code review
CSS
7
star
28

typing-in-js

An introduction to JavaScript type systems
HTML
6
star
29

secure-notes-exporter

πŸ” Export Secure Notes from the OS X keychain
C
6
star
30

js

β˜•οΈ Assorted JavaScript
TypeScript
5
star
31

Google-Breakpad

Fork of the official Google Breakpad repository
C++
5
star
32

algorithms

Code related to the Princeton Algorithms course
JavaScript
5
star
33

atosym

dSYM-compatible replacement for atos
Objective-C
4
star
34

bansshee

Anti-SSH-attack tool
4
star
35

walrat

Ruby packrat parser generator
Ruby
4
star
36

gdiff

Mac OS X-native diff and patch visualization tool for Git
Objective-C
4
star
37

WinSwitch

Fast User Switching menu replacement for Mac OS X
R
3
star
38

walrus

Object-oriented templating system
Ruby
3
star
39

WOPublic

Common code used in all Wincent products
Objective-C
3
star
40

react-training-week-8

βš›οΈ Simple exercises for React training week 8
JavaScript
3
star
41

next

To-do app
TypeScript
3
star
42

automatic-octo-barnacle-theme

Empty Liferay 7.1 theme created for testing purposes
CSS
3
star
43

converter

βš›οΈ Simple demo app for React workshop
JavaScript
3
star
44

remote-component-test

HTML
2
star
45

jost

🀑 Just Jost (not Jest)
JavaScript
2
star
46

url-lengthening-as-a-service

URL lengthener
JavaScript
2
star
47

remote-app-test

JavaScript
2
star
48

presentation

A dead simple presentation boilerplate
JavaScript
2
star
49

wincent-strings-util

Strings file localization tool
Objective-C
2
star
50

login-tool

Command-line tool for managing startup items
Objective-C
2
star
51

clipper-lightning-talk

Lightning talk on Clipper (clipboard access for local and remote tmux sessions)
JavaScript
2
star
52

wopen3

Open3 replacement
Ruby
2
star
53

git-submodules-tech-talk

Slides from a tech talk that I gave at Causes on Git submodules
CSS
2
star
54

buildtools

Build scripts and configuration for use across all Wincent projects
Shell
2
star
55

static-react-boilerplate

Boilerplate for simple static React web applications
JavaScript
2
star
56

wincent-icon-util

Custom folder icon utility
Objective-C
2
star
57

testable-js-lightning-talk

Slides for a lightning talk on writing testable JS and testing it with Jasmine
Ruby
2
star
58

WOHotKey

Hot Key support for Cocoa applications
Objective-C
2
star
59

mkdtemp

Secure creation of temporary directories
Ruby
2
star
60

dented

↔️ Indenting and dedenting utilities
JavaScript
2
star
61

simple-debounce

πŸ€ Simple debounce implementation that fires on the trailing edge only
JavaScript
2
star
62

rails-3-lightning-talk

Slides for a 5-minute lightning talk on view escaping in Rails 3
JavaScript
2
star
63

unpack-content

πŸ—ƒ Extract header data and body from plaintext (Markdown-ish) markup source
JavaScript
2
star
64

git-filter-branch-lightning-talk

How to open-source your repo without open-sourcing your repo
CSS
2
star
65

null

An empty value
1
star
66

minimal-npm-boilerplate

Minimal boilerplate for creating an NPM package
JavaScript
1
star
67

fusion

Pure plug-in architecture framework for Objective-C
Objective-C
1
star
68

fusion-base

Base plug-in for building "pure plug-in" apps
Objective-C
1
star
69

fusion-meta

Plug-in management plug-in for building "pure plug-in" apps
Objective-C
1
star
70

fusion-updater

Updater plug-in for building "pure plug-in" apps
C
1
star
71

fusion-crash-reporter

Crash reporter plug-in for building "pure plug-in" apps
C
1
star
72

wincent-on-rails

Legacy Rails application that used to power wincent.com
HTML
1
star
73

askpass

Graphical password prompter
C
1
star
74

compass-lightning-talk

Tiny demo app showing off some features of Compass for a 5-minute lightning talk at Causes
Ruby
1
star
75

conway

Conway's Game of Life
JavaScript
1
star
76

seven-languages-prolog-tech-talk

Slides and code from a tech talk on Prolog given at Causes for our Seven Languages in Seven Weeks reading group
Prolog
1
star
77

tiktoken-ruby

Rust
1
star
78

fusion-demo

Demonstration app for Fusion framework
Objective-C
1
star
79

fusion-menu

Menu plug-in for building "pure plug-in" apps
Objective-C
1
star
80

fusion-help

Help plug-in for building "pure plug-in" apps
C
1
star
81

WOBezel

Bezels, splashes and HUDs for Mac OS X
Objective-C
1
star
82

fusion-prefs

Preferences plug-in for building "pure plug-in" apps
Objective-C
1
star
83

WOTest

Objective-C unit testing framework
Objective-C
1
star
84

gerrit-intro-tech-talk

Slides from an introductory tech talk at Causes on the subject of Gerrit code review
CSS
1
star