├── README.md
├── doc
├── casechange.txt
└── tags
├── lua
└── casechange.lua
└── plugin
└── casechange.vim
/README.md:
--------------------------------------------------------------------------------
1 | This fork add support for: `aNy-CasE` or `Any cAse` - always converted to snake_case
2 | Also I added support for new: `Title Case`
3 |
4 |
7 |
8 | # casechange.vim
9 |
10 | 
11 |
12 | ## Introduction
13 |
14 | `CaseChange` is a plugin for rotating through different casing styles. It aims to
15 | fix the behaviour of `~` in visual mode.
16 |
17 | ## Usage
18 |
19 | Select the block of text you want to apply `CaseChange` to and press `~`
20 |
21 | ```vim
22 | helloWorld
23 | HelloWorld
24 | HELLO_WORLD
25 | hello_world
26 | hello-world
27 | ```
28 |
29 | For example, if you wish to change the current word, you could press `viw~` and then keep
30 | pressing `~` until you get to the right case.
31 |
32 | ## Keymaps
33 |
34 | The only keymap that this plugin sets is `~`, you can prevent this by setting:
35 |
36 | ```vim
37 | let g:casechange_nomap = 1
38 | ```
39 |
40 | ## License
41 |
42 | Copyright (c) Ignacio Catalina. Distributed under the same terms as Vim itself. See `:help license`.
43 |
--------------------------------------------------------------------------------
/doc/casechange.txt:
--------------------------------------------------------------------------------
1 | *casechange.txt* Lets roll the cases!
2 |
3 | Author: Ignacio Catalina
4 | License: Same terms as Vim itself (see |license|)
5 |
6 | Version: 1.0
7 |
8 | INTRODUCTION *casechange*
9 |
10 | Casechange is a plugin for rotating through different casing styles. It aims to
11 | fix the behaviour of ~ in visual mode.
12 |
13 | USAGE *casechange-usage*
14 |
15 | Select the piece of text you want to apply CaseChange to and press ~
16 |
17 | helloWorld
18 | HelloWorld
19 | HELLO_WORLD
20 | hello_world
21 | hello-world
22 |
23 | For example, if you wish to change the current word, you could press viw~ and
24 | then keep pressing ~ until you get to the right case.
25 |
26 | KEYMAPS *casechange-keymaps*
27 |
28 | The only keymap that this plugin sets is ~, you can prevent this by setting:
29 |
30 | let g:casechange_nomap = 1
31 |
32 | ABOUT *casechange-about*
33 |
34 | Grab the latest version or report a bug on GitHub:
35 |
36 | http://github.com/icatalina/vim-case-change
37 |
38 |
--------------------------------------------------------------------------------
/doc/tags:
--------------------------------------------------------------------------------
1 | casechange casechange.txt /*casechange*
2 | casechange-about casechange.txt /*casechange-about*
3 | casechange-keymaps casechange.txt /*casechange-keymaps*
4 | casechange-usage casechange.txt /*casechange-usage*
5 | casechange.txt casechange.txt /*casechange.txt*
6 |
--------------------------------------------------------------------------------
/lua/casechange.lua:
--------------------------------------------------------------------------------
1 | -- casechange.vim - Lets role the cases
2 | -- Maintainer: Ignacio Catalina
3 | -- Version: 1.0
4 | --
5 | -- License:
6 | -- Copyright (c) Ignacio Catalina. Distributed under the same terms as Vim itself.
7 | -- See :help license
8 | --
9 |
10 | local my_plugin = {}
11 |
12 | local function with_defaults(options)
13 | return {
14 | name = options.name or "John Doe"
15 | }
16 | end
17 |
18 |
19 | function my_plugin.setup(options)
20 | my_plugin.options = with_defaults(options)
21 | end
22 |
23 | function my_plugin.is_configured()
24 | return my_plugin.options ~= nil
25 | end
26 |
27 | -- escape terminal control characters
28 | local function t(str)
29 | return vim.api.nvim_replace_termcodes(str, true, true, true)
30 | end
31 |
32 | -- \C - case sensitive
33 | -- \v - magic mode (no need for \)
34 | local dash = vim.regex [==[\v^[a-z0-9]+(-+[a-z0-9]+)+$]==] -- [==['^[a-z0-9]+(-+[a-z0-9]+)+$]==] -- dash-case
35 | local camel = vim.regex [==[\v\C^[a-z][a-z0-9]*([A-Z][a-z0-9]*)*$]==] -- camelCase
36 | local snake = vim.regex [==[\v\C^[a-z0-9]+(_+[a-z0-9]+)*$]==] -- snake_case
37 | local upper = vim.regex [==[\v\C^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$]==] -- UPPER_CASE
38 | local pascal = vim.regex [==[\v\C^[A-Z][a-z0-9]*([A-Z0-9][a-z0-9]*)*$]==] -- PascalCase
39 | local title = vim.regex [==[\v\C^[A-Z][a-z0-9]*( [A-Z][a-z0-9]+)*$]==] -- Title Case
40 | local any = vim.regex [==[\v\C^[a-zA-Z][a-zA-Z0-9]*((\W)[a-zA-Z][a-zA-Z0-9]+)*$]==] -- -case etc.
41 |
42 | local substitute = function(args)
43 | return vim.api.nvim_call_function("substitute", args)
44 | end
45 |
46 | local toupper = function(args)
47 | return vim.api.nvim_call_function("toupper", args)
48 | end
49 |
50 | local tolower = function(args)
51 | return vim.api.nvim_call_function("tolower", args)
52 | end
53 |
54 |
55 | function _G.casechange()
56 | vim.cmd [[noau normal! "zd]]
57 | -- vim.pretty_print(vim.api.nvim_get_mode())
58 | local str = vim.fn.getreg("z")
59 |
60 | -- local start = vim.api.nvim_buf_get_mark(0, '<')
61 | -- local finish = vim.api.nvim_buf_get_mark(0, '>')
62 |
63 | local sub
64 | if dash:match_str(str) then
65 | sub = substitute({ str, [[\v-+([a-z])]], [[\U\1]], 'g' }) -- camelCase
66 | elseif camel:match_str(str) then
67 | sub = substitute({ str, [[^.*$]], [[\u\0]], '' }) -- PascalCase
68 | elseif upper:match_str(str) then
69 | local tit_under = substitute({ str, [[\v([A-Z])([A-Z]*)]], [[\1\L\2]], 'g' })
70 | sub = substitute({ tit_under, '_', ' ', 'g' }) -- Title Case
71 | elseif pascal:match_str(str) then
72 | local res = substitute({ str, [==[\C^\@=casechange(@z)v`[
90 |
91 | my_plugin.options = nil
92 | return my_plugin
93 |
--------------------------------------------------------------------------------
/plugin/casechange.vim:
--------------------------------------------------------------------------------
1 | " casechange.vim - Lets role the cases
2 | " Maintainer: Ignacio Catalina
3 | " Version: 1.0
4 | "
5 | " Installation:
6 | " Place in either ~/.vim/plugin/casechange.vim (to load at start up) or
7 | " ~/.vim/autoload/casechange.vim (to load automatically as needed).
8 | "
9 | " License:
10 | " Copyright (c) Ignacio Catalina. Distributed under the same terms as Vim itself.
11 | " See :help license
12 | "
13 | let s:casechange = luaeval('require("casechange")')
14 |
15 | " if s:casechange.is_configured()
16 | " Neovim does not expose a lua API to create commands yet
17 | " command! MyPluginGreet call s:casechange.greet()
18 | " endif
19 |
--------------------------------------------------------------------------------