Skip to content

Commit 3102227

Browse files
committed
Switch Vim string styles, apply a minor python fix
1 parent e8f338d commit 3102227

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

ftplugin/vim/switch.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ endif
55
let b:switch_definitions =
66
\ [
77
\ g:switch_builtins.vim_script_local_function,
8+
\ g:switch_builtins.vim_string_style,
89
\ ]

plugin/switch.vim

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ let g:switch_builtins =
228228
\ '\<s:\(\h\w\+\)(': '<SID>\1(',
229229
\ '<SID>\(\h\w\+\)(': 's:\1(',
230230
\ },
231+
\ 'vim_string_style': {
232+
\ '\$"\(\%([^"\\]\|\\.\)*\)"': '''\1''',
233+
\ '''\(\%([^''\\]\|\\.\)*\)''': '"\1"',
234+
\ '\%([^$]\|^\)\zs"\(\%([^"\\]\|\\.\)*\)"': '$"\1"',
235+
\ },
231236
\ 'markdown_task_item': {
232237
\ '^\(\s*\)- \[ \] \(.*\)': '\1- [x] \2',
233238
\ '^\(\s*\)- \[x\] \(.*\)': '\1- [ ] \2',
@@ -254,9 +259,9 @@ let g:switch_builtins =
254259
\ },
255260
\ },
256261
\ 'python_string_style': {
257-
\ 'f"\(\%([^"\\]\|\\.\)*\)"': '''\1''',
258-
\ '''\(\%([^''\\]\|\\.\)*\)''': '"\1"',
259-
\ 'f\@!"\(\%([^"\\]\|\\.\)*\)"': 'f"\1"',
262+
\ 'f"\(\%([^"\\]\|\\.\)*\)"': '''\1''',
263+
\ '''\(\%([^''\\]\|\\.\)*\)''': '"\1"',
264+
\ '\%\([^f]\|^\)\zs"\(\%([^"\\]\|\\.\)*\)"': 'f"\1"',
260265
\ },
261266
\ 'python_asserts': {
262267
\ '\<assertTrue\>': 'assertFalse',

spec/plugin/vim_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,17 @@
1818
call s:TestFunction()
1919
EOF
2020
end
21+
22+
specify "string type" do
23+
set_file_contents 'let foo = "bar?"'
24+
25+
vim.search('bar').switch
26+
assert_file_contents 'let foo = $"bar?"'
27+
28+
vim.switch
29+
assert_file_contents "let foo = 'bar?'"
30+
31+
vim.switch
32+
assert_file_contents 'let foo = "bar?"'
33+
end
2134
end

0 commit comments

Comments
 (0)