Use o script que eu chamo de haetex
para a pesquisa em todo o sistema. Coloque o script em /usr/local/bin/
como apenas haetex
com tais permissões / proprietários; o que você pode fazer por sudo chmod 755 /usr/local/bin/haetex
-rwxr-xr-x 1 root root 932 Jun 21 17:16 haetex
Características
- use
find -L ... -exec fgrep -l ... 2>/dev/null
porque ele ocupa um espaço maior no sistema quefind -H ... -exec fgrep -l ...
, sem dar erros sobre links simbólicos defeituosos - Acho que
fgrep
cabe aqui melhor quegrep
-
/dev/null
é necessário no segundo conjunto de comandos porque estamos usandofind -L
, pois queremos incluir todos os links simbólicos e executá-los e não excluir nada na pesquisa
Arquivo haetex
#!/bin/bash
# $Id: haetex, v 0.01 2016/5/4 17:33:12 Masi $
# v 0.011 2016/7/1 08:28:11 Masi $ [location], show filename when one file, search symlinks by default
# v 0.012 2016/8/16 19:21:00 Masi $ fix for find: ‘/home/masi/LOREM’: Too many levels of symbolic links
# Search .tex files
#
# .vimrc
# http://vi.stackexchange.com/q/7782/2923
#
# http://unix.stackexchange.com/a/287344/16920
usage() {
# a function that prints an optional error message and some help.
# and then exits with exit code 1
[ -n "$*" ] && printf "%s\n" "$*" > /dev/stderr
cat <<__EOF__
Usage:
$0 [-h] [ -i ] [ location ] [ word(s) ] [ -x example_data ]
-i Ignore case
-x The example option, requires an argument.
-h This help message.
Detailed help message here
__EOF__
exit 1
}
case_option=''
case_example=''
while getopts "hix:" opt; do
case "$opt" in
h) usage ;;
i) case_option='-i' ;;
x) case_example="$OPTARG" ;;
*) usage ;;
esac
done
shift $((OPTIND-1))
# include symlinks
# http://unix.stackexchange.com/a/293147/16920
# http://unix.stackexchange.com/a/303694/16920
# http://unix.stackexchange.com/a/304027/16920
find -L "$1" -xtype f -name "*.tex" \
-exec fgrep -l $case_option "$2" {} + 2>/dev/null | vim -R -
# The /dev/null makes sure 'fgrep' prints a filename even when it has only a single file to search.
# TODO +perm 0666 not working in Ubuntu 16.04; instead fix the origin of the permission denied alerts
#sudo gfind /Users/masi/Math/ -type d -exec chmod 0755 {} \;
#sudo gfind /Users/masi/Math/ -iname '*.docx' ! -readable -exec chmod 0644 {} \;
# TODO remove -l but make opening file only filename in Vim
# TODO less -s -M +Gg - Less as frontend with selection possibility? Maybe with GNU Screen
Selecione links no modo visual. Pressione Enter
(= líder) + g
+ t
no modo visual. Saída: arquivos nas guias.
Então você redireciona a saída para o Vim.
Esperado $HOME/.vimrc
"" Mapleader is space now from \
let mapleader=" "
"" Quick tabs - Go to tab by number
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<CR>
"" Go to last active tab
au TabLeave * let g:lasttab = tabpagenr()
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>
"" http://vi.stackexchange.com/a/7787/2923
function! OpenSelectionAsTabs() range
let tabnr = tabpagenr()
for line in range(a:firstline, a:lastline)
"" to allow whitespaces in names http://vi.stackexchange.com/a/7865/2923
execute "tabedit " . fnameescape(getline(line))
execute "tabp"
endfor
endfunction
nnoremap <leader>gf :'<,'>call OpenSelectionAsTabs()<CR>
vnoremap <leader>gf :call OpenSelectionAsTabs()<CR>
Pressione Space
+ [1-9]
para navegar pelas guias no Vim.
Limitações Conhecidas: nenhuma
Sistemas: Ubuntu 14.04, Ubuntu 16.04, Debian 8.5, ...
Hardware: Asus Zenbook UX303UA