-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for any case, and Title Case #1
Open
JoseConseco
wants to merge
5
commits into
icatalina:master
Choose a base branch
from
JoseConseco:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−31
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
casechange casechange.txt /*casechange* | ||
casechange-about casechange.txt /*casechange-about* | ||
casechange-keymaps casechange.txt /*casechange-keymaps* | ||
casechange-usage casechange.txt /*casechange-usage* | ||
casechange.txt casechange.txt /*casechange.txt* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
-- casechange.vim - Lets role the cases | ||
-- Maintainer: Ignacio Catalina | ||
-- Version: 1.0 | ||
-- | ||
-- License: | ||
-- Copyright (c) Ignacio Catalina. Distributed under the same terms as Vim itself. | ||
-- See :help license | ||
-- | ||
|
||
local my_plugin = {} | ||
|
||
local function with_defaults(options) | ||
return { | ||
name = options.name or "John Doe" | ||
} | ||
end | ||
|
||
|
||
function my_plugin.setup(options) | ||
my_plugin.options = with_defaults(options) | ||
end | ||
|
||
function my_plugin.is_configured() | ||
return my_plugin.options ~= nil | ||
end | ||
|
||
-- escape terminal control characters | ||
local function t(str) | ||
return vim.api.nvim_replace_termcodes(str, true, true, true) | ||
end | ||
|
||
-- \C - case sensitive | ||
-- \v - magic mode (no need for \) | ||
local dash = vim.regex [==[\v^[a-z0-9]+(-+[a-z0-9]+)+$]==] -- [==['^[a-z0-9]+(-+[a-z0-9]+)+$]==] -- dash-case | ||
local camel = vim.regex [==[\v\C^[a-z][a-z0-9]*([A-Z][a-z0-9]*)*$]==] -- camelCase | ||
local snake = vim.regex [==[\v\C^[a-z0-9]+(_+[a-z0-9]+)*$]==] -- snake_case | ||
local upper = vim.regex [==[\v\C^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$]==] -- UPPER_CASE | ||
local pascal = vim.regex [==[\v\C^[A-Z][a-z0-9]*([A-Z0-9][a-z0-9]*)*$]==] -- PascalCase | ||
local title = vim.regex [==[\v\C^[A-Z][a-z0-9]*( [A-Z][a-z0-9]+)*$]==] -- Title Case | ||
local any = vim.regex [==[\v\C^[a-zA-Z][a-zA-Z0-9]*((\W)[a-zA-Z][a-zA-Z0-9]+)*$]==] -- -case etc. | ||
|
||
local substitute = function(args) | ||
return vim.api.nvim_call_function("substitute", args) | ||
end | ||
|
||
local toupper = function(args) | ||
return vim.api.nvim_call_function("toupper", args) | ||
end | ||
|
||
local tolower = function(args) | ||
return vim.api.nvim_call_function("tolower", args) | ||
end | ||
|
||
|
||
function _G.casechange() | ||
vim.cmd [[noau normal! "zd]] | ||
-- vim.pretty_print(vim.api.nvim_get_mode()) | ||
local str = vim.fn.getreg("z") | ||
|
||
-- local start = vim.api.nvim_buf_get_mark(0, '<') | ||
-- local finish = vim.api.nvim_buf_get_mark(0, '>') | ||
|
||
local sub | ||
if dash:match_str(str) then | ||
sub = substitute({ str, [[\v-+([a-z])]], [[\U\1]], 'g' }) -- camelCase | ||
elseif camel:match_str(str) then | ||
sub = substitute({ str, [[^.*$]], [[\u\0]], '' }) -- PascalCase | ||
elseif upper:match_str(str) then | ||
local tit_under = substitute({ str, [[\v([A-Z])([A-Z]*)]], [[\1\L\2]], 'g' }) | ||
sub = substitute({ tit_under, '_', ' ', 'g' }) -- Title Case | ||
elseif pascal:match_str(str) then | ||
local res = substitute({ str, [==[\C^\@<![A-Z]]==], [[_\0]], 'g' }) | ||
sub = toupper({ res }) -- UPPER_CASE | ||
elseif title:match_str(str) then | ||
local res = substitute({ str, ' ', '_', 'g' }) | ||
sub = tolower({ res }) -- snake_case | ||
elseif snake:match_str(str) then | ||
sub = substitute({ str, [[\v_+]], '-', 'g' }) -- dash-case | ||
elseif any:match_str(str) then -- wurst case scenario | ||
local res = substitute({ str, [[\v(\W)([a-z])]], [[_\U\2]], 'g' }) -- snake_case | ||
sub = tolower({ res }) | ||
end | ||
|
||
vim.fn.setreg("z", sub) | ||
vim.cmd('normal! ' .. [["zPv`[]]) -- FIXED: by using: d - rather than c at fun beg | ||
end | ||
|
||
vim.keymap.set('v', '~', function() casechange() end, { noremap = true, silent = true, desc = 'CaseChange Plug' }) | ||
-- vnoremap ~ "<C-R>=casechange(@z)<CR><Esc>v`[ | ||
|
||
my_plugin.options = nil | ||
return my_plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! thanks for your contribution!
Could you please make this look like it is part of the same repo? 🙇