我正在使用VIM编写一些基本的C算法。我有一些键绑定到SCCompile插件,当我按它它将编译我的程序。如果没有问题,它会显示我按任意键,然后我回到VIM打开文件。但如果有问题或警告,它只会告诉我该错误,我不知道如何回到我的档案。
是否有一些命令如何才能回到项目?或者我需要重新打开它吗?
我的.vimrc文件:
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" All of your Plugins must be added before the following line
call vundle#end() " required
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set nocompatible
filetype plugin indent on
syntax on
silent! runtime macros/matchit.vim
set autochdir
set backspace=indent,eol,start
set foldenable
set hidden
set incsearch
set laststatus=2
set ruler
set switchbuf=useopen,usetab
set tags=./tags,tags;/
set wildmenu
nnoremap gb :buffers<CR>:sb<SPACE>
set number
set tabstop=4
set shiftwidth=4
set softtabstop=4
set fo=cqt
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" In text files, always limit the width of text to 78 characters
autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
endif
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
filetype plugin on
if &term=="xterm"
set t_Co=8
set t_Sb=[4%dm
set t_Sf=[3%dm
endif
" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"
autocmd Filetype c nmap <buffer> <F5> :SCCompileAF -std=c99 -Wall -Wextra -pedantic <CR>
execute pathogen#infect()
答案 0 :(得分:1)
据我所知,SCCompile插件应该可以让你更容易在Vim中编译东西。我不能保证这个说法,但插件的文档说明如果编译时出错,那么你应该使用quickfix列表。
要了解此过程,首先要了解Vim的原生:make
/ quickfix
工作流程可能会更容易。
运行:make
将执行make程序'makeprg'
。然后使用'errorformat'
解析输出,并将每个条目放入quickfix列表中。
通常'makeprg'
默认为运行make
的{{1}}命令。但是,您可以通过Makefile
命令更改'makeprg'
或直接设置。
您还可以将额外参数传递给:compiler
。例如:make
注意:运行:make clean
通常会在屏幕底部显示命令的输出,并提示输入。只需按Enter即可,因为所有输出都将在quickfix列表中可用。
运行:make
后,您的quickfix列表将保存编译器的输出。
使用以下命令导航quickfix列表。
:make
打开quickfix窗口:copen
关闭quickfix窗口:cclose
/ :cnext
转到下一个/上一个项目:cprev
打印出当前错误的底部或:cc
以显示此示例中的特定错误3 我个人使用Tim Pope的unimpaired插件导航quickfix列表。
据我所知,SCCompile是处理:cc 3
和/或:make
设置的'makeprg'
包装器。因此,SCCompile只是'errorformat'
的替代品。要编译,只需执行SCCompile映射,然后使用quickfix列表检查错误。
请查看SCCompile的文档::make
和:h SingleCompile-overview
。
由于你是一个新手,我建议创建一个:h SingleCompile-contents
并使用Makefile
,因为这样可以使事情变得非常简单,并且可以很好地记录你编译程序的方式。
我还建议你研究创建一个运行:make
的映射。例如:
:make
nnoremap <f5> :make<cr>