I found the shorter way.
Add this line to your ~/.vimrc
au FileType perl nnoremap <buffer> _t <ESC>:%! perltidy<CR>
Frage
How to enable map command only when filetype is 'perl'?
something like:
if(&ft=='perl')
map ,pt <ESC>:%! perltidy<CR>
endif
but it doesn't work.
Lösung 3
I found the shorter way.
Add this line to your ~/.vimrc
au FileType perl nnoremap <buffer> _t <ESC>:%! perltidy<CR>
Andere Tipps
Create the file ~/.vim/after/ftplugin/perl.vim
.
Put this line in that file:
nnoremap <buffer> ,pt <ESC>:%! perltidy<CR>
I have below lines in my .vimrc
. the first one sets the "tab" unit for any "perl" filetype and the second one runs perltidy
with _t
keyboard shortcut. THis many not get you the exact answer but surely should get you some pointers:
autocmd FileType perl set tabstop=4|set shiftwidth=4|set expandtab|set softtabstop=4
nnoremap <silent> _t :%!perltidy -q<Enter>
vnoremap <silent> _t :!perltidy -q<Enter>
I have been using these setting in my .vimrc
for last 5+ years. The credit goes to whoever came up with these commands. I did not make above commands.