Compare commits
No commits in common. "master" and "v0.0.2" have entirely different histories.
69
README.md
69
README.md
|
@ -1,68 +1,3 @@
|
||||||
# SplitOpen
|
# vim-split-open
|
||||||
|
|
||||||
This vim plugin opens file-pairs in a new split-window tab
|
This is my first vim plugin. It provides a command to open a combination of c++ source and header file in a new tab split side-by-side.
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use
|
|
||||||
|
|
||||||
:SplitOpen filename
|
|
||||||
|
|
||||||
with a .cpp or .h file as filename to open a new tab containing a vertical split
|
|
||||||
with the corresponding header file in the left window and the corresponding
|
|
||||||
source file in the right window.
|
|
||||||
|
|
||||||
Use
|
|
||||||
|
|
||||||
:Split
|
|
||||||
|
|
||||||
to open the corresponding header or source file to your currently open file in
|
|
||||||
a vertical split.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
Set this option to 1
|
|
||||||
|
|
||||||
let g:splitopen_set_fzf_keys = 1
|
|
||||||
|
|
||||||
to have SplitOpen overwrite the default fzf keybindings ctrl-t/x/v for opening
|
|
||||||
files in splits or tabs to add an addional binding ctrl-s to call SplitOpen.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
SplitOpen is GPL-3.0 licensed. See LICENSE file for more info.
|
|
||||||
|
|
||||||
## Changelog
|
|
||||||
|
|
||||||
v1.1.0
|
|
||||||
* Added Split() command
|
|
||||||
|
|
||||||
v1.0.0
|
|
||||||
* Fixed error when reloading plugin
|
|
||||||
|
|
||||||
v0.0.4
|
|
||||||
* Add filetype configuraton
|
|
||||||
|
|
||||||
v0.0.3
|
|
||||||
* Add fzf.vim keybinding
|
|
||||||
|
|
||||||
v0.0.2
|
|
||||||
* Added delay-loading
|
|
||||||
* Added documentation
|
|
||||||
|
|
||||||
v0.0.1
|
|
||||||
* Initial release
|
|
||||||
|
|
|
@ -1,68 +1,11 @@
|
||||||
function s:invert_dict(source_dict)
|
function splitopen#SplitOpenFile(filename)
|
||||||
let result = {}
|
|
||||||
for [key, value] in items(a:source_dict)
|
|
||||||
let result[value] = key
|
|
||||||
endfor
|
|
||||||
return result
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
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)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function s:isRightSideExtension(extension)
|
|
||||||
return has_key(s:extensions_rev, a:extension)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function s:getFileExtension(filename)
|
|
||||||
return fnamemodify(a:filename, ":e")
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function s:getFileRoot(filename)
|
|
||||||
return fnamemodify(a:filename, ":r")
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
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
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function s:getSwitchFile(filename)
|
|
||||||
return s:getFileRoot(a:filename) . "." . s:getSwitchExtension(a:filename)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function s:addLeftSplit(filename)
|
|
||||||
execute("vsplit " . s:getSwitchFile(a:filename))
|
|
||||||
execute("wincmd l")
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function s:addRightSplit(filename)
|
|
||||||
execute("vsplit " . s:getSwitchFile(a:filename))
|
|
||||||
execute("wincmd L")
|
|
||||||
execute("wincmd h")
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function s:splitOpenFile(filename)
|
|
||||||
let extension = s:getFileExtension(a:filename)
|
|
||||||
if s:isLeftSideExtension(extension)
|
|
||||||
call s:addRightSplit(a:filename)
|
|
||||||
elseif s:isRightSideExtension(extension)
|
|
||||||
call s:addLeftSplit(a:filename)
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! splitopen#SplitOpenFile(filename)
|
|
||||||
execute("tabedit " . a:filename)
|
execute("tabedit " . a:filename)
|
||||||
call s:splitOpenFile(a:filename)
|
let l:file_extension = tolower(fnamemodify(a:filename, ":e"))
|
||||||
endfunction
|
if l:file_extension == "cpp"
|
||||||
|
execute("FSSplitLeft")
|
||||||
function! splitopen#SplitFile()
|
execute("wincmd l")
|
||||||
call s:splitOpenFile(expand("%:p"))
|
elseif l:file_extension == "h"
|
||||||
|
execute("FSSplitRight")
|
||||||
|
execute("wincmd h")
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
================================================================================
|
================================================================================
|
||||||
CONTENTS *SplitOpenContents*
|
CONTENTS *SplitOpenContents*
|
||||||
|
|
||||||
1. Usage ..............................|SplitOpenUsage|
|
1. Usage ..................................|SplitOpenUsage|
|
||||||
2. Configuration ......................|SlitOpenConfiguraton|
|
2. License ................................|SplitOpenLicense|
|
||||||
2.1 g:splitopen_extensions.........|SplitOpenConfiguration_extensions|
|
3. Changelog ..............................|SplitOpenChangelog|
|
||||||
2.2 g:splitopen_set_fzf_keys.......|SplitOpenConfiguration_set_fzf_keys|
|
|
||||||
3. License ............................|SplitOpenLicense|
|
|
||||||
4. Changelog ..........................|SplitOpenChangelog|
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
1. Usage *SplitOpenUsage*
|
1. Usage *SplitOpenUsage*
|
||||||
|
@ -21,57 +18,17 @@ with a .cpp or .h file as filename to open a new tab containing a vertical split
|
||||||
with the corresponding header file in the left window and the corresponding
|
with the corresponding header file in the left window and the corresponding
|
||||||
source file in the right window.
|
source file in the right window.
|
||||||
|
|
||||||
Use
|
|
||||||
|
|
||||||
:Split
|
|
||||||
|
|
||||||
to open the corresponding header or source file to your currently open file in
|
|
||||||
a vertical split.
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
2. Configuration *SplitOpenConfiguration*
|
2. License *SplitOpenLicense*
|
||||||
|
|
||||||
You can configure the following settings:
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
2.1 g:splitopen_extensions *SplitOpenConfiguration_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.
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
2.2 g:splitopen_set_fzf_keys *SplitOpenConfiguration_set_fzf_keys*
|
|
||||||
|
|
||||||
Set this option to 1
|
|
||||||
|
|
||||||
let g:splitopen_set_fzf_keys = 1
|
|
||||||
|
|
||||||
to have SplitOpen overwrite the default fzf keybindings ctrl-t/x/v for opening
|
|
||||||
files in splits or tabs to add an addional binding ctrl-s to call SplitOpen.
|
|
||||||
|
|
||||||
================================================================================
|
|
||||||
3. License *SplitOpenLicense*
|
|
||||||
|
|
||||||
SplitOpen is GPL-3.0 licensed. See LICENSE file for more info.
|
SplitOpen is GPL-3.0 licensed. See LICENSE file for more info.
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
4. Changelog *SplitOpenChangelog*
|
3. Changelog *SplitOpenChangelog*
|
||||||
|
|
||||||
v1.1.0
|
|
||||||
* Added Split() command
|
|
||||||
v1.0.0
|
|
||||||
* Fixed error when reloading plugin
|
|
||||||
v0.0.4
|
|
||||||
* Add filetype configuraton
|
|
||||||
v0.0.3
|
|
||||||
* Add fzf.vim keybinding
|
|
||||||
v0.0.2
|
v0.0.2
|
||||||
* Added delay-loading
|
* Added delay-loading
|
||||||
* Added documentation
|
* Added documentation
|
||||||
|
|
||||||
v0.0.1
|
v0.0.1
|
||||||
* Initial release
|
* Initial release
|
||||||
|
|
|
@ -1,23 +1 @@
|
||||||
command! -nargs=1 SplitOpen :call splitopen#SplitOpenFile("<args>")
|
command -nargs=1 SplitOpen :call splitopen#SplitOpenFile("<args>")
|
||||||
command! Split :call splitopen#SplitFile()
|
|
||||||
|
|
||||||
" 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')
|
|
||||||
let g:splitopen_set_fzf_keys = 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
if g:splitopen_set_fzf_keys
|
|
||||||
let g:fzf_action = {
|
|
||||||
\ 'ctrl-s': 'SplitOpen',
|
|
||||||
\ 'ctrl-t': 'tab split',
|
|
||||||
\ 'ctrl-x': 'split',
|
|
||||||
\ 'ctrl-v': 'vsplit',
|
|
||||||
\ }
|
|
||||||
endif
|
|
||||||
|
|
Loading…
Reference in New Issue