title: Key mapping confusion in VIM,How to make vim works in a smart way?
body: <p>I want to bind <kbd>Ctrl</kbd>-<kbd>w</kbd> with <code>:q</code> command in vim That is to say, I want to use <kbd>Ctrl</kbd>-<kbd>w</kbd> to close the current window of vim,</p>
  
  <p>So I add this to my <code>~/.vimrc</code> :</p>
  
  <pre><code>nmap &lt;C-W&gt; :q&lt;cr&gt;
  </code></pre>
  
  <p>When I use this to close a window that has something unsaved,this command cannot work.</p>
  
  <p>So I want to make it works in a smart way: When the content is saved, just close the window. When the content remains unsaved, ask me whether to close the window directly like this command</p>
  
  <pre><code>:0,$s/a/b/gc
  </code></pre>
  
  <p>I don't know if this is clear enough for you, but thanks in advance.</p>