문제

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.

도움이 되었습니까?

해결책 3

I found the shorter way.

Add this line to your ~/.vimrc

au FileType perl nnoremap <buffer> _t <ESC>:%! perltidy<CR>

다른 팁

  1. Create the file ~/.vim/after/ftplugin/perl.vim.

  2. 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top