简体   繁体   English

我应该添加什么.vimrc,当我用vim创建一个html文件时,创建* .html文件显示 <!DOCTYPE html> … 默认?

[英]What should I add to my .vimrc, when I create an html file with vim, created *.html file shows <!DOCTYPE html>… by default?

I checked this question to solve my problem, but I couldn't. 我检查了这个问题以解决我的问题,但我做不到。 Is there any way when I create xxx.html file with vim editor by terminal to open it, vim shows these lines by default(like PHP STORM)? 当我用vim编辑器通过终端创建xxx.html文件打开它时,有没有办法,vim默认显示这些行(如PHP STORM)?
I tried some given solutions like adding this line to my .vimrc: 我尝试了一些给定的解决方案,例如将此行添加到我的.vimrc:

au BufNewFile *.html 0r ~/.vim/html.skel | let IndentStyle = "html"

But I got an error(when I want to open x.html file: 但是我收到了一个错误(当我想打开x.html文件时:

Error detected while processing BufNewFile Auto commands for "*.html": 处理“* .html”的BufNewFile自动命令时检测到错误:
E484: Can't open file /home/radioactive/.vim/html.skel E484:无法打开文件/home/radioactive/.vim/html.skel
Press ENTER or type command to countinue 按ENTER或键入命令countinue

Or when i add these lines: 或者当我添加这些行时:

augroup Xml
    au BufNewFile *.xml 0r ~/vim/skeleton.xml
augroup end

Nothing happens when I create *.html file. 创建* .html文件时没有任何反应。
What I'm asking for is: 我要求的是:
For example: 例如:

sss@sss:~$ vim x.html

Created x.html file should be like this(by default): 创建的x.html文件应该是这样的(默认情况下):

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    </body>
</html>

What should I add to my .vimrc ? 我应该将什么添加到我的.vimrc Is there any other solution? 还有其他解决方案吗?
My .vimrc: 我的.vimrc:

:set number " Display line numbers on the left side
:set ls=2 " This makes Vim show a status line even when only one window is shown
:filetype plugin on " This line enables loading the plugin files for specific file types
:set tabstop=4 " Set tabstop to tell vim how many columns a tab counts for. Linux kernel code expects each tab to be eight columns wide.
:set expandtab " When expandtab is set, hitting Tab in insert mode will produce the appropriate number of spaces.
:set softtabstop=4 " Set softtabstop to control how many columns vim uses when you hit Tab in insert mode. If softtabstop is less than tabstop and expandtab is not set, vim will use a combination of tabs and spaces to make up the desired spacing. If softtabstop equals tabstop and expandtab is not set, vim will always use tabs. When expandtab is set, vim will always use the appropriate number of spaces.
:set shiftwidth=4 " Set shiftwidth to control how many columns text is indented with the reindent operations (<< and >>) and automatic C-style indentation. 
:setlocal foldmethod=indent " Set folding method
:set t_Co=256 " makes Vim use 256 colors
:set nowrap " Don't Wrap lines!
:colorscheme molokai  "Set colorScheme
:set nocp " This changes the values of a LOT of options, enabling features which are not Vi compatible but really really nice
:set clipboard=unnamed
:set clipboard=unnamedplus
:set autoindent " Automatic indentation
:set cindent " This turns on C style indentation
:set si " Smart indent
:syntax enable " syntax highlighting
:set showmatch " Show matching brackets
:set hlsearch " Highlight in search
"":set ignorecase " Ignore case in search
:set noswapfile " Avoid swap files
:set mouse=a " Mouse Integration

" auto complete for ( , " , ' , [ , { 
:inoremap        (  ()<Left>
:inoremap        "  ""<Left>
:inoremap        `  ``<Left>
:inoremap        '  ''<Left>
:inoremap        [  []<Left>
:inoremap      {  {}<Left>

" auto comment and uncooment with F6 and F7 key
:autocmd FileType c,cpp,java,scala let b:comment_leader = '// '
:autocmd FileType sh,ruby,python   let b:comment_leader = '# '
:noremap <silent> #6 :<C-B>silent<C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR> " commenting line with F6
:noremap <silent> #7 :<C-B>silent<C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR> "uncommenting line with F7
:noremap <silent> #5 :!konsole --hold -e 'python ./%' <CR> <CR>" execute python script with F5
" :noremap <silent> #5 :!xterm -hold -e './%' <CR> <CR>" execute bash &python script with F5
:noremap <silent> #3 :tabprevious<CR> " switch to previous tab with F3
:noremap <silent> #4 :tabnext<CR> " switch to next tab with F2
:map <F8> :setlocal spell! spelllang=en_us<CR> " check spelling with F8
:set pastetoggle=<F2> " Paste mode toggle with F2 Pastemode disable auto-indent and bracket auto-compelation and it helps you to paste code froelsewhere .
autocmd TextChanged,TextChangedI <buffer> silent write    " autosave
:let NERDTreeShowHidden=1    "show hidden files


" plugins
"indentLine 
:let g:indentLine_char = '.'
" autocomplpop setting
:set omnifunc=syntaxcomplete " This is necessary for acp plugin
:let g:acp_behaviorKeywordLength = 1 "  Length of keyword characters before the cursor, which are needed to attempt keyword completion



" Vim-plug
" Plugins will be downloaded under the specified directory.
call plug#begin('~/.vim/plugged')

" enter the plugin you wanna install here
Plug 'https://github.com/junegunn/vim-plug.git'
" List ends here. Plugins become visible to Vim after this call.
call plug#end()



" NERDTree plugin setting

"toggle showing NERDTree with F9
:map <F9> :NERDTreeToggle<CR> 

"open a NERDTree automatically when vim starts up if no files were specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

" close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" Open file in new tab with ctrl + t
:let NERDTreeMapOpenInTab='<c-t>'

"vim-airline-clock 
:let g:airline#extensions#clock#format = '%c'



" airline plugin setting
:let g:airline_theme='wombat' " set airline plugin theme
:let g:airline#extensions#tabline#enabled = 1 " showing tabs 
:let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
  endif

" unicode symbols
:let g:airline_left_sep = '»'
:let g:airline_left_sep = '▶'
:let g:airline_right_sep = '«'
:let g:airline_right_sep = '◀'

Looks like you're missing your "skeleton" file. 看起来你错过了你的“骨架”文件。

Just create the html.skel file with your HTML skeleton in your ~/.vim folder. 只需在~/.vim文件夹中使用HTML框架创建html.skel文件即可。 Then the first auto command you posted in your question should work fine. 然后你在问题中发布的第一个自动命令应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM