Wikia

Vim Tips Wiki

Changes: Make-compile current buffer

Edit

Back to page

(Compile with gcc)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 11: Line 11:
 
|category2=Compiler
 
|category2=Compiler
 
}}
 
}}
This tip shows techniques to compile or to run <tt>make</tt> for the file in the current buffer. This is useful to list any compile errors in the quickfix window.
+
This tip shows techniques to compile or to run <code>make</code> for the file in the current buffer. This is useful to list any compile errors in the quickfix window.
   
 
==Compile with gcc==
 
==Compile with gcc==
Line 19: Line 19:
 
</pre>
 
</pre>
   
in your [[vimrc]], and your actual file is <tt>file.c</tt>, then <tt>:make</tt> will compile <tt>file.c</tt> with the output <tt>file</tt>. (<tt>gcc file.c -o file</tt>).
+
in your [[vimrc]], and your actual file is <code>file.c</code>, then <code>:make</code> will compile <code>file.c</code> with the output <code>file</code>. (<code>gcc file.c -o file</code>).
   
If you use GNU <tt>make</tt> the above change is not required. Instead, simply use the following command to compile the current file (you need to save it first):
+
If you use GNU <code>make</code> the above change is not required. Instead, simply use the following command to compile the current file (you need to save it first):
 
<pre>
 
<pre>
 
:make %:r
 
:make %:r
 
</pre>
 
</pre>
   
When using other compilers, like Sun <tt>cc</tt>, you can adapt the tip to suit your compiler.
+
When using other compilers, like Sun <code>cc</code>, you can adapt the tip to suit your compiler.
   
 
==Invoking make==
 
==Invoking make==
The following allows you to press F7 (in normal mode) to invoke <tt>make</tt> to compile the file in the current buffer. If modified, the file is first saved.
+
The following allows you to press F7 (in normal mode) to invoke <code>make</code> to compile the file in the current buffer. If modified, the file is first saved.
 
<pre>
 
<pre>
 
" Save and make current file.o
 
" Save and make current file.o
Line 48: Line 48:
 
{{todo}}
 
{{todo}}
 
*I've done a pretty quick clean up. Would someone please reply here with news about whether it actually works (after testing).
 
*I've done a pretty quick clean up. Would someone please reply here with news about whether it actually works (after testing).
*Need some explanation, including note about (deprecated) <tt>%<</tt>. [[User:JohnBeckett|JohnBeckett]] 04:49, 14 July 2009 (UTC)
+
*Need some explanation, including note about (deprecated) <code>%<</code>. [[User:JohnBeckett|JohnBeckett]] 04:49, 14 July 2009 (UTC)

Latest revision as of 05:18, July 13, 2012

Tip 210 Printable Monobook Previous Next

created 2002 · complexity basic · author elian · version 6.0


This tip shows techniques to compile or to run make for the file in the current buffer. This is useful to list any compile errors in the quickfix window.

Compile with gccEdit

If you use

set makeprg=gcc\ -o\ %<\ %

in your vimrc, and your actual file is file.c, then :make will compile file.c with the output file. (gcc file.c -o file).

If you use GNU make the above change is not required. Instead, simply use the following command to compile the current file (you need to save it first):

:make %:r

When using other compilers, like Sun cc, you can adapt the tip to suit your compiler.

Invoking makeEdit

The following allows you to press F7 (in normal mode) to invoke make to compile the file in the current buffer. If modified, the file is first saved.

" Save and make current file.o
function! Make()
  let curr_dir = expand('%:h')
  if curr_dir == ''
    let curr_dir = '.'
  endif
  echo curr_dir
  execute 'lcd ' . curr_dir
  execute 'make %:r.o'
  execute 'lcd -'
endfunction
nnoremap <F7> :update<CR>:call Make()<CR>

CommentsEdit

 TO DO 

  • I've done a pretty quick clean up. Would someone please reply here with news about whether it actually works (after testing).
  • Need some explanation, including note about (deprecated) %<. JohnBeckett 04:49, 14 July 2009 (UTC)

Around Wikia's network

Random Wiki