如何将 Vim 配置转换为 Emacs 配置?

如何将 Vim 配置转换为 Emacs 配置?

我需要通过准备~/.emacs配置文件来设置 Emacs 编辑器。我已经使用 Vim 多年了,现在由于各种原因我想切换到 Emacs,这些原因超出了本文的范围。为此,我需要在 Emacs 中重现我多年来使用 Vim 所开发的所有功能。换句话说:我想将我的~/.vimrc配置文件转换为等效的~/.emacs配置文件。我~/.vimrc在这篇文章中评论了所有设置。

我知道我的~/.vimrc设置很多,但我已经知道如何转换其中一些设置,我也知道有些设置实际上不需要转换。不幸的是,它们中的大多数仍然超出了我目前对 Emacs 配置的了解。

这是我的~/.vimrc

" Configuration file for Vi Improved, save as ~/.vimrc to use.
set nocompatible " Vim mode instead of pure Vi
set encoding=utf-8 " encoding used for displaying file
set fileencoding=utf-8 " encoding used when saving file
set nobackup " do not keep the backup~ file
set confirm " confirm :q in case of unsaved changes
set ruler " show the cursor position all the time
set textwidth=80 " wrap lines automatically at 80th column
set tabstop=8 " set tabulator length to 8 columns
set expandtab " fill tabs with spaces
set softtabstop=8 " backspacing over 8 spaces like over tabs
set shiftwidth=8 " set indentation depth to 8 columns
set backspace=indent,eol,start " backspacing over everything in insert mode
set nojoinspaces " no extra space after '.' when joining lines
set incsearch " do incremental search
set ignorecase " do case insensitive search...
set smartcase " ...unless capital letters are used
set hlsearch " highlight search results
set showmatch " highlight matching braces

filetype on " enable file type detection
filetype plugin on " load the plugins for specific file types
filetype indent on " automatically indent code...
set cinoptions=:0g0 " ...but don't indent case labels and access modifiers

syntax enable " syntax highlighting
set background=dark " dark background for console
colorscheme solarized " set color scheme, must be installed before use

" characters for displaying non-printable characters
set listchars=eol:$,tab:>-,trail:.,nbsp:_,extends:+,precedes:+

" tuning for gVim only
if has('gui_running')
    set number " show line numbers
    set columns=84 lines=48 " GUI window geometry
    set guifont=Monospace\ 12 " font for GUI window
    set background=light " light background for GUI
endif

" automatic commands
if has('autocmd')
    " file type specific automatic commands

    " don't replace Tabs with spaces when editing makefiles
    autocmd Filetype makefile setlocal noexpandtab

    " press F5 to call `indent` for C and C++ source code files
    autocmd FileType c,cpp noremap <F5> :%!indent -kr -brf -nut<cr>
    autocmd FileType c,cpp inoremap <F5> <Esc>:%!indent -kr -brf -nut<cr>

    " tuning textwidth for Java code
    autocmd FileType java setlocal textwidth=132
    if has('gui_running')
        autocmd FileType java setlocal columns=136
    endif

    " disable automatic code indentation when editing TeX and XML files
    autocmd FileType tex,xml setlocal indentexpr=

    " clean-up commands that run automatically on write; use with caution

    " delete empty or whitespaces-only lines at the end of file
    autocmd BufWritePre * :%s/\(\s*\n\)\+\%$//ge

    " replace groups of empty or whitespaces-only lines with one empty line
    autocmd BufWritePre * :%s/\(\s*\n\)\{3,}/\r\r/ge

    " delete any trailing whitespaces
    autocmd BufWritePre * :%s/\s\+$//ge
endif

" general key mappings

" center view on the search result
noremap n nzz
noremap N Nzz

" press F4 to fix indentation in whole file; overwrites marker 'q' position
noremap <F4> mqggVG=`qzz
inoremap <F4> <Esc>mqggVG=`qzza

" press F8 to turn the search results highlight off
noremap <F8> :nohl<cr>
inoremap <F8> <Esc>:nohl<cr>a 

" press F12 to toggle showing the non-printable charactes
noremap <F12> :set list!<cr>
inoremap <F12> <Esc>:set list!<cr>a

答案1

不幸的是,没有自动化的方法可以做到这一点。您是否可能已经取得了进展和/或不再需要这个答案?

你的问题不太具体。你提到你已经搞清楚了很多转换,有些不需要转换。哪些还需要转换?

emacs 有一个 vim 模式被称为邪恶这可能很有趣。他们有一个 YouTube视频也。

相关内容