Merge branch 'release/configure-filetypes'

This commit is contained in:
Michael Mandl 2019-10-20 15:54:28 +02:00
commit f4b4dfe38d
4 changed files with 93 additions and 10 deletions

View file

@ -16,6 +16,15 @@ source file in the right window.
You can configure the following settings: You can configure the following settings:
### g:splitopen_extensions
Use this dictionary to define your pairs of left-hand- right-hand-side file
types. E.g.
let g:splitopen_extensions = {"h": "cpp"}
always places a .cpp file on the right-hand side when opening an .h file and
vice versa.
### g:splitopen_set_fzf_keys ### g:splitopen_set_fzf_keys
@ -32,6 +41,9 @@ SplitOpen is GPL-3.0 licensed. See LICENSE file for more info.
## Changelog ## Changelog
v0.0.4
* Add filetype configuraton
v0.0.3 v0.0.3
* Add fzf.vim keybinding * Add fzf.vim keybinding

View file

@ -1,11 +1,60 @@
function s:invert_dict(source_dict)
let result = {}
for [key, value] in items(a:source_dict)
let result[value] = key
endfor
return result
endfunc
let s:extensions = g:splitopen_extensions
let s:extensions_rev = s:invert_dict(s:extensions)
function s:isLeftSideExtension(extension)
return has_key(s:extensions, a:extension)
endfunc
function s:isRightSideExtension(extension)
return has_key(s:extensions_rev, a:extension)
endfunc
function s:getFileExtension(filename)
return fnamemodify(a:filename, ":e")
endfunction
function s:getFileRoot(filename)
return fnamemodify(a:filename, ":r")
endfunc
function s:getSwitchExtension(filename)
let extension = s:getFileExtension(a:filename)
if s:isLeftSideExtension(extension)
return s:extensions[extension]
elseif s:isRightSideExtension(extension)
return s:extensions_rev[extension]
endif
endfunc
function s:getSwitchFile(filename)
return s:getFileRoot(a:filename) . "." . s:getSwitchExtension(a:filename)
endfunc
function s:addLeftSplit(filename)
execute("vsplit " . s:getSwitchFile(a:filename))
execute("wincmd l")
endfunc
function s:addRightSplit(filename)
execute("vsplit " . s:getSwitchFile(a:filename))
execute("wincmd L")
execute("wincmd h")
endfunc
function splitopen#SplitOpenFile(filename) function splitopen#SplitOpenFile(filename)
execute("tabedit " . a:filename) execute("tabedit " . a:filename)
let l:file_extension = tolower(fnamemodify(a:filename, ":e")) let extension = s:getFileExtension(a:filename)
if l:file_extension == "cpp" if s:isLeftSideExtension(extension)
execute("FSSplitLeft") call s:addRightSplit(a:filename)
execute("wincmd l") elseif s:isRightSideExtension(extension)
elseif l:file_extension == "h" call s:addLeftSplit(a:filename)
execute("FSSplitRight")
execute("wincmd h")
endif endif
endfunction endfunction

View file

@ -5,7 +5,8 @@ CONTENTS *SplitOpenContents*
1. Usage ..............................|SplitOpenUsage| 1. Usage ..............................|SplitOpenUsage|
2. Configuration ......................|SlitOpenConfiguraton| 2. Configuration ......................|SlitOpenConfiguraton|
2.1 g:splitopen_set_fzf_keys.......|SplitOpenConfiguration_set_fzf_keys| 2.1 g:splitopen_extensions.........|SplitOpenConfiguration_extensions|
2.2 g:splitopen_set_fzf_keys.......|SplitOpenConfiguration_set_fzf_keys|
3. License ............................|SplitOpenLicense| 3. License ............................|SplitOpenLicense|
4. Changelog ..........................|SplitOpenChangelog| 4. Changelog ..........................|SplitOpenChangelog|
@ -26,8 +27,18 @@ source file in the right window.
You can configure the following settings: You can configure the following settings:
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
2.1 g:splitopen_extensions *SplitOpenConfiguration_extensions*
2.1 g:splitopen_set_fzf_keys *SplitOpenConfiguration_set_fzf_keys* Use this dictionary to define your pairs of left-hand- right-hand-side file
types. E.g.
let g:splitopen_extensions = {"h": "cpp"}
always places a .cpp file on the right-hand side when opening an .h file and
vice versa.
--------------------------------------------------------------------------------
2.2 g:splitopen_set_fzf_keys *SplitOpenConfiguration_set_fzf_keys*
Set this option to 1 Set this option to 1
@ -44,6 +55,8 @@ SplitOpen is GPL-3.0 licensed. See LICENSE file for more info.
================================================================================ ================================================================================
4. Changelog *SplitOpenChangelog* 4. Changelog *SplitOpenChangelog*
v0.0.4
* Add filetype configuraton
v0.0.3 v0.0.3
* Add fzf.vim keybinding * Add fzf.vim keybinding
v0.0.2 v0.0.2

View file

@ -1,5 +1,13 @@
command -nargs=1 SplitOpen :call splitopen#SplitOpenFile("<args>") command -nargs=1 SplitOpen :call splitopen#SplitOpenFile("<args>")
" map left-split / right-split file extensions
if !exists("g:splitopen_extensions")
let g:splitopen_extensions = {
\ "h": "cpp",
\ "H": "CPP",
\ }
endif
if !exists('g:splitopen_set_fzf_keys') if !exists('g:splitopen_set_fzf_keys')
let g:splitopen_set_fzf_keys = 0 let g:splitopen_set_fzf_keys = 0
endif endif
@ -9,5 +17,6 @@ if g:splitopen_set_fzf_keys
\ 'ctrl-s': 'SplitOpen', \ 'ctrl-s': 'SplitOpen',
\ 'ctrl-t': 'tab split', \ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split', \ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' } \ 'ctrl-v': 'vsplit',
\ }
endif endif