actually make the vim syntax work nicely + document it

This commit is contained in:
Mirek Kratochvil 2025-10-14 14:07:40 +02:00
parent 6beaeec8e7
commit 10777c32f6
3 changed files with 41 additions and 9 deletions

View file

@ -42,6 +42,16 @@ In any other case, you may set up a path to any compatible `diff` and `patch`
(or suitable wrapper scripts) via environment variables `WERGE_DIFF` and
`WERGE_PATCH`. (If required, the same applies for `WERGE_GIT`.)
### Editor integration
There's a `vim` syntax highlighting file in `vim/werge.vim`. To install, simply
copy it to your local `vim` syntax configuration directory (usually to
`~/.vim/syntax/werge.vim`). Then, you can activate the syntax in vim with:
```
:set syn=werge
```
## Demo
##### Original (`old` file):
@ -74,7 +84,8 @@ Violets are blue.
Patching is hard.<<<<< I still||||| I=====
I>>>>> cannot do verses.
```
(NOTE: option `-G` gives nicely colored output that is much easier to read.)
(NOTE: option `-G` gives nicely colored output that is much easier to read.
Alternatively you can install the syntax highlighting for `vim`.)
##### Merge with separate space resultion
Adding option `-s` to `werge merge` causes it to resolve space conflicts

29
vim/werge.vim Normal file
View file

@ -0,0 +1,29 @@
" Vim syntax file
" Language: werge
" Maintainer: Mirek Kratochvil
" Last Change: Oct 14, 2025
" Version: 1
" URL: https://github.com/exaexa/werge
" quit if a syntax file was already loaded
if exists("b:current_syntax")
finish
endif
" syntax for the werge files
syntax region wergeHunk start=/<<<<</ end=/>>>>>/ contains=wergeRm,wergeDiffAdd,wergeConflictOrigAdd
syntax region wergeRm start=/<<<<</hs=e+1 end=/|||||/he=s-1,me=s-1 contained
syntax match wergeDiffAdd /|||||\([^>=]\|>\{1,4\}>\@!\|=\{1,4\}=\@!\)*>>>>>/ms=s+5,me=e-5 contained
syntax match wergeConflictOrigAdd /|||||\([^=>]\|=\{1,4\}=\@!\|>\{1,4\}>\@!\)*=====\([^=>]\|=\{1,4\}=\@!\|>\{1,4\}>\@!\)*>>>>>/me=e-5 contained contains=wergeConflictOrig,wergeconflictAdd
syntax region wergeConflictOrig start=/|||||/hs=e+1 end=/=====/he=s-1,me=s-1 contained
syntax region wergeConflictAdd start=/=====/hs=e+1 end=/>>>>>/he=s-1,me=s-1 contained
" color specification
highlight default link wergeHunk Comment
highlight default link wergeRm Removed
highlight default link wergeDiffAdd Added
highlight default link wergeConflictOrigAdd Comment
highlight default link wergeConflictOrig Changed
highlight default link wergeConflictAdd Added
let b:current_syntax = "werge"

View file

@ -1,8 +0,0 @@
syntax region wergeDiffChange start=/<<<<</ end=/>>>>>/ contains=wergeDiffRm,wergeDiffAdd
syntax region wergeDiffRm start=/<<<<</hs=e+1 end=/|||||/he=b-1,me=b-1 contained
syntax region wergeDiffAdd start=/|||||/hs=e+1 end=/>>>>>/he=b-1,me=b-1 contained
highlight default link wergeDiffChange Comment
highlight default link wergeDiffRm Removed
highlight default link wergeDiffAdd Added