Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalnode committed Apr 15, 2022
0 parents commit 2ece48c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# zenkaku.vim
Adds commands to find and replace zenkaku characters with normal character equivalents.

[wtf is a zenkaku?](https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_\(Unicode_block\))

## Features
The plugin adds the following commands:

| Command | Effect |
| -------------------- | ------------------------------------------------------------------------ |
| `:FixZenkakuDigits` | Replace all zenkaku digits with ascii equivalents |
| `:FixZenkakuUpper` | Replace all zenkaku upper-case with ascii equivalents |
| `:FixZenkakuLower` | Replace all zenkaku lower-case with ascii equivalents |
| `:FixZenkakuOthers` | Replace all zenkaku special characters with ascii equivalents |
| `:FixZenkakuLetters` | Combine `:FixZenkakuLower` and `:FixZenkakuUpper` |
| `:FixZenkaku` | Combine `:FixZenkakuDigits`, `FixZenkakuLetters` and `:FixZenkakuOthers` |

## Installation
As with most vim plugins, [vim-plug](https://github.com/junegunn/vim-plug) is a handy way to
install it.
55 changes: 55 additions & 0 deletions plugin/zenkaku.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
" vim:set ft=vim et sw=2:
let s:digits = [
\ ['', '0'], ['', '1'], ['', '2'], ['', '3'], ['', '4'],
\ ['', '5'], ['', '6'], ['', '7'], ['', '8'], ['', '9'],
\]

let s:upper = [
\ ['', 'A'], ['', 'B'], ['', 'C'], ['', 'D'], ['', 'E'],
\ ['', 'F'], ['', 'G'], ['', 'H'], ['', 'I'], ['', 'J'],
\ ['', 'K'], ['', 'L'], ['', 'M'], ['', 'N'], ['', 'O'],
\ ['', 'P'], ['', 'Q'], ['', 'R'], ['', 'S'], ['', 'T'],
\ ['', 'U'], ['', 'V'], ['', 'W'], ['', 'X'], ['', 'Y'],
\ ['', 'Z'],
\]

let s:lower = [
\ ['', 'a'], ['', 'b'], ['', 'c'], ['', 'd'], ['', 'e'],
\ ['', 'f'], ['', 'g'], ['', 'h'], ['', 'i'], ['', 'j'],
\ ['', 'k'], ['', 'l'], ['', 'm'], ['', 'n'], ['', 'o'],
\ ['', 'p'], ['', 'q'], ['', 'r'], ['', 's'], ['', 't'],
\ ['', 'u'], ['', 'v'], ['', 'w'], ['', 'x'], ['', 'y'],
\ ['', 'z'],
\]

let s:others = [
\ ['', '!'], ['', '"'], ['', '#'], ['', '$'], ['', '%'],
\ ['', '\&'], ["", "'"], ['', '('], ['', ')'], ['', '*'],
\ ['', '+'], ['', ','], ['', '-'], ['', '.'], ['', '\/'],
\ ['', ':'], ['', ';'], ['', '<'], ['', '='], ['', '>'],
\ ['', '?'], ['', '@'], ['', '['], ['', '\'], ['', ']'],
\ ['', '^'], ['_', '_'], ['', '`'], ['', '{'], ['', '|'],
\ ['', '}'], ['', '~'], ['', '«'], ['', '»'], ['', '.'],
\ ['', ','], ['', '-'], ['] ', ']'], ['', '¢'], ['', '£'],
\ ['', '¥'], ['', ''],
\]

function s:ReplaceWithMap(replacementMap)
for pair in a:replacementMap
execute '%s/\C' . pair[0] . '/' . pair[1] . '/g'
endfor
endfunction

command FixZenkakuDigits call s:ReplaceWithMap(s:digits)
command FixZenkakuUpper call s:ReplaceWithMap(s:upper)
command FixZenkakuLower call s:ReplaceWithMap(s:lower)
command FixZenkakuOthers call s:ReplaceWithMap(s:others)

command FixZenkakuLetters
\ execute 'FixZenkakuUpper'
\ | execute 'FixZenkakuLower'

command FixZenkaku
\ execute 'FixZenkakuDigits'
\ | execute 'FixZenkakuLetters'
\ | execute 'FixZenkakuOthers'

0 comments on commit 2ece48c

Please sign in to comment.