2018-02-19 22:07:04 +08:00
"=============================================================================
" edit.vim --- SpaceVim edit layer
2023-03-26 13:44:47 +08:00
" Copyright (c) 2016-2023 Wang Shidong & Contributors
2022-03-27 13:38:54 +08:00
" Author: Wang Shidong < wsdjeg@outlook.com >
2018-02-19 22:07:04 +08:00
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
2022-02-05 11:13:50 +08:00
""
" @section edit, layers-edit
" @parentsection layers
" The `edit` layer provides basic feature for editing files.
" This layer is loaded by default. To disable this layer:
" >
" [[layers]]
" name = 'edit'
" enable = false
" <
" @subsection Configuration
" 1. `autosave_timeout`: set the timeoutlen of autosave plugin. By default it
" is 0. And autosave is disabled. timeoutlen must be given in millisecods and
" can't be > 100*60*1000 (100 minutes) or < 1000 (1 second). For example,
" setup timer with 5 minutes:
" >
" [[layers]]
" name = 'edit'
" autosave_timeout = 300000
" <
" 2. `autosave_events`: set the events on which autosave will perform a save.
" This option is an empty list by default. you can trigger saving based
" on vim's events, for example:
" >
" [[layers]]
" name = 'edit'
" autosave_events = ['InsertLeave', 'TextChanged']
" <
" 3. `autosave_all_buffers`: By default autosave plugin only save current buffer.
" If you want to save all buffers automatically. Set this option to `true`.
" >
" [[layers]]
" name = 'edit'
" autosave_all_buffers = true
" <
2022-02-06 13:12:15 +08:00
" 4. `autosave_location`: set the directory where to save changed files. By
" default it is empty string, that means saving to the original file. If this
" option is not an empty string. files will me saved to that directory
" automatically. and the format is:
" >
" autosave_location/path+=to+=filename.ext.backup
" <
2022-04-27 22:13:32 +08:00
" 5. `enable_hop`: by default, spacevim use easymotion plugin. and if you are
" using neovim 0.6.0 or above, hop.nvim will be enabled. You can disabled this
" plugin and still using easymotion.
"
" @subsection key bindings
"
" The `edit` layer also provides many key bindings:
" >
" key binding description
" SPC x c count in the selection region
" <
"
" The following key binding is to jump to targets. The default plugin is
" `easymotion`, and if you are using neovim 0.6.0 or above. The `hop.nvim` will
" be used.
" >
" key binding description
" SPC j j jump or select a character
" SPC j J jump to suite of two characters
" SPC j l jump or select to a line
" SPC j w jump to a word
" SPC j u jump to a url
" <
2018-02-19 22:07:04 +08:00
2017-07-17 07:08:53 +08:00
scriptencoding utf -8
2022-02-05 11:13:50 +08:00
if exists ( 's:autosave_timeout' )
finish
endif
2017-07-01 01:32:14 -05:00
let s :PASSWORD = SpaceVim #api #import ( 'password' )
let s :NUMBER = SpaceVim #api #import ( 'data#number' )
let s :LIST = SpaceVim #api #import ( 'data#list' )
2019-09-05 14:10:49 +08:00
let s :VIM = SpaceVim #api #import ( 'vim' )
2020-10-31 15:52:34 +08:00
let s :CMP = SpaceVim #api #import ( 'vim#compatible' )
2021-04-10 20:10:16 +08:00
let s :BUFFER = SpaceVim #api #import ( 'vim#buffer' )
2022-03-28 12:03:17 +08:00
let s :HI = SpaceVim #api #import ( 'vim#highlight' )
2017-07-01 01:32:14 -05:00
2022-02-05 11:13:50 +08:00
let s :autosave_timeout = 0
let s :autosave_events = []
let s :autosave_all_buffers = 0
2022-02-06 13:12:15 +08:00
let s :autosave_location = ''
2022-04-27 22:13:32 +08:00
let s :enable_hop = 1
2022-02-05 11:13:50 +08:00
2021-08-10 19:59:42 +08:00
function ! SpaceVim #layers #edit #health ( ) abort
call SpaceVim #layers #edit #plugins ( )
call SpaceVim #layers #edit #config ( )
return 1
endfunction
2017-01-14 19:49:19 +08:00
function ! SpaceVim #layers #edit #plugins ( ) abort
2017-12-06 16:15:18 +08:00
let plugins = [
2020-06-13 14:06:35 +08:00
\ [g :_spacevim_root_dir . 'bundle/vim-surround' ],
\ [g :_spacevim_root_dir . 'bundle/vim-repeat' ],
\ [g :_spacevim_root_dir . 'bundle/vim-emoji' ],
2023-03-28 23:43:55 +08:00
\ [g :_spacevim_root_dir . 'bundle/vim-grammarous' , {'merged' : 0 }],
2020-06-13 14:06:35 +08:00
\ [g :_spacevim_root_dir . 'bundle/vim-expand-region' , { 'loadconf' : 1 }],
\ [g :_spacevim_root_dir . 'bundle/vim-textobj-user' ],
\ [g :_spacevim_root_dir . 'bundle/vim-textobj-indent' ],
\ [g :_spacevim_root_dir . 'bundle/vim-textobj-line' ],
\ [g :_spacevim_root_dir . 'bundle/vim-table-mode' ],
\ [g :_spacevim_root_dir . 'bundle/vim-textobj-entire' ],
\ [g :_spacevim_root_dir . 'bundle/wildfire.vim' , {'on_map' : '<Plug>(wildfire-' }],
\ [g :_spacevim_root_dir . 'bundle/editorconfig-vim' , { 'merged' : 0 , 'if' : has ( 'python' ) | | has ( 'python3' ) }],
2020-06-13 20:32:34 +08:00
\ [g :_spacevim_root_dir . 'bundle/vim-jplus' , { 'on_map' : '<Plug>(jplus' }],
2020-06-13 14:06:35 +08:00
\ [g :_spacevim_root_dir . 'bundle/tabular' , { 'merged' : 0 }],
2021-05-02 21:20:03 +08:00
\ ['andrewradev/splitjoin.vim' , { 'on_cmd' :['SplitjoinJoin' , 'SplitjoinSplit' ], 'merged' : 0 , 'loadconf' : 1 }],
2017-12-06 16:15:18 +08:00
\ ]
2022-06-10 16:31:14 +08:00
if has ( 'nvim-0.6.0' ) && s :enable_hop
2022-04-27 22:13:32 +08:00
call add ( plugins , [g :_spacevim_root_dir . 'bundle/hop.nvim' , { 'merged' : 0 , 'loadconf' : 1 }])
else
call add ( plugins , [g :_spacevim_root_dir . 'bundle/vim-easymotion' , { 'merged' : 0 }])
call add ( plugins , [g :_spacevim_root_dir . 'bundle/vim-easyoperator-line' , { 'merged' : 0 }])
endif
2017-12-06 16:15:18 +08:00
if executable ( 'fcitx' )
2020-06-13 14:06:35 +08:00
call add ( plugins , [g :_spacevim_root_dir . 'bundle/fcitx.vim' , { 'on_event' : 'InsertEnter' }])
2017-12-06 16:15:18 +08:00
endif
2019-04-13 22:12:33 +08:00
if g :spacevim_enable_bepo_layout
2020-06-13 14:06:35 +08:00
call add ( plugins , [g :_spacevim_root_dir . 'bundle/vim-bepo' , { 'merged' : 0 }])
2019-04-13 22:12:33 +08:00
endif
2021-04-13 23:24:58 +08:00
if s :CMP .has ( 'python3' ) | | s :CMP .has ( 'python' )
2020-10-31 15:52:34 +08:00
call add ( plugins , [g :_spacevim_root_dir . 'bundle/vim-mundo' , { 'on_cmd' : 'MundoToggle' }])
else
call add ( plugins , [g :_spacevim_root_dir . 'bundle/undotree' , { 'on_cmd' : 'UndotreeToggle' }])
endif
2017-12-06 16:15:18 +08:00
return plugins
2017-01-14 19:49:19 +08:00
endfunction
2022-02-05 11:13:50 +08:00
function ! SpaceVim #layers #edit #set_variable ( var ) abort
let s :autosave_timeout = get ( a :var , 'autosave_timeout' , s :autosave_timeout )
let s :autosave_events = get ( a :var , 'autosave_events' , s :autosave_events )
let s :autosave_all_buffers = get ( a :var , 'autosave_all_buffers' , s :autosave_all_buffers )
2022-02-06 13:12:15 +08:00
let s :autosave_location = get ( a :var , 'autosave_location' , s :autosave_location )
2022-04-27 22:13:32 +08:00
let s :enable_hop = get ( a :var , 'enable_hop' , s :enable_hop )
2022-02-05 11:13:50 +08:00
endfunction
function ! SpaceVim #layers #edit #get_options ( ) abort
return ['autosave_all_buffers' , 'autosave_timeout' , 'autosave_events' ]
endfunction
2017-01-14 19:49:19 +08:00
function ! SpaceVim #layers #edit #config ( ) abort
2022-02-05 11:13:50 +08:00
" autosave plugins options
let autosave_opt = {
\ 'timeoutlen' : s :autosave_timeout ,
\ 'save_all_buffers' : s :autosave_all_buffers ,
2022-02-06 13:12:15 +08:00
\ 'backupdir' : s :autosave_location ,
2022-02-05 11:13:50 +08:00
\ 'event' : s :autosave_events ,
\ }
2023-07-02 18:57:09 +08:00
2022-09-27 23:54:04 +08:00
if has ( 'nvim-0.7.0' )
lua require ( 'spacevim.plugin.autosave' ) .config ( vim .api .nvim_eval ( 'autosave_opt' ) )
else
call SpaceVim #plugins #autosave #config ( autosave_opt )
endif
2022-02-05 11:13:50 +08:00
2017-12-06 16:15:18 +08:00
let g :multi_cursor_next_key = get ( g :, 'multi_cursor_next_key' , '<C-n>' )
let g :multi_cursor_prev_key = get ( g :, 'multi_cursor_prev_key' , '<C-m>' )
let g :multi_cursor_skip_key = get ( g :, 'multi_cursor_skip_key' , '<C-x>' )
let g :multi_cursor_quit_key = get ( g :, 'multi_cursor_quit_key' , '<Esc>' )
let g :user_emmet_install_global = 0
let g :user_emmet_mode = 'a'
let g :user_emmet_settings = {
2017-12-12 01:10:54 +09:00
\ 'javascript' : {
2023-07-02 18:57:09 +08:00
\ 'extends' : 'jsx' ,
\ },
\ 'jsp' : {
\ 'extends' : 'html' ,
\ },
\ }
2017-12-12 01:10:54 +09:00
2017-12-06 16:15:18 +08:00
"noremap <SPACE> <Plug>(wildfire-fuel)
vnoremap < C - SPACE > < Plug > ( wildfire - water )
let g :wildfire_objects = ["i'" , 'i"' , 'i)' , 'i]' , 'i}' , 'ip' , 'it' ]
2017-11-15 22:41:34 +09:00
" osyo-manga/vim-jplus {{{
nmap < silent > J < Plug > ( jplus )
vmap < silent > J < Plug > ( jplus )
" }}}
2020-10-31 15:52:34 +08:00
2021-04-13 23:24:58 +08:00
if s :CMP .has ( 'python3' ) | | s :CMP .has ( 'python' )
2020-10-31 15:52:34 +08:00
nnoremap < silent > < F7 > :MundoToggle < CR >
else
nnoremap < silent > < F7 > :UndotreeToggle < CR >
endif
2017-12-06 16:15:18 +08:00
let g :_spacevim_mappings_space .x = {'name' : '+Text' }
let g :_spacevim_mappings_space .x .a = {'name' : '+align' }
let g :_spacevim_mappings_space .x .d = {'name' : '+delete' }
let g :_spacevim_mappings_space .x .i = {'name' : '+change symbol style' }
nnoremap < silent > < Plug > CountSelectionRegion :call < SID > count_selection_region ( ) < Cr >
xnoremap < silent > < Plug > CountSelectionRegion :< C - u > call < SID > count_selection_region ( ) < Cr >
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'c' ], '<Plug>CountSelectionRegion' , 'count in the selection region' , 0 , 1 )
2019-10-03 12:32:30 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '#' ], 'Tabularize /#' , 'align-region-at-#' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '%' ], 'Tabularize /%' , 'align-region-at-%' , 1 , 1 )
2019-03-10 08:34:20 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '&' ], 'Tabularize /&' , 'align-region-at-&' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '(' ], 'Tabularize /(' , 'align-region-at-(' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , ')' ], 'Tabularize /)' , 'align-region-at-)' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '[' ], 'Tabularize /[' , 'align-region-at-[' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , ']' ], 'Tabularize /]' , 'align-region-at-]' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '{' ], 'Tabularize /{' , 'align-region-at-{' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '}' ], 'Tabularize /}' , 'align-region-at-}' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , ',' ], 'Tabularize /,' , 'align-region-at-,' , 1 , 1 )
2020-04-27 21:59:45 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '.' ], 'Tabularize /\.' , 'align-region-at-dot' , 1 , 1 )
2019-03-10 08:34:20 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , ':' ], 'Tabularize /:' , 'align-region-at-:' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , ';' ], 'Tabularize /;' , 'align-region-at-;' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '=' ], 'Tabularize /===\|<=>\|\(&&\|||\|<<\|>>\|\/\/\)=\|=\~[#?]\?\|=>\|[:+/*!%^=><&|.?-]\?=[#?]\?/l1r1' , 'align-region-at-=' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , 'o' ], 'Tabularize /&&\|||\|\.\.\|\*\*\|<<\|>>\|\/\/\|[-+*/.%^><&|?]/l1r1' , 'align-region-at-operator, such as +,-,*,/,%,^,etc' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '¦' ], 'Tabularize /¦' , 'align-region-at-¦' , 1 , 1 )
2021-10-17 13:16:30 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , '<Bar>' ], 'Tabularize /[|| ]' , 'align-region-at-|' , 1 , 1 )
2019-10-25 21:13:22 +08:00
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'a' , '[SPC]' ], 'Tabularize /\s\ze\S/l0' , 'align-region-at-space' , 1 , 1 )
nmap < Space > xa < Space > [SPC ]xa [SPC ]
2019-02-16 23:47:48 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'a' , 'r' ], 'call call('
\ . string ( s :_function ( 's:align_at_regular_expression' ) ) . ', [])' ,
\ 'align-region-at-user-specified-regexp' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'd' , 'w' ], 'StripWhitespace' , 'delete trailing whitespaces' , 1 )
2021-08-08 12:53:02 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'd' , '[SPC]' ], 'silent call call('
2017-12-06 16:15:18 +08:00
\ . string ( s :_function ( 's:delete_extra_space' ) ) . ', [])' ,
\ 'delete extra space arround cursor' , 1 )
2021-08-08 12:53:02 +08:00
nmap < Space > xd < Space > [SPC ]xd [SPC ]
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'i' , 'c' ], 'silent call call('
\ . string ( s :_function ( 's:lowerCamelCase' ) ) . ', [])' ,
\ 'change symbol style to lowerCamelCase' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'i' , 'C' ], 'silent call call('
\ . string ( s :_function ( 's:UpperCamelCase' ) ) . ', [])' ,
\ 'change symbol style to UpperCamelCase' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'i' , '_' ], 'silent call call('
\ . string ( s :_function ( 's:under_score' ) ) . ', [])' ,
\ 'change symbol style to under_score' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'i' , 'u' ], 'silent call call('
\ . string ( s :_function ( 's:under_score' ) ) . ', [])' ,
\ 'change symbol style to under_score' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'i' , 'U' ], 'silent call call('
\ . string ( s :_function ( 's:up_case' ) ) . ', [])' ,
2020-05-15 21:45:12 +08:00
\ 'change symbol style to UP_CASE' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'i' , 'k' ], 'silent call call('
\ . string ( s :_function ( 's:kebab_case' ) ) . ', [])' ,
\ 'change symbol style to kebab-case' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'i' , '-' ], 'silent call call('
\ . string ( s :_function ( 's:kebab_case' ) ) . ', [])' ,
\ 'change symbol style to kebab-case' , 1 )
2017-07-17 07:54:57 +08:00
2019-01-27 10:59:44 +08:00
" justification
2019-02-17 10:30:13 +08:00
let g :_spacevim_mappings_space .x .j = {'name' : '+Justification' }
2019-01-27 10:59:44 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'j' , 'l' ], 'silent call call('
\ . string ( s :_function ( 's:set_justification_to' ) ) . ', ["left"])' ,
\ 'set-the-justification-to-left' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'j' , 'c' ], 'silent call call('
\ . string ( s :_function ( 's:set_justification_to' ) ) . ', ["center"])' ,
\ 'set-the-justification-to-center' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'j' , 'r' ], 'silent call call('
\ . string ( s :_function ( 's:set_justification_to' ) ) . ', ["right"])' ,
\ 'set-the-justification-to-right' , 1 )
2017-07-17 07:54:57 +08:00
2021-04-11 12:31:24 +08:00
nnoremap < silent > < Plug > Lowercase :call < SID > toggle_case ( 0 , -1 ) < Cr >
vnoremap < silent > < Plug > Lowercase :call < SID > toggle_case ( 1 , -1 ) < Cr >
nnoremap < silent > < Plug > Uppercase :call < SID > toggle_case ( 0 , 1 ) < Cr >
vnoremap < silent > < Plug > Uppercase :call < SID > toggle_case ( 1 , 1 ) < Cr >
nnoremap < silent > < Plug > ToggleCase :call < SID > toggle_case ( 0 , 0 ) < Cr >
vnoremap < silent > < Plug > ToggleCase :call < SID > toggle_case ( 1 , 0 ) < Cr >
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'u' ] , '<Plug>Lowercase' , 'lowercase-text' , 0 , 1 )
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'U' ] , '<Plug>Uppercase' , 'uppercase-text' , 0 , 1 )
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , '~' ] , '<Plug>ToggleCase' , 'toggle-case-text' , 0 , 1 )
2019-03-17 22:03:27 +08:00
" word
2019-09-15 14:30:49 +08:00
let g :_spacevim_mappings_space .x .w = {'name' : '+Word' }
2019-10-05 22:31:49 +08:00
call SpaceVim #mapping #space #def ( 'vnoremap' , ['x' , 'w' , 'c' ], 'normal! ' . ":'<,'>s/\\\w\\+//gn" . "\<cr>" , 'count the words in the select region' , 1 )
2022-05-09 23:21:35 +08:00
let g :_spacevim_mappings_space .x .s = {'name' : '+String/Snippet' }
2019-09-15 14:30:49 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 's' , 'j' ], 'call call('
\ . string ( s :_function ( 's:join_string_with' ) ) . ', [])' ,
\ 'join-string-with' , 1 )
2017-07-17 07:54:57 +08:00
2021-04-10 20:10:16 +08:00
" line
let g :_spacevim_mappings_space .x .l = {'name' : '+Line' }
nnoremap < silent > < Plug > DuplicateLines :call < SID > duplicate_lines ( 0 ) < Cr >
vnoremap < silent > < Plug > DuplicateLines :call < SID > duplicate_lines ( 1 ) < Cr >
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'l' , 'd' ], '<Plug>DuplicateLines' ,
\ 'duplicate-line-or-region' , 0 , 1 )
2022-03-19 23:51:37 +08:00
nnoremap < silent > < Plug > ReverseLines :ReverseLines < cr >
vnoremap < silent > < Plug > ReverseLines :ReverseLines < cr >
2022-02-26 11:03:48 +08:00
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'l' , 'r' ] , '<Plug>ReverseLines' , 'reverse-lines' , 0 , 1 )
2021-04-10 20:10:16 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'l' , 's' ] , 'sort i' , 'sort lines (ignorecase)' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'l' , 'S' ] , 'sort' , 'sort lines (case-sensitive)' , 1 )
nnoremap < silent > < Plug > UniquifyIgnoreCaseLines :call < SID > uniquify_lines ( 0 , 1 ) < Cr >
vnoremap < silent > < Plug > UniquifyIgnoreCaseLines :call < SID > uniquify_lines ( 1 , 1 ) < Cr >
nnoremap < silent > < Plug > UniquifyCaseSenstiveLines :call < SID > uniquify_lines ( 0 , 0 ) < Cr >
vnoremap < silent > < Plug > UniquifyCaseSenstiveLines :call < SID > uniquify_lines ( 1 , 0 ) < Cr >
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'l' , 'u' ], '<Plug>UniquifyIgnoreCaseLines' ,
\ 'uniquify-lines (ignorecase)' , 0 , 1 )
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'l' , 'U' ], '<Plug>UniquifyCaseSenstiveLines' ,
\ 'uniquify-lines (case-senstive)' , 0 , 1 )
2023-03-29 18:01:18 +08:00
let g :_spacevim_mappings_space .x .g = {'name' : '+Grammarous' }
" | `<Plug>(grammarous-move-to-info-window)` | Move the cursor to the info window |
" | `<Plug>(grammarous-open-info-window)` | Open the info window for the error under the cursor |
" | `<Plug>(grammarous-reset)` | Reset the current check |
" | `<Plug>(grammarous-fixit)` | Fix the error under the cursor automatically |
" | `<Plug>(grammarous-fixall)` | Fix all the errors in a current buffer automatically |
" | `<Plug>(grammarous-close-info-window)` | Close the information window from checked buffer |
" | `<Plug>(grammarous-remove-error)` | Remove the error under the cursor |
" | `<Plug>(grammarous-disable-rule)` | Disable the grammar rule under the cursor |
" | `<Plug>(grammarous-move-to-next-error)` | Move cursor to the next error |
" | `<Plug>(grammarous-move-to-previous-error)` | Move cursor to the previous error |
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'g' , 'n' ], '<Plug>(grammarous-move-to-next-error)' , 'move-cursor-to-next-error' , 0 , 1 )
call SpaceVim #mapping #space #def ( 'nmap' , ['x' , 'g' , 'p' ], '<Plug>(grammarous-move-to-previous-error)' , 'move-cursor-to-previous-error' , 0 , 1 )
2017-12-06 16:15:18 +08:00
let g :_spacevim_mappings_space .i = {'name' : '+Insertion' }
let g :_spacevim_mappings_space .i .l = {'name' : '+Lorem-ipsum' }
let g :_spacevim_mappings_space .i .p = {'name' : '+Passwords' }
let g :_spacevim_mappings_space .i .U = {'name' : '+UUID' }
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'p' , 1 ], 'call call('
\ . string ( s :_function ( 's:insert_simple_password' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-simple-password' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'p' , 2 ], 'call call('
\ . string ( s :_function ( 's:insert_stronger_password' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-stronger-password' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'p' , 3 ], 'call call('
\ . string ( s :_function ( 's:insert_paranoid_password' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-password-for-paranoids' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'p' , 'p' ], 'call call('
\ . string ( s :_function ( 's:insert_phonetically_password' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-a-phonetically-easy-password' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'p' , 'n' ], 'call call('
\ . string ( s :_function ( 's:insert_numerical_password' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-a-numerical-password' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'U' , 'U' ], 'call call('
\ . string ( s :_function ( 's:uuidgen_U' ) ) . ', [])' ,
\ 'uuidgen-4' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'l' , 'l' ], 'call call('
\ . string ( s :_function ( 's:insert_lorem_ipsum_list' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-lorem-ipsum-list' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'l' , 'p' ], 'call call('
\ . string ( s :_function ( 's:insert_lorem_ipsum_paragraph' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-lorem-ipsum-paragraph' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['i' , 'l' , 's' ], 'call call('
\ . string ( s :_function ( 's:insert_lorem_ipsum_sentence' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'insert-lorem-ipsum-sentence' , 1 )
2017-12-06 16:15:18 +08:00
" move line
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'J' ], 'call call('
\ . string ( s :_function ( 's:move_text_down_transient_state' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'move-text-down(enter-transient-state)' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 'K' ], 'call call('
\ . string ( s :_function ( 's:move_text_up_transient_state' ) ) . ', [])' ,
2019-09-15 14:30:49 +08:00
\ 'move-text-up(enter-transient-state)' , 1 )
2017-07-24 05:50:27 +08:00
2017-12-06 16:15:18 +08:00
" transpose
2023-07-03 22:38:52 +08:00
if has_key ( g :_spacevim_mappings_space .x , 't' )
let g :_spacevim_mappings_space .x .t .name = '+Transpose/Translate'
else
let g :_spacevim_mappings_space .x .t = {'name' : '+Transpose' }
endif
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 't' , 'c' ], 'call call('
\ . string ( s :_function ( 's:transpose_with_previous' ) ) . ', ["character"])' ,
2019-09-15 14:30:49 +08:00
\ 'swap-current-character-with-previous-one' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 't' , 'w' ], 'call call('
\ . string ( s :_function ( 's:transpose_with_previous' ) ) . ', ["word"])' ,
2019-09-15 14:30:49 +08:00
\ 'swap-current-word-with-previous-one' , 1 )
2017-12-06 16:15:18 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 't' , 'l' ], 'call call('
\ . string ( s :_function ( 's:transpose_with_previous' ) ) . ', ["line"])' ,
2019-09-15 14:30:49 +08:00
\ 'swap-current-line-with-previous-one' , 1 )
2019-03-19 13:32:05 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 't' , 'C' ], 'call call('
\ . string ( s :_function ( 's:transpose_with_next' ) ) . ', ["character"])' ,
2019-09-15 14:30:49 +08:00
\ 'swap-current-character-with-next-one' , 1 )
2019-03-19 13:32:05 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 't' , 'W' ], 'call call('
\ . string ( s :_function ( 's:transpose_with_next' ) ) . ', ["word"])' ,
2019-09-15 14:30:49 +08:00
\ 'swap-current-word-with-next-one' , 1 )
2019-03-19 13:32:05 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['x' , 't' , 'L' ], 'call call('
\ . string ( s :_function ( 's:transpose_with_next' ) ) . ', ["line"])' ,
2019-09-15 14:30:49 +08:00
\ 'swap-current-line-with-next-one' , 1 )
2017-07-24 05:50:27 +08:00
2020-12-19 14:00:47 +01:00
" splitjoin
call SpaceVim #mapping #space #def ( 'nnoremap' , ['j' , 'o' ],
\ 'SplitjoinJoin' , 'join into a single-line statement' , 1 )
call SpaceVim #mapping #space #def ( 'nnoremap' , ['j' , 'm' ],
\ 'SplitjoinSplit' , 'split a one-liner into multiple lines' , 1 )
2022-04-27 22:13:32 +08:00
call SpaceVim #mapping #space #def ( 'nnoremap' , ['j' , 'k' ], 'j==' , 'goto-next-line-and-indent' , 0 )
if has ( 'nvim-0.6.0' ) && s :enable_hop
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'j' ], 'HopChar1' , 'jump-or-select-to-a-character' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'J' ], 'HopChar2' , 'jump-to-suite-of-two-characters' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'l' ], 'HopLine' , 'jump-or-select-to-a-line' , 1 , 1 )
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'w' ], 'HopWord' , 'jump-to-a-word' , 1 , 1 )
else
" call SpaceVim#mapping#space#def('nmap', ['j', 'j'], '<Plug>(easymotion-overwin-f)', 'jump to a character', 0)
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'j' ], '<Plug>(better-easymotion-overwin-f)' , 'jump-or-select-to-a-character' , 0 , 1 )
nnoremap < silent > < Plug > ( better - easymotion - overwin - f ) :call < SID > better_easymotion_overwin_f ( 0 ) < Cr >
xnoremap < silent > < Plug > ( better - easymotion - overwin - f ) :< C - U > call < SID > better_easymotion_overwin_f ( 1 ) < Cr >
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'J' ], '<Plug>(easymotion-overwin-f2)' , 'jump-to-suite-of-two-characters' , 0 )
" call SpaceVim#mapping#space#def('nmap', ['j', 'l'], '<Plug>(easymotion-overwin-line)', 'jump to a line', 0)
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'l' ], '<Plug>(better-easymotion-overwin-line)' , 'jump-or-select-to-a-line' , 0 , 1 )
nnoremap < silent > < Plug > ( better - easymotion - overwin - line ) :call < SID > better_easymotion_overwin_line ( 0 ) < Cr >
xnoremap < silent > < Plug > ( better - easymotion - overwin - line ) :< C - U > call < SID > better_easymotion_overwin_line ( 1 ) < Cr >
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'v' ], '<Plug>(easymotion-overwin-line)' , 'jump-to-a-line' , 0 )
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'w' ], '<Plug>(easymotion-overwin-w)' , 'jump-to-a-word' , 0 )
call SpaceVim #mapping #space #def ( 'nmap' , ['j' , 'q' ], '<Plug>(easymotion-overwin-line)' , 'jump-to-a-line' , 0 )
endif
call SpaceVim #mapping #space #def ( 'nnoremap' , ['j' , 'u' ], 'call call('
\ . string ( s :_function ( 's:jump_to_url' ) ) . ', [])' ,
\ 'jump-to-url' , 1 )
2017-07-24 05:50:27 +08:00
endfunction
2022-04-27 22:13:32 +08:00
if has ( 'nvim-0.6.0' )
function ! s :jump_to_url ( ) abort
2023-07-02 18:57:09 +08:00
lua require ( 'spacevim.plugin.hop' ) .hintLines ( )
2022-04-27 22:13:32 +08:00
endfunction
else
function ! s :jump_to_url ( ) abort
let g :EasyMotion_re_anywhere = 'http[s]*://'
call feedkeys ( "\<Plug>(easymotion-jumptoanywhere)" )
endfunction
endif
2017-07-24 05:50:27 +08:00
function ! s :transpose_with_previous ( type ) abort
2019-03-19 13:32:05 +08:00
let l :save_register = @"
2017-12-06 16:15:18 +08:00
if a :type = = # 'line'
if line ( '.' ) > 1
normal ! kddp
endif
elseif a :type = = # 'word'
2019-03-19 13:32:05 +08:00
normal ! yiw
let l :cw = @"
normal ! geyiw
let l :tw = @"
if l :cw ! = # l :tw
let @" = l :cw
normal ! viwp
let @" = l :tw
normal ! eviwp
2017-07-24 05:50:27 +08:00
endif
2017-12-06 16:15:18 +08:00
elseif a :type = = # 'character'
if col ( '.' ) > 1
2019-01-25 19:19:38 +08:00
normal ! hxp
2017-12-06 16:15:18 +08:00
endif
endif
2019-03-19 13:32:05 +08:00
let @" = l :save_register
endfunction
function ! s :transpose_with_next ( type ) abort
let l :save_register = @"
if a :type = = # 'line'
if line ( '.' ) < line ( '$' )
normal ! ddp
endif
elseif a :type = = # 'word'
normal ! yiw
let l :cw = @"
normal ! wyiw
let l :nw = @"
if l :cw ! = # l :nw
let @" = l :cw
normal ! viwp
let @" = l :nw
normal ! geviwp
endif
elseif a :type = = # 'character'
if col ( '.' ) < col ( '$' ) -1
normal ! xp
endif
endif
let @" = l :save_register
2017-07-22 07:30:17 +08:00
endfunction
2022-04-27 22:13:32 +08:00
function ! s :better_easymotion_overwin_line ( is_visual ) abort
let current_line = line ( '.' )
try
if a :is_visual
call EasyMotion #Sol ( 0 , 2 )
else
call EasyMotion #overwin #line ( )
endif
" clear cmd line
noautocmd normal ! :
if a :is_visual
let last_line = line ( '.' )
exe current_line
if last_line > current_line
exe 'normal! V' . ( last_line - current_line ) . 'j'
else
exe 'normal! V' . ( current_line - last_line ) . 'k'
endif
endif
catch /^Vim\%((\a\+)\)\=:E117/
endtry
endfunction
function ! s :better_easymotion_overwin_f ( is_visual ) abort
let [current_line , current_col ] = getpos ( '.' ) [1 :2 ]
try
call EasyMotion #OverwinF ( 1 )
" clear cmd line
noautocmd normal ! :
if a :is_visual
let last_line = line ( '.' )
let [last_line , last_col ] = getpos ( '.' ) [1 :2 ]
call cursor ( current_line , current_col )
if last_line > current_line
exe 'normal! v' . ( last_line - current_line ) . 'j0' . last_col . '|'
else
exe 'normal! v' . ( current_line - last_line ) . 'k0' . last_col . '|'
endif
endif
catch /^Vim\%((\a\+)\)\=:E117/
endtry
endfunction
2017-07-22 07:30:17 +08:00
function ! s :move_text_down_transient_state ( ) abort
2017-12-06 16:15:18 +08:00
if line ( '.' ) = = line ( '$' )
else
2019-01-25 19:19:38 +08:00
let l :save_register = @"
2017-07-22 08:33:41 +08:00
normal ! ddp
2019-01-25 19:19:38 +08:00
let @" = l :save_register
2017-12-06 16:15:18 +08:00
endif
call s :text_transient_state ( )
2017-07-22 07:30:17 +08:00
endfunction
function ! s :move_text_up_transient_state ( ) abort
2019-01-25 19:19:38 +08:00
if line ( '.' ) > 1
let l :save_register = @"
2017-07-22 08:33:41 +08:00
normal ! ddkP
2019-01-25 19:19:38 +08:00
let @" = l :save_register
2017-12-06 16:15:18 +08:00
endif
call s :text_transient_state ( )
2017-07-22 07:30:17 +08:00
endfunction
function ! s :text_transient_state ( ) abort
2017-12-06 16:15:18 +08:00
let state = SpaceVim #api #import ( 'transient_state' )
call state .set_title ( 'Move Text Transient State' )
call state .defind_keys (
\ {
2023-07-02 18:57:09 +08:00
\ 'layout' : 'vertical split' ,
\ 'left' : [
\ {
\ 'key' : 'J' ,
\ 'desc' : 'move text down' ,
\ 'func' : '' ,
\ 'cmd' : 'noautocmd silent! m .+1' ,
\ 'exit' : 0 ,
\ },
\ ],
\ 'right' : [
\ {
\ 'key' : 'K' ,
\ 'func' : '' ,
\ 'desc' : 'move text up' ,
\ 'cmd' : 'noautocmd silent! m .-2' ,
\ 'exit' : 0 ,
\ },
\ ],
\ }
\ )
2017-12-06 16:15:18 +08:00
call state .open ( )
2017-01-14 19:49:19 +08:00
endfunction
2017-07-17 07:08:53 +08:00
function ! s :lowerCamelCase ( ) abort
2017-12-06 16:15:18 +08:00
" fooFzz
2020-10-31 15:52:34 +08:00
if matchstr ( getline ( '.' ) , '\%' . col ( '.' ) . 'c.' ) = ~ # '\s'
2020-05-15 21:45:12 +08:00
return
endif
2017-12-06 16:15:18 +08:00
let cword = s :parse_symbol ( expand ( '<cword>' ) )
if ! empty ( cword )
let rst = [cword [0 ]]
if len ( cword ) > 1
let rst + = map ( cword [1 :], "substitute(v:val, '^.', '\\u&', 'g')" )
2017-07-17 07:08:53 +08:00
endif
2017-12-06 16:15:18 +08:00
let save_register = @k
let save_cursor = getcurpos ( )
let @k = join ( rst , '' )
normal ! viw "kp
call setpos ( '.' , save_cursor )
let @k = save_register
endif
2017-07-17 07:08:53 +08:00
endfunction
function ! s :UpperCamelCase ( ) abort
2017-12-06 16:15:18 +08:00
" FooFzz
2020-10-31 15:52:34 +08:00
if strcharpart ( getline ( '.' ) [col ( '.' ) - 1 :], 0 , 1 ) = ~ # '\s'
2020-05-15 21:45:12 +08:00
return
endif
2017-12-06 16:15:18 +08:00
let cword = s :parse_symbol ( expand ( '<cword>' ) )
if ! empty ( cword )
let rst = map ( cword , "substitute(v:val, '^.', '\\u&', 'g')" )
let save_register = @k
let save_cursor = getcurpos ( )
let @k = join ( rst , '' )
normal ! viw "kp
call setpos ( '.' , save_cursor )
let @k = save_register
endif
2017-07-17 07:08:53 +08:00
endfunction
2017-07-17 07:36:55 +08:00
function ! s :kebab_case ( ) abort
2017-12-06 16:15:18 +08:00
" foo-fzz
2020-10-31 15:52:34 +08:00
if matchstr ( getline ( '.' ) , '\%' . col ( '.' ) . 'c.' ) = ~ # '\s'
2020-05-15 21:45:12 +08:00
return
endif
2017-12-06 16:15:18 +08:00
let cword = s :parse_symbol ( expand ( '<cword>' ) )
if ! empty ( cword )
let save_register = @k
let save_cursor = getcurpos ( )
let @k = join ( cword , '-' )
normal ! viw "kp
call setpos ( '.' , save_cursor )
let @k = save_register
endif
2017-07-17 07:54:57 +08:00
endfunction
2017-07-17 07:36:55 +08:00
2017-07-17 07:54:57 +08:00
function ! s :under_score ( ) abort
2017-12-06 16:15:18 +08:00
" foo_fzz
let cword = s :parse_symbol ( expand ( '<cword>' ) )
if ! empty ( cword )
let save_register = @k
let save_cursor = getcurpos ( )
let @k = join ( cword , '_' )
normal ! viw "kp
call setpos ( '.' , save_cursor )
let @k = save_register
endif
2017-07-17 07:54:57 +08:00
endfunction
2017-07-17 07:44:46 +08:00
2017-07-17 07:54:57 +08:00
function ! s :up_case ( ) abort
2017-12-06 16:15:18 +08:00
" FOO_FZZ
2020-10-31 15:52:34 +08:00
if matchstr ( getline ( '.' ) , '\%' . col ( '.' ) . 'c.' ) = ~ # '\s'
2020-05-15 21:45:12 +08:00
return
endif
2017-12-06 16:15:18 +08:00
let cword = map ( s :parse_symbol ( expand ( '<cword>' ) ) , 'toupper(v:val)' )
if ! empty ( cword )
let save_register = @k
let save_cursor = getcurpos ( )
let @k = join ( cword , '_' )
normal ! viw "kp
call setpos ( '.' , save_cursor )
let @k = save_register
endif
2017-07-17 07:36:55 +08:00
endfunction
2017-07-17 07:44:46 +08:00
let s :STRING = SpaceVim #api #import ( 'data#string' )
2017-07-17 07:36:55 +08:00
function ! s :parse_symbol ( symbol ) abort
2017-12-06 16:15:18 +08:00
if a :symbol = ~ # '^[a-z]\+\(-[a-zA-Z]\+\)*$'
return split ( a :symbol , '-' )
elseif a :symbol = ~ # '^[a-z]\+\(_[a-zA-Z]\+\)*$'
return split ( a :symbol , '_' )
elseif a :symbol = ~ # '^[a-z]\+\([A-Z][a-z]\+\)*$'
let chars = s :STRING .string2chars ( a :symbol )
let rst = []
let word = ''
for char in chars
if char = ~ # '[a-z]'
let word .= char
else
2017-07-19 05:01:34 +08:00
call add ( rst , tolower ( word ) )
2017-12-06 16:15:18 +08:00
let word = char
endif
endfor
call add ( rst , tolower ( word ) )
return rst
elseif a :symbol = ~ # '^[A-Z][a-z]\+\([A-Z][a-z]\+\)*$'
let chars = s :STRING .string2chars ( a :symbol )
let rst = []
let word = ''
for char in chars
if char = ~ # '[a-z]'
let word .= char
else
if ! empty ( word )
call add ( rst , tolower ( word ) )
endif
let word = char
endif
endfor
call add ( rst , tolower ( word ) )
return rst
else
return [a :symbol ]
endif
2017-07-17 07:36:55 +08:00
endfunction
2017-07-19 07:09:41 +08:00
function ! s :count_selection_region ( ) abort
2017-12-06 16:15:18 +08:00
call feedkeys ( "gvg\<c-g>\<Esc>" , 'ti' )
2017-07-19 07:09:41 +08:00
endfunction
2017-07-17 07:08:53 +08:00
function ! s :delete_extra_space ( ) abort
2017-12-06 16:15:18 +08:00
if ! empty ( getline ( '.' ) )
if getline ( '.' ) [col ( '.' ) -1 ] = = # ' '
2019-01-27 10:59:44 +08:00
execute "normal! \"_ciw\<Space>\<Esc>"
2017-07-17 07:08:53 +08:00
endif
2017-12-06 16:15:18 +08:00
endif
2017-07-01 01:32:14 -05:00
endfunction
2019-01-27 10:59:44 +08:00
function ! s :set_justification_to ( align ) abort
2019-09-05 14:10:49 +08:00
let l :startlinenr = line ( "'{" )
let l :endlinenr = line ( "'}" )
if getline ( l :startlinenr ) = = # ''
let l :startlinenr + = 1
endif
if getline ( l :endlinenr ) = = # ''
let l :endlinenr - = 1
endif
let l :lineList = map ( getline ( l :startlinenr , l :endlinenr ) , 'trim(v:val)' )
let l :maxlength = 0
for l :line in l :lineList
let l :length = strdisplaywidth ( l :line )
if l :length > l :maxlength
let l :maxlength = l :length
2019-01-27 10:59:44 +08:00
endif
2019-09-05 14:10:49 +08:00
endfor
if a :align = = # 'left'
execute l :startlinenr . ',' . l :endlinenr . ":left\<cr>"
elseif a :align = = # 'center'
execute l :startlinenr . ',' . l :endlinenr . ':center ' . l :maxlength . "\<cr>"
elseif a :align = = # 'right'
execute l :startlinenr . ',' . l :endlinenr . ':right ' . l :maxlength . "\<cr>"
endif
2019-01-27 10:59:44 +08:00
2019-09-05 14:10:49 +08:00
unlet l :startlinenr
unlet l :endlinenr
unlet l :lineList
unlet l :maxlength
2019-01-27 10:59:44 +08:00
endfunction
2017-07-01 01:32:14 -05:00
let s :local_lorem_ipsum = [
2017-12-06 16:15:18 +08:00
\ 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.' ,
\ 'Donec hendrerit tempor tellus.' ,
\ 'Donec pretium posuere tellus.' ,
\ 'Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus.' ,
\ 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.' ,
\ 'Nulla posuere.' ,
\ 'Donec vitae dolor.' ,
\ 'Nullam tristique diam non turpis.' ,
\ 'Cras placerat accumsan nulla.' ,
\ 'Nullam rutrum.' ,
\ 'Nam vestibulum accumsan nisl.' ,
\ 'Pellentesque dapibus suscipit ligula.' ,
\ 'Donec posuere augue in quam.' ,
\ 'Etiam vel tortor sodales tellus ultricies commodo.' ,
\ 'Suspendisse potenti.' ,
\ 'Aenean in sem ac leo mollis blandit.' ,
\ 'Donec neque quam, dignissim in, mollis nec, sagittis eu, wisi.' ,
\ 'Phasellus lacus.' ,
\ 'Etiam laoreet quam sed arcu.' ,
\ 'Phasellus at dui in ligula mollis ultricies.' ,
\ 'Integer placerat tristique nisl.' ,
\ 'Praesent augue.' ,
\ 'Fusce commodo.' ,
\ 'Vestibulum convallis, lorem a tempus semper, dui dui euismod elit, vitae placerat urna tortor vitae lacus.' ,
\ 'Nullam libero mauris, consequat quis, varius et, dictum id, arcu.' ,
\ 'Mauris mollis tincidunt felis.' ,
\ 'Aliquam feugiat tellus ut neque.' ,
\ 'Nulla facilisis, risus a rhoncus fermentum, tellus tellus lacinia purus, et dictum nunc justo sit amet elit.' ,
\ 'Aliquam erat volutpat.' ,
\ 'Nunc eleifend leo vitae magna.' ,
\ 'In id erat non orci commodo lobortis.' ,
\ 'Proin neque massa, cursus ut, gravida ut, lobortis eget, lacus.' ,
\ 'Sed diam.' ,
\ 'Praesent fermentum tempor tellus.' ,
\ 'Nullam tempus.' ,
\ 'Mauris ac felis vel velit tristique imperdiet.' ,
\ 'Donec at pede.' ,
\ 'Etiam vel neque nec dui dignissim bibendum.' ,
\ 'Vivamus id enim.' ,
\ 'Phasellus neque orci, porta a, aliquet quis, semper a, massa.' ,
\ 'Phasellus purus.' ,
\ 'Pellentesque tristique imperdiet tortor.' ,
\ 'Nam euismod tellus id erat.' ,
\ 'Nullam eu ante vel est convallis dignissim.' ,
\ 'Fusce suscipit, wisi nec facilisis facilisis, est dui fermentum leo, quis tempor ligula erat quis odio.' ,
\ 'Nunc porta vulputate tellus.' ,
\ 'Nunc rutrum turpis sed pede.' ,
\ 'Sed bibendum.' ,
\ 'Aliquam posuere.' ,
\ 'Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis varius mi purus non odio.' ,
\ 'Pellentesque condimentum, magna ut suscipit hendrerit, ipsum augue ornare nulla, non luctus diam neque sit amet urna.' ,
\ 'Curabitur vulputate vestibulum lorem.' ,
\ 'Fusce sagittis, libero non molestie mollis, magna orci ultrices dolor, at vulputate neque nulla lacinia eros.' ,
\ 'Sed id ligula quis est convallis tempor.' ,
\ 'Curabitur lacinia pulvinar nibh.' ,
\ 'Nam a sapien.' ,
\ ]
2017-07-01 01:32:14 -05:00
let s :lorem_ipsum_paragraph_separator = "\n\n"
let s :lorem_ipsum_sentence_separator = ' '
let s :lorem_ipsum_list_beginning = ''
let s :lorem_ipsum_list_bullet = '* '
let s :lorem_ipsum_list_item_end = "\n"
let s :lorem_ipsum_list_end = ''
function ! s :insert_lorem_ipsum_list ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
let @k = '* ' . s :local_lorem_ipsum [s :NUMBER .random ( 0 , len ( s :local_lorem_ipsum ) ) ] . "\n"
normal ! "kgP
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
function ! s :insert_lorem_ipsum_paragraph ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
let pids = len ( s :local_lorem_ipsum ) / 11
let pid = s :NUMBER .random ( 0 , pids ) * 11
let @k = join ( s :LIST .listpart ( s :local_lorem_ipsum , pid , 11 ) , s :lorem_ipsum_sentence_separator ) . s :lorem_ipsum_paragraph_separator
normal ! "kgP
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
function ! s :insert_lorem_ipsum_sentence ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
let @k = s :local_lorem_ipsum [s :NUMBER .random ( 0 , len ( s :local_lorem_ipsum ) ) ] . s :lorem_ipsum_sentence_separator
normal ! "kgP
let @k = save_register
2017-01-14 19:49:19 +08:00
endfunction
2017-07-01 01:32:14 -05:00
function ! s :insert_simple_password ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
2020-04-16 16:27:49 +02:00
let @k = s :PASSWORD .generate_simple ( v :count ? v :count : 8 )
2017-12-06 16:15:18 +08:00
normal ! "kPl
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
2021-04-10 20:10:16 +08:00
function ! s :duplicate_lines ( visual ) abort
if a :visual
call setline ( '.' , getline ( "'<" ) )
2021-04-10 23:01:10 +08:00
elseif line ( '.' ) > 1
2021-04-10 20:10:16 +08:00
call setline ( '.' , getline ( line ( '.' ) - 1 ) )
endif
endfunction
2022-03-19 23:53:05 +08:00
command ! - nargs = 0 - range = % ReverseLines :< line1 > , < line2 > call < sid > reverse_lines ( )
2022-03-19 23:51:37 +08:00
function ! s :reverse_lines ( ) range
let rst = getline ( a :firstline , a :lastline )
2022-02-26 11:03:48 +08:00
call reverse ( rst )
2022-03-19 23:51:37 +08:00
call s :BUFFER .buf_set_lines ( bufnr ( '.' ) , a :firstline -1 , a :lastline , 0 , rst )
2022-02-26 11:03:48 +08:00
endfunction
2021-04-10 20:10:16 +08:00
function ! s :uniquify_lines ( visual , ignorecase ) abort
if a :visual
let start_line = line ( "'<" )
let end_line = line ( "'>" )
let rst = []
for l in range ( start_line , end_line )
2021-04-10 22:16:45 +08:00
if index ( rst , getline ( l ) , 0 , a :ignorecase ) = = # -1
call add ( rst , getline ( l ) )
2021-04-10 20:10:16 +08:00
endif
endfor
call s :BUFFER .buf_set_lines ( bufnr ( '.' ) , start_line -1 , end_line , 0 , rst )
else
2021-04-11 12:23:47 +08:00
if line ( '.' ) > 1
if a :ignorecase
if getline ( '.' ) = = ? getline ( line ( '.' ) - 1 )
normal ! dd
endif
else
if getline ( '.' ) = = # getline ( line ( '.' ) - 1 )
normal ! dd
endif
endif
2021-04-10 20:10:16 +08:00
endif
endif
endfunction
2021-04-11 12:31:24 +08:00
function ! s :toggle_case ( visual , uppercase ) abort
if a :visual
if a :uppercase = = 1
normal ! gvgU
elseif a :uppercase = = -1
normal ! gvgu
elseif a :uppercase = = 0
normal ! gv ~
endif
else
if a :uppercase = = 1
normal ! gUl
elseif a :uppercase = = -1
normal ! gul
elseif a :uppercase = = 0
normal ! ~
endif
endif
endfunction
2017-07-01 01:32:14 -05:00
function ! s :insert_stronger_password ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
2020-04-16 16:27:49 +02:00
let @k = s :PASSWORD .generate_strong ( v :count ? v :count : 12 )
2017-12-06 16:15:18 +08:00
normal ! "kPl
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
function ! s :insert_paranoid_password ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
2020-04-16 16:27:49 +02:00
let @k = s :PASSWORD .generate_paranoid ( v :count ? v :count : 20 )
2017-12-06 16:15:18 +08:00
normal ! "kPl
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
function ! s :insert_numerical_password ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
2020-04-16 16:27:49 +02:00
let @k = s :PASSWORD .generate_numeric ( v :count ? v :count : 4 )
2017-12-06 16:15:18 +08:00
normal ! "kPl
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
function ! s :insert_phonetically_password ( ) abort
2017-12-06 16:15:18 +08:00
let save_register = @k
2020-04-16 16:27:49 +02:00
let @k = s :PASSWORD .generate_phonetic ( v :count ? v :count : 8 )
2017-12-06 16:15:18 +08:00
normal ! "kPl
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
function ! s :uuidgen_U ( ) abort
2017-12-06 16:15:18 +08:00
let uuid = system ( 'uuidgen' )
let save_register = @k
let @k = uuid
normal ! "kPl
let @k = save_register
2017-07-01 01:32:14 -05:00
endfunction
2019-02-16 23:47:48 +08:00
function ! s :align_at_regular_expression ( ) abort
let re = input ( ':Tabularize /' )
if ! empty ( re )
exe 'Tabularize /' . re
else
normal ! :
echo 'empty input, canceled!'
endif
endfunction
2019-09-15 14:30:49 +08:00
function ! s :join_string_with ( ) abort
2022-03-28 12:03:17 +08:00
if s :HI .is_string ( line ( '.' ) , col ( '.' ) )
2019-09-15 14:30:49 +08:00
let c = col ( '.' )
let a = 0
let b = 0
let _c = c
while c > 0
2022-03-28 12:03:17 +08:00
if s :HI .is_string ( line ( '.' ) , c )
2019-09-15 14:30:49 +08:00
let c - = 1
else
let a = c
break
endif
endwhile
let c = _c
while c > 0
2022-03-28 12:03:17 +08:00
if s :HI .is_string ( line ( '.' ) , c )
2019-09-15 14:30:49 +08:00
let c + = 1
else
let b = c
break
endif
endwhile
let l :save_register_m = @m
let line = getline ( '.' ) [:a ] . join ( split ( getline ( '.' ) [a + 1 : b ]) , '-' ) . getline ( '.' ) [b :]
call setline ( '.' , line )
let @m = l :save_register_m
endif
endfunction
2017-07-01 01:32:14 -05:00
" function() wrapper
if v :version > 703 | | v :version = = 703 && has ( 'patch1170' )
2017-12-06 16:15:18 +08:00
function ! s :_function ( fstr ) abort
return function ( a :fstr )
endfunction
2017-07-01 01:32:14 -05:00
else
2017-12-06 16:15:18 +08:00
function ! s :_SID ( ) abort
return matchstr ( expand ( '<sfile>' ) , '<SNR>\zs\d\+\ze__SID$' )
endfunction
let s :_s = '<SNR>' . s :_SID ( ) . '_'
function ! s :_function ( fstr ) abort
return function ( substitute ( a :fstr , 's:' , s :_s , 'g' ) )
endfunction
2017-07-01 01:32:14 -05:00
endif
2017-07-28 08:07:50 +08:00
augroup spacevim_layer_edit
2017-12-06 16:15:18 +08:00
au !
2019-09-04 22:56:45 +08:00
autocmd FileType * call < SID > add_buffer_head ( )
2017-07-28 08:07:50 +08:00
augroup END
let s :ft_head_tp = {}
function ! s :add_buffer_head ( ) abort
2019-10-05 22:31:49 +08:00
if has_key ( s :ft_head_tp , &ft ) && getline ( 1 ) = = # '' && line ( '$' ) = = 1
2019-09-04 22:56:45 +08:00
let head = s :ft_head_tp [&ft ]
2019-09-05 14:10:49 +08:00
call setline ( 1 , map ( head , 's:parse(v:val)' ) )
2019-09-04 22:56:45 +08:00
call cursor ( len ( head ) , 0 )
2017-12-06 16:15:18 +08:00
endif
2017-07-28 08:07:50 +08:00
endfunction
2019-09-05 14:10:49 +08:00
function ! s :parse ( line ) abort
return s :VIM .parse_string ( a :line )
endfunction
2018-03-18 19:43:23 +08:00
function ! SpaceVim #layers #edit #add_ft_head_tamplate ( ft , tamp ) abort
2017-12-06 16:15:18 +08:00
call extend ( s :ft_head_tp , {a :ft : a :tamp })
2017-07-28 08:07:50 +08:00
endfunction