2

Github GitHub - JRasmusBm/vim-peculiar

 2 years ago
source link: https://github.com/JRasmusBm/vim-peculiar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Vim Peculiar

Not just normal commands.

Video introduction: Go to YouTube

The idea behind the plugin is to provide shortcuts when working with the :norm[al] command. It has been so useful to me that I for the first time decided to wrap it up as a plugin for others to use.

Motivation

I really love the expressiveness of running normal commands, either over a range of lines or matching a search. The original intent of this plugin was to provide a way to run such commands against a text object.

Usage

Please note: Since making the video I updated the prompt for PeculiarV and PeculiarG. Until I have time to document it, please refer to Issue #5 for the motivation and Issue #9 for an explanation of how it works.

The plug-in exposes 4 command line utilities,

  • <Plug> PeculiarN: Takes a text object and a normal command and runs the command against each line of the text object (think l1,l2 norm with better support for multi-line edits)
  • <Plug> PeculiarG: Takes a text object, a search and a normal command and runs the command against each line of the text object matching the search (think l1,l2 g/<search>/norm)
  • <Plug> PeculiarV: Takes a text object, a search and a normal command and runs the command against each line of the text object not matching the search (think l1,l2 v/<search>/norm)
  • <Plug> PeculiarR: Takes a text object and runs the previous peculiar command against it (think repeat previous)

Example setup:

nmap <localleader>v <Plug>PeculiarV
nmap <localleader>g <Plug>PeculiarG
nmap <localleader>n <Plug>PeculiarN
nmap <localleader>r <Plug>PeculiarR

Each command run updates the command line history and the search commands update the search history for easy editing if you make mistakes.

Options

The normal command used in PeculiarN will cause the whole selection to be highlighted if incsearch is turned on. If you want to run PeculiarN in a function instead (thus suppressing the highlight), you can set.

let g:peculiar#surpress_highlight_n = 1

Attributions


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK