diff options
author | Cody Hiar <codyfh@gmail.com> | 2018-03-12 12:26:43 -0600 |
---|---|---|
committer | Cody Hiar <codyfh@gmail.com> | 2018-03-12 12:26:43 -0600 |
commit | 4591084bd038cdb3f6e3542af810b568f1e538e7 (patch) | |
tree | 9795122b7c18cfab1668fe53a069a8f11d7e10f1 /plugin/vim-options.vim | |
parent | a2798013c5267b3f2b82a3727d97a719adc4ae0c (diff) |
Map F4 to Generate Django Choices
Diffstat (limited to 'plugin/vim-options.vim')
-rw-r--r-- | plugin/vim-options.vim | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/plugin/vim-options.vim b/plugin/vim-options.vim index f9e98ea..addfdc7 100644 --- a/plugin/vim-options.vim +++ b/plugin/vim-options.vim @@ -213,6 +213,30 @@ nnoremap g2 V:s/-/ /g<CR>:noh<CR> nnoremap g3 ^v$:s/\%V /-/g<CR>:noh<CR> nnoremap g4 V:s/ /_/g<CR>:noh<CR> nnoremap g5 ^v$:s/\%V /_/g<CR>:noh:<CR> +function! WordsToChoices() + python3 << EOF +import vim +buf = vim.current.buffer +(lnum1, col1) = buf.mark('<') +(lnum2, col2) = buf.mark('>') +lspaces = len(buf[lnum1]) - len(buf[lnum1].lstrip(' ')) +start_choices = lnum1 + (lnum2 - lnum1) +end_choices = lnum2 + (lnum2 - lnum1) +end_line = end_choices + 1 +choices_and_values = [] +for line_num in range(lnum1-1, lnum2): + word = buf[line_num].strip() + line = buf[line_num] + buf[line_num] = "{} = '{}'".format(line.upper(), word) + choices_and_values.append((word.upper(), "'{}'".format(word))) +buf[lnum2] = '{}TEST_CHOICES = ('.format(' ' * lspaces) +for line_num in range(start_choices + 1, end_choices + 2): + choice, value = choices_and_values.pop(0) + buf[line_num] = "{}({}, ({})),".format(' ' * (lspaces + 4), choice, value) +buf[end_choices + 2] = '{})'.format(' ' * lspaces) +EOF +endfunction +nnoremap <F4> `>o<ESC>p`]o<ESC>`<:call WordsToChoices()<CR> "----------------------------------------------------------------------------------------------------------------------- |