Vim-NLS

1. Intro

This plugin can help you quikly convert the nls copy to nls key,
such as "this is a nls", can convert to below keys list as you wanto.

  1. "F_THIS_IS_A_NLS",
  2. "mc.inbox_F_THIS_IS_A_NLS",
  3. "mc_this_is_a_nls",
  4. "mc.this_is_a_nls"

2. useage

This plugin support the following key binding:
nj: it convert the copy in the double quote to the first style.
nj: it convert to second style.
nk: it convert to three style
nk: it convert to four style.

3. bug-fix

  1. remove , and : from the string befor handle.

4. vim-nls code

vim-nls/

  • autoload/
    nls.vim
" this is for nls convert "  

let g:nls_sub_length = 8
let s:store_single = @t 
let s:store_double = @t 
let s:store_visual = @@

" handle NLS 
function! g:nls#ChangeNls(quote, prefix)
  let l:reg = 't'

  if a:quote ==# 'v'
    execute 'norm! `<v`>y'
    let l:reg_save = getreg('@')
    let s:store_visual = l:reg_save
  elseif a:quote ==# '"' 
    execute 'norm! "'. l:reg . 'yi"' 
    let l:reg_save = getreg(l:reg)
    let s:store_double = l:reg_save
  elseif a:quote ==# "'"
    execute 'norm! "' . l:reg . "yi'"
    let l:reg_save = getreg(l:reg)
    let s:store_single = l:reg_save
  endif 

  let l:words = split(l:reg_save)[0:g:nls_sub_length - 1]
  call map(l:words, {key, val -> split(val,"'")[0]})

  let l:format_str = s:FormatString(l:words, a:prefix)
  echo l:format_str

  call setreg(l:reg, l:format_str)
  if a:quote ==# 'v'
    execute 'norm! gv'
    execute 'norm! "' . l:reg . 'p'
    call setreg(l:reg, s:store_visual)
  elseif a:quote ==# '"'
    execute 'norm! vi"'
    execute 'norm! "'. l:reg . 'p'
    call setreg(l:reg, s:store_double)
  elseif a:quote ==# "'"
    execute "norm! vi'"
    execute 'norm! "' .l:reg . 'p'
    call setreg(l:reg, s:store_single)
  endif
endfunction

" format string
function! s:FormatString(words, prefix)
  if a:prefix ==# 'F_' || a:prefix ==# 'mc.inbox_F_'
    let l:Handler = function('toupper')
  elseif a:prefix ==# 'mc_' || a:prefix ==# 'mc.' 
    let l:Handler = function('tolower')
  endif

  let l:format_str = a:prefix . Handler(join(a:words,'_'))
  return l:format_str
endfunction

  • plugin/
    nls.vim
" commands
command! -nargs=0 ChangeDoubleF call g:nls#ChangeNls('"', 'F_')
command! -nargs=0 ChangeDoubleM call g:nls#ChangeNls('"', 'mc_')
command! -nargs=0 ChangeSingleF call g:nls#ChangeNls("'", 'F_')
command! -nargs=0 ChangeSingleM call g:nls#ChangeNls("'", 'mc_')

" key maps
nnoremap nj :call g:nls#ChangeNls('"', 'F_')<cr>
nnoremap <leader>nj :call g:nls#ChangeNls('"', 'mc.inbox_F_')<cr>
nnoremap njj :call g:nls#ChangeNls('"', 'mc_')<cr>
nnoremap <leader>njj :call g:nls#ChangeNls('"', 'mc.')<cr>
nnoremap nk :call g:nls#ChangeNls("'", 'F_')<cr>
nnoremap <leader>nk :call g:nls#ChangeNls("'", 'mc.inbox_F_')<cr>
nnoremap nkk :call g:nls#ChangeNls("'", 'mc_')<cr>
nnoremap <leader>nkk :call g:nls#ChangeNls("'", 'mc.')<cr>
vnoremap nj :call g:nls#ChangeNls('v', 'F_')<cr>
vnoremap <leader>nj :call g:nls#ChangeNls('v', 'mc.inbox_F_')<cr>
vnoremap njj :call g:nls#ChangeNls('v', 'mc_')<cr>
vnoremap <leader>njj :call g:nls#ChangeNls('v', 'mc.')<cr>

  • ftPlugin/
    javascript.vim
  • doc/
    nls.txt
*nls.txt*  handle DSR nls plugin
*nls"

================================================================
CONTENTS                                        *nls-contents*
1. introduction....................................|nls-intro|
2. useage..........................................|nls-usage|

================================================================
1. Intro                                           *nls-intro*
This plugin can help you quily convert the nls copy to nls key, 
such as "this is a nls", can convert to below keys list as you wanto.
 1. "F_THIS_IS_A_NLS",
 2. "mc.inbox_F_THIS_IS_A_NLS",
 3. "mc_this_is_a_nls",
 4. "mc.this_is_a_nls"

2. useage                                           *nls-usage*
This plugin support the following key binding:
  nj: it convert the copy in the double quote to the first style.
  <leader>nj: it convert to second style.
  nk: it convert to three style
  <leaser>nk: it convert to four style.
3. bug-fix
  1. remove , and : from the string befor handle.


vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

tags

nls-contents	nls.txt	/*nls-contents*
nls-intro	nls.txt	/*nls-intro*
nls-usage	nls.txt	/*nls-usage*
nls.txt	nls.txt	/*nls.txt*
posted @ 2023-02-08 20:01  箫笛  阅读(24)  评论(0)    收藏  举报