I can easily vsplit vim window into two(left and right).
How to config vim to:
edit CoffeeScript in the left-window
view compiled JavaScript result in the right-window
view error message at the status-line
When I type in the left-window, the right-window and status-line should update JIT.
For example:
========================================================================
alert "hello" | alert("hello");
alert "world | alert;
|
========================================================================
missing ", starting on line 2
Just like http://coffeescript.org/ -> Try CoffeeScript.
I don't just use vim for this, I use a combination of GNU screen, GNU source-highlight and GNU watch. However, you need to have the version of screen that has the vertical split patch.
After starting screen, I'll hit Ctrl+ACtrl+C to create a second shell, then use Ctrl+AShift+\ to create a vertical split, then Ctrl+ATab to swap over to the new split and Ctrl+ACtrl+A to swap the split over to the new shell. In that shell, I run:
$ mkdir compiled
$ coffee -w -c -o compiled/ *.coffee &
That will run coffee in watch mode, which watches the source file (*.coffee) or folder for changes, and automatically recompiles changed *.coffee files and places the resulting .js files in the compiled folder.
Now, I will run $ watch --color -n 1 colorize compiled/main.js to display the contents of the compiled file I'm interested in, enabling ANSI colorized output.
That script file that I have called colorize is just a wrapper around source-highlight that automatically detects the language of the source file and applies appropriate syntax highlighting.
Then I use Ctrl+ACtrl+Tab to move back over to the first split, and fire up vim main.coffee and start editing away.
As I edit the coffeescript file, the compiled changes show up on the right hand side.
Errors are a little trickier, as they get spit out from the background coffee -w job. They will show up, but sometimes the watch command will overwrite the errors, and sometimes the errors will mess up the screen. When that happens, a quick Ctrl+L to tell bash to redraw the screen fixes things up.
Hope that's of some help.
vimrc config
set autoread
aug coffee
au!
au BufNewFile,BufRead *.coffee setf coffee.python
au FileType coffee.python setl makeprg=coffee\ -c\ %
au FileType coffee.python setl errorformat=Error:\ In\ %f\\,\ %m\ on\ line\ %l,
\Error:\ In\ %f\\,\ Parse\ error\ on\ line\ %l:\ %m,
\SyntaxError:\ In\ %f\\,\ %m,
\%-G%.%#
au BufWritePost *.coffee silent! make! | copen | redraw!
aug END
Note: If you like JIT, try CursorHold instead of BufWritePost.
open file
$ vim -O code.{coffee,js}
run ex command
:w
Related
Rather than having vim print the output of the :make command, I want to read the output in a file (which gets updated automatically in vim); so that my compiled file can run right away without having to see the output of the :make command.
I'm using the following makefile
all: compile run
compile: file.cc
g++ -o file file.cc
run: file
./file
How does one redirect the output of the :make command in a way that it isn't also printed to the screen by vim?
First of all we have https://vi.stackexchange.com/ , you can get better answers about Vim in there.
Second, I'll argue that a Makefile is no place to run a program, the idea behind make is to catch compilation errors. But assuming you have your reasons (e.g. ./file opens a graphical display) there are a couple of ways to perform this in Vim:
For a start you can set makeprg to perform the redirection:
:set makeprg=make\ >/dev/null\ 2>&1
(You can change /dev/null to an actual file)
But that still leaves the line:
Press ENTER or type command to continue
And asks for confirmation, which may be annoying when you know that there is no output.
To get rid of the confirmation line you can use silent as follows:
set makeprg=make\ >/dev/null\ 2>&1
function! MyMake()
silent make
redraw!
endfunction
command Mm call MyMake()
And now you can do:
:Mm
To perform the make and go back to straight to Vim. (the redraw! is needed only in some terminals)
You can execute this command:
:silent exec "!make >Output" | :redraw!
The file Output contains the last output of the executed make command.
Use :silent to remove the output and "press enter" prompt. I suggest a nice mapping or command:
command! -nargs=* Smake silent make <args>
nnoremap <f5> :silent make<cr>
:make will populate the quickfix list with the results from :make. Use :copen to open the quickfix window.
For more help see:
:h :command
:h silent
:h :make
:h 'makeprg'
:h quickfix
I wish to integrate the source code formatter Uncrustify with Vim. Any of the below two options will suffice.
Format the code that I am currently editing (i.e. when gq is pressed).
Format the code when I save the file and then reload the formatted file into current Vim window.
Option 1 is preferable. I tried
set formatprg=uncrustify\ -c ~/misc/uncrustify.cfg --no-backup
i.e. I call Uncrustify with command line options.
This does not work. Vi gives the E518: Unknown option: ~/misc/uncrustify.cfg error.
For option 2, I tried the following in the vimrc file
autocmd bufwritepost *.cpp ! ~/bin/uncrustify -c ~/misc/uncrustify.cfg --no-backup <afile>
The file is formatted after the save, but I have to manually reload the file into Vim.
Have you tried escaping whitespaces:
:set formatprg=uncrustify\ -c\ ~/misc/uncrustify.cfg\ --no-backup
UPDATE
uncrustify prints "Parsing: 170 bytes ..." message to stderr so we need to redirect it to /dev/null:
:set formatprg=uncrustify\ -c\ ~/misc/uncrustify.cfg\ -l\ CPP\ --no-backup\ 2>/dev/null
gq operates on lines, so you can select necessary lines in visual mode and execute gq. For example, if you want to reformat whole file execute ggVGgq.
More info at :help gq
I am running Vim on a Windows box and I would like to integrate my use of pc_lint into Vim. I have figured out how to run lint from within Vim, however I don't know how to grab the output into Vim and ideally how to parse the output so that I can jump to the correct code lines via the error messages.
Does anyone know of a plug-in that will do this? I couldn't find one.
Any advice for this Vim novice?
Cheers,
Andrew
I believe you want the :redir command.
See this link for a good description: http://vim.wikia.com/wiki/Capture_ex_command_output
Actually, here's a much easier way:
:r ! command
That will read the results of command into the current buffer.
OK I got it working.
My efm setting wasn't working correctly.
In my pc_lint config file I have the following setting:
-"format=%(%f %l %C %) %t %n: %m"
And in my vimrc file I have the following setting:
set efm=%f\ \ %l\ \ %c\ \ %m
I also have the following script in my vimrc
" map f4 to run lint
map <f4> :call LintProject()<cr>
"use windows default shell
set shell=cmd.exe
function! LintProject()
new "open a new buffer
exec 'silent r! lint-nt c:\lint\vim\std.lnt *.c -b'
exe "normal ggdd" "remove blank line at the top of the file
caddb "add content of the buffer to the quickfix window
close "close the buffer
copen "open quickfix window
endfunction
Now I can move around the quickfix window as normal and when I press enter I am taken to the file with the error.
Fantastic!!!
According to the answer of this question, the :bd command should not quit Vim (gVim) when it is the last buffer remaining. Unfortunately, it does close gVim in my case. Did I understand something wrong about :bd?
I am also using a preconfigured vimrc file. Maybe a setting in there has that side affect, but I couldn’t find it.
Try doing the following:
:set eventignore=all | bd | set eventignore=
If this won't quit vim then you have some plugin that defines an autocommand that quits vim when no more buffers are present in the list, so after that try doing
verbose autocmd BufWinLeave,BufLeave,BufDelete,BufUnload,BufWipeout
This will show you all autocommands attached to given events (these are events that are executed when buffer is deleted) and where they were defined. Note that I do not have any autocommands attached to these events that are defined by plugins in standart vim distribution.
Update: I do not see anything bad in your output. You may also try
verbose autocmd BufNew,BufAdd,BufCreate,BufEnter,BufWinEnter
(because when you leave last buffer new empty one is created). If this does not show anything suspicious, start ignoring event types: if you are on linux try the following script:
for event in BufWinLeave BufLeave BufDelete BufUnload BufWipeout BufNew BufAdd BufCreate BufEnter BufWinEnter
do
event=$event vim file -c "set eventignore=$event | bd"
done
This script should iterate until you find event name that causes trouble. After this you can use execute "verbose autocmd" $event in vim to narrow number of plugins that should be checked. After you got list of autocmd groups (augroup names are shown just before event name in your output: railsPluginDetect is one of such groups), delete events in them (augroup {GroupName} | execute 'autocmd!' | augroup END) and find out which plugin to claim.
Alternatively, you can use debugger:
debug bd
, then s<CR>n<CR><CR><CR>... until vim quits; don't forget to remember what vim have shown above > prompt before quiting.
I do not want to install another plugin, like pylint.vim,
And today, I decide to use vim edit python instead of pydev which is a eclipse plugin. But I got issues.
I have add this in my vimrc
autocmd BufWritePost *.py !pylint <afile>
but pylint does not contains filename in output
************* Module mymodule
E: 22: invalid syntax
shell return 2
so it can not jump to the line 22 , so I use sed change the output
autocmd BufWritePost *.py !pylint <afile> | sed 's/^\(\w*\):\s*\([0-9]\+\)/<afile>:\2: \1: /g'
it returns:
mymodule.py:22: E: : invalid syntax
but without shell return 2 by vim. so it still can't jump to that line. vim consider it as compile successfully
========================= new comment ===========
Call a function in Vim’s `autocmd` command
I think maybe I should use make command and set makeprg, so I use below config
autocmd FileType python let &makeprg='pylint <afile> | sed s/^\(\w*\):\s*\([0-9]\+\)/<afile>:\2: \1: /g'
autocmd BufWritePost *.py make
when I save, vim returns:
************* Module count
E: 3: invalid syntax
(1 of 2): ************* Module count
Error detected while processing BufWritePost Auto commands for "*.py":
E492: Not an editor command: sed s/^\(\w*\):\s*\([0-9]\+\)/<afile>:\2:
\1: /g
why so complicated with sed which just works properly on Linux? Try the following:
set makeprg=pylint\ --reports=n\ --output-format=parseable\ %:p
set errorformat=%f:%l:\ %m
pylint.vim is old, use syntastic instead:
https://github.com/scrooloose/syntastic
at last I resolve it myself. I'd like share with you guys. 2 lines in vimrc.
autocmd FileType python let &makeprg='pylint %\|sed "s/^\(\w*\):\s*\([0-9]\+\)/%:\2:\ \1:\ /g"'
autocmd BufWritePost *.py make
I would recommend to use A.L.E (Asynchronous Lint Engine) https://github.com/w0rp/ale
It supports a range of python linters and formatters including pylint. Great thing about A.L.E that it supports many other languages.
Nowadays vim ships a compiler file for pylint.
This means that if you have enabled filetype detection (filetype plugin indent on), this is already available without external plugins.
:set makeprg? should show you that pylint is what will be called when issuing :make. If it doesn't, you need to set it as the current compiler with :compiler! pylint.
Now, to have this working, you need to pass some arguments so pylint knows what to lint, most notably what you want to lint, i.e. the filename or directory to link. So to lint the current buffer, run :make %. To lint the current directory, run :make .
That same mecanism could be extended to use flake8 for example, or any linter for any kind of file. See :h :compiler.
autocmd FileType python let &makeprg=‘/usr/local/bin/pylint %’
autocmd BufWritePost *.py make
autocmd FileType python let &makeprg=‘/usr/local/bin/pyflakes %’
autocmd BufWritePost *.py make
you may want to try running epylint instead of just pylint.
epylint (shipped with pylint) is the one that is used within emacs (with flymake). It has a few changes, especially regarding path handling, see the docstring at the start of pylint/epylint.py for more information. It may help you in vim too.
Sidenote: I'm not a vim user for programming myself, but pylint.vim still seems to be a decent option. But I won't question your prerequisites.