From 702903b58931978c03e3a6f078058fa1284ae8fe Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Fri, 27 Apr 2018 08:46:32 +0100 Subject: [PATCH] Add easier window movement / creation --- .vimrc | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/.vimrc b/.vimrc index 70f8813..0bddfc0 100644 --- a/.vimrc +++ b/.vimrc @@ -302,17 +302,32 @@ endfunction " Find a file and pass it to cmd function! DmenuOpen(cmd) - let fname = Chomp(system("git ls-files | rofi -dmenu -i -l 20 -p " . a:cmd)) - if empty(fname) - return - endif - execute a:cmd . " " . fname + let fname = Chomp(system("git ls-files | rofi -dmenu -i -l 20 -p " . a:cmd)) + if empty(fname) + return + endif + execute a:cmd . " " . fname +endfunction + +" Moves to open window, or focuses it +" https://www.reddit.com/r/vim/comments/8f80o3/awesome_way_to_navigate_windows_and_autocreate/ +function! WinMove(key) + let t:curwin = winnr() + exec "wincmd ".a:key + if (t:curwin == winnr()) + if (match(a:key,'[jk]')) + wincmd v + else + wincmd s + endif + exec "wincmd ".a:key + endif endfunction " Commands {{{1 "gets the wp salts -command WpSalts :r! curl https://api.wordpress.org/secret-key/1.1/salt 2> /dev/null +command! WpSalts :r! curl https://api.wordpress.org/secret-key/1.1/salt 2> /dev/null " Mappings {{{1 @@ -331,6 +346,12 @@ noremap nnoremap :call DmenuOpen("e") +" make ctrl + hjkl move + create windows +nnoremap :call WinMove('h') +nnoremap :call WinMove('j') +nnoremap :call WinMove('k') +nnoremap :call WinMove('l') + " Make Ctrl C and Ctrl V work on system buffer " if in visual or insert mode respectively vnoremap "+y