【问题标题】:Open a .bat file in Unix with syntax highlighting在 Unix 中使用语法高亮打开一个 .bat 文件
【发布时间】:2023-03-05 00:29:01
【问题描述】:

请给我推荐一个好的编辑器,我可以在其中从支持语法高亮的 Unix 编辑器中打开文件。我一直在使用vi编辑器。我尝试了 ESC :syntax on 但没有帮助

【问题讨论】:

    标签: batch-file editor syntax-highlighting vi


    【解决方案1】:

    vim 工作正常,你只需要告诉它什么是 .bat 文件。

    如果 vim 不能自动识别文件,你可以用:set filetype=bat 告诉它如何突出显示它。

    【讨论】:

    • 请注意vi 不是vim。 (尽管一些 Linux 发行版使命令 vi 运行 vim;在 Solaris 等 UNIX 上绝对不一样)
    • @dsh - 这就是我推荐 vim 的原因
    • 正确。我只是想指出这一点,因为问题提到了“vi”。 (PS。我赞成您的回答,并对其进行了编辑以提及:set ft=bat
    • 在我安装 gVim 时,我必须使用 :set ft=dosbatch。 'bat' 文件类型似乎不起作用。
    【解决方案2】:

    我希望这是你想要的..不需要使用任何其他编辑器..你可以使用和配置 vi 编辑器

    VI and VIM Syntax Highlighting

    这是我的示例屏幕截图。我正在使用来自here.. 的 .bat 文件代码。

    这是我的 ~/.vimrc 文件配置

    syntax on
    set background=dark
    set ruler                     " show the line number on the bar
    set more                      " use more prompt
    set autoread                  " watch for file changes
    set number                    " line numbers
    set hidden
    set noautowrite               " don't automagically write on :next
    set lazyredraw                " don't redraw when don't have to
    set showmode
    set showcmd
    set nocompatible              " vim, not vi
    set autoindent smartindent    " auto/smart indent
    set smarttab                  " tab and backspace are smart
    set tabstop=2                 " 6 spaces
    set shiftwidth=2
    set scrolloff=5               " keep at least 5 lines above/below
    set sidescrolloff=5           " keep at least 5 lines left/right
    set history=200
    set backspace=indent,eol,start
    set linebreak
    set cmdheight=2               " command line two lines high
    set undolevels=1000           " 1000 undos
    set updatecount=100           " switch every 100 chars
    set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
    set ttyfast                   " we have a fast terminal
    set noerrorbells              " No error bells please
    set shell=bash
    set fileformats=unix
    set ff=unix
    filetype on                   " Enable filetype detection
    filetype indent on            " Enable filetype-specific indenting
    filetype plugin on            " Enable filetype-specific plugins
    set wildmode=longest:full
    set wildmenu                  " menu has tab completion
    let maplocalleader=','        " all my macros start with ,
    set laststatus=2
    nore ; :
    nore , ;
    
    map ,<Tab> :set hls<CR>/\\n.*\\n/<CR>
    set statusline=%2*%n\|%<%*%-.40F%2*\|\ %2*%M\ %3*%=%1*\ %1*%2.6l%2*x%1*%1.9(%c%V%)%2*[%1*%P%2*]%1*%2B
    
    "  searching
    set incsearch                 " incremental search
    set ignorecase                " search ignoring case
    set hlsearch                  " highlight the search
    set showmatch                 " show matching bracket
    set diffopt=filler,iwhite     " ignore all whitespace and sync
    
    "  backup
    " set backup
    " set backupdir=~/.vim_backup
    " set viminfo=%100,'100,/100,h,\"500,:100,n~/.viminfo
    "set viminfo='100,f1
    
    " spelling
    if v:version >= 700
      " Enable spell check for text files
      autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en
    endif
    
    " mappings
    " toggle list mode
    nmap <LocalLeader>tl :set list!<cr>
    " toggle paste mode
    nmap <LocalLeader>pp :set paste!<cr>
    
    
    """"""""""""""""""""""""""""""""""""""""""""""""
    " Dark background
    """"""""""""""""""""""""""""""""""""""""""""""""
    
    "I always work on dark terminals
    " set background=dark
    
    "Make the completion menus readable
    highlight Pmenu ctermfg=0 ctermbg=3
    highlight PmenuSel ctermfg=0 ctermbg=7
    
    "The following should be done automatically for the default colour scheme
    "at least, but it is not in Vim 7.0.17.
    if &bg == "dark"
      highlight MatchParen ctermbg=darkblue guibg=blue
    endif
    

    【讨论】:

      【解决方案3】:

      如果你不喜欢 vi,试试 emacs :-)

      【讨论】:

      • 您能告诉我如何在 emacs 中设置语法高亮吗?
      • 您可能需要安装额外的编辑模式才能让 Emacs 与 DOS 批处理文件很好地配合使用:emacswiki.org/emacs/DosScripts
      • 哇!讽刺赢得了接受;)无论如何,你的答案和我的一样好,恭喜。
      【解决方案4】:

      如果你想要一个终端编辑器,你可以使用 vim。如果你想要一个 GUI,你可以使用 gedit,它很简单,并且支持多种语言的高亮显示。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-25
        • 2018-07-04
        • 2012-07-03
        • 2014-08-31
        • 1970-01-01
        • 2016-11-17
        • 1970-01-01
        • 2011-03-07
        相关资源
        最近更新 更多