From: Jannik ZANDER Date: Sun, 8 Jul 2018 06:24:52 +0000 (+0200) Subject: Integrate ranger with vim and bash X-Git-Url: https://git.zndr.dk/?a=commitdiff_plain;h=e3b7cd56967c652626bc1cadeb63c39e97d41fa2;p=dotfiles.git Integrate ranger with vim and bash --- diff --git a/.bashrc b/.bashrc index bbb3215..9af60eb 100644 --- a/.bashrc +++ b/.bashrc @@ -57,7 +57,7 @@ fi export LESS=" -R " # Load aliases, functions, etc -for file in ${HOME}/.config/bash/*; do +for file in ${HOME}/.config/bash/*.sh; do [ -f "$file" ] && . "$file"; done; diff --git a/.config/bash/aliases.sh b/.config/bash/aliases.sh index 0ecbb00..7bd734a 100644 --- a/.config/bash/aliases.sh +++ b/.config/bash/aliases.sh @@ -34,8 +34,10 @@ alias rd='rmdir' # My shortcuts alias h='history' alias q='exit' -alias info='info --vi-keys' +alias e='ranger-cd' +alias o='rifle' alias open='xdg-open &>/dev/null' +alias info='info --vi-keys' alias dit='git --git-dir=$HOME/.dit --work-tree=$HOME' alias ag='ag --path-to-ignore=$HOME/.ignore --skip-vcs-ignores' alias rg='rg --path-separator="//"' @@ -57,18 +59,14 @@ alias mkdate='mkdir "$(date +'%Y%m%d')"' # Stopwatch alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date' - # Automatically change the directory in bash after closing ranger -function ranger-cd { +function ranger-cd +{ tempfile="$(mktemp -t tmp.XXXXXX)" - ~/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}" + ranger --choosedir="$tempfile" "${@:-$(pwd)}" test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then cd -- "$(cat "$tempfile")" fi rm -f -- "$tempfile" } - -# This binds Ctrl-O to ranger-cd: -bind '"\C-o":"ranger-cd\C-m"' -alias r='ranger-cd' diff --git a/.gitmodules b/.gitmodules index 9702a91..d0245c7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,3 +34,6 @@ [submodule ".vim/pack/github/ranger"] path = .vim/pack/github/ranger url = https://github.com/ranger/ranger.git +[submodule ".vim/pack/github/opt/vim-ranger"] + path = .vim/pack/github/opt/vim-ranger + url = https://github.com/Mizuchi/vim-ranger.git diff --git a/.vim/pack/github/opt/vim-ranger b/.vim/pack/github/opt/vim-ranger new file mode 160000 index 0000000..5f1ea1a --- /dev/null +++ b/.vim/pack/github/opt/vim-ranger @@ -0,0 +1 @@ +Subproject commit 5f1ea1adf48f804bb29b89beb5ca79a34474e312 diff --git a/.vim/vimrc b/.vim/vimrc index c1cd30f..0f11350 100644 --- a/.vim/vimrc +++ b/.vim/vimrc @@ -1,12 +1,35 @@ -" options -" --------------------- +syntax on +filetype plugin indent on +" Colors and Fonts +highlight Normal guibg=black guifg=white +set background=dark +set t_Co=256 +if (&t_Co > 2 || has("gui_running")) + if exists("&guifont") + if has("mac") + set guifont=monaco:h11 + elseif has("unix") + set guifont=inconsolata\ 11 + elseif has("win32") +" set guifont=consolas:h11,courier\ new:h10 + set guifont=consolas:h10:cANSI:qDRAFT + endif + endif +endif + +" block cursor in normal mode +let &t_ti.="\e[1 q" +let &t_SI.="\e[5 q" +let &t_EI.="\e[1 q" +let &t_te.="\e[0 q" + +" General options silent !mkdir -p ~/.local/share/vim/{swap,backup,undo} set directory=~/.local/share/vim/swap set backupdir=~/.local/share/vim/backup set undodir=~/.local/share/vim/undo set viminfo+=n~/.local/share/vim/viminfo - set path=.,,**,C:\programs\IAR\\\ System\EWB_V850_V360\common\bin set fileformats=unix,dos,mac set printoptions=paper:letter @@ -14,232 +37,134 @@ set shell=/bin/bash set undofile set autoread set autowrite - -"set autoindent set backspace=2 set breakindent showbreak=\ + - set clipboard=unnamed -"set clipboard=unnamedplus - "set foldmethod=syntax "set foldlevel=1 "set foldclose=all "set foldopen+=jump - set guioptions+=a "set guioptions-=m "menu bar set guioptions-=T "toolbar set guioptions-=r "scroolbar - set complete-=i " searching includes can be slow set history=200 set incsearch " incremental search set lazyredraw set linebreak - set mouse=nvi set mousemodel=popup - set number set scrolloff=1 set shiftround set shortmess=aoOtI -set laststatus=2 " always show status line +set laststatus=2 set cmdheight=2 -set showcmd " show (partial) command in status line. - -set showmatch " show matching brackets. +set showcmd +set showmatch set sidescrolloff=5 -set smartcase " case insensitive searches become sensitive with capitals +set smartcase "setglobal tags=./tags; - set timeoutlen=500 " leader key timeout set ttimeoutlen=50 " make esc work faster - set visualbell set virtualedit=block set updatetime=250 - set wildmenu set wildmode=longest:full,full set wildignore+=tags,.*.un~,*.pyc set winaltkeys=no +" Programs + +" make +"set makeprg=cmake\ --build\ . +set makeprg=msbuild +set errorformat=\ %#%f(%l):\ %m " Visual studio 2013 +"set errorformat=%.%#>\ %#%f(%l)\ :\ %m " Visual studio 2008 +"set makeprg=vim-iarbuild.cmd " IAR compiler +"set errorformat=%f(%l)\ :\ %m + +" grep +set grepprg=ag\ --vimgrep\ --skip-vcs-ignores\ --path-to-ignore\ ~/.ignore\ --cpp\ --cc +set grepformat^=%f:%l:%c:%m " file:line:coloumn:message + let mapleader = "," -" visual -" --------------------- -highlight Normal guibg=black guifg=white -set background=dark -set t_Co=256 +" Normal mode Mappings +nnoremap * :silent grep \| copen +nnoremap t :tags +nnoremap za +nnoremap +nnoremap +nnoremap +nnoremap +nnoremap :bnext +nnoremap :bNext -" switch syntax highlighting on, when the terminal has colors -if (&t_Co > 2 || has("gui_running")) && has("syntax") - if exists("&guifont") - if has("mac") - set guifont=monaco:h11 - elseif has("unix") - set guifont=inconsolata\ 11 - elseif has("win32") -" set guifont=consolas:h11,courier\ new:h10 - set guifont=consolas:h10:cANSI:qDRAFT - endif - endif +" Insert Mappings +" Command Mappings - if exists("syntax_on") || exists("syntax_manual") - else - syntax on - endif -endif +" Command aliases +cnoreabbrev w!! w !sudo tee "%" -" block cursor in normal mode -let &t_ti.="\e[1 q" -let &t_SI.="\e[5 q" -let &t_EI.="\e[1 q" -let &t_te.="\e[0 q" +" Commands -" plugins -" --------------------- +" Plugins + +" Tagbar packadd tagbar + +" Fugitive packadd vim-fugitive + +" Gtags packadd vim-gtags + +" Unimpaired packadd vim-unimpaired -" netrw -" --------------------- +" Netrw let g:netrw_liststyle=3 let g:netrw_banner = 0 let g:netrw_sort_sequence = '[\/]$,*' -" ranger -" --------------------- -function! RangeChooser() - let temp = tempname() - " The option "--choosefiles" was added in ranger 1.5.1. Use the next line - " with ranger 1.4.2 through 1.5.0 instead. - "exec 'silent !ranger --choosefile=' . shellescape(temp) - if has("gui_running") - exec 'silent !xterm -e ranger --choosefiles=' . shellescape(temp) - else - exec 'silent !ranger --choosefiles=' . shellescape(temp) - endif - if !filereadable(temp) - redraw! - " Nothing to read. - return - endif - let names = readfile(temp) - if empty(names) - redraw! - " Nothing to open. - return - endif - " Edit the first item. - exec 'edit ' . fnameescape(names[0]) - " Add any remaning items to the arg list/buffer list. - for name in names[1:] - exec 'argadd ' . fnameescape(name) - endfor - redraw! -endfunction -command! -bar RangerChooser call RangeChooser() -nnoremap r :RangerChooser - -" airline -" --------------------- +" Ranger +packadd vim-ranger +let g:ranger_on_exit = 'bw!' +let g:ranger_open_mode = 'edit' + +" Airline packadd vim-airline let g:airline#extensions#tabline#enabled = 1 -" editorconfig -" --------------------- +" Editorconfig packadd editorconfig-vim let g:editorconfig_exclude_patterns = ['fugitive://.*', 'scp://.*'] let g:editorconfig_verbose = 1 - if has("win32") let g:EditorConfig_exec_path = "C:\programs\editorconfig\bin\editorconfig.exe" else let g:editorconfig_core_mode = "python_builtin" endif -" make -" --------------------- -"set makeprg=cmake\ --build\ . -set makeprg=msbuild -" Visual studio 2013 -set errorformat=\ %#%f(%l):\ %m -" Visual studio 2008 -"set errorformat=%.%#>\ %#%f(%l)\ :\ %m -" -" IAR compiler -"if executable('vim-iarbuild.cmd') -" set makeprg=vim-iarbuild.cmd -" set errorformat=%f(%l)\ :\ %m -"endif - -" grep -" --------------------- -if executable('ag') - set grepprg=ag\ --vimgrep\ --skip-vcs-ignores\ --path-to-ignore\ ~/.ignore\ --cpp\ --cc - set grepformat^=%f:%l:%c:%m " file:line:coloumn:message -endif -" grep under cursor -nnoremap * :silent grep \| copen " redraws the screen - -" ctrl-p -" --------------------- +" CtrlP packadd ctrlp.vim -let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] let g:ctrlp_map = '' let g:ctrlp_cmd = 'CtrlP' - -" mappings -" --------------------- - -" buffers -nnoremap b :buffer - -" tags -nnoremap t :tags - -" ctrl-hjkl to windows navigation and resizing -nnoremap -nnoremap -nnoremap -nnoremap - - -" Maps Ctrl-[h,j,k,l,+,-] to windows split navigations and resizing -nnoremap -nnoremap -nnoremap -nnoremap - -if bufwinnr(1) -nnoremap :exe "resize " . (winheight(0) * 2/3) -nnoremap :exe "resize " . (winheight(0) * 3/2) -endif - -" folding -noremap za - -" force save -ca w!! w !sudo tee "%" +let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] +"let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""' +nnoremap b :CtrlPBuffer +nnoremap m :CtrlPMRU " autocommands -" --------------------- - -if has("autocmd") - filetype plugin indent on - autocmd BufReadPost quickfix nnoremap - autocmd bufnewfile,bufread *.md set filetype=markdown - autocmd bufnewfile,bufread *.gradle set filetype=groovy -endif +autocmd BufReadPost quickfix nnoremap +autocmd bufnewfile,bufread *.md set filetype=markdown +autocmd bufnewfile,bufread *.gradle set filetype=groovy " local -" --------------------- if filereadable(expand('~/.vim/vimrc.local')) source ~/.vim/vimrc.local endif