Vim Tips Wiki
(Initial revision)
 
(Adjust previous/next navigation)
Line 1: Line 1:
  +
{{TipProposed
Add the following into your ~/.bash_completion file (create it if it does not exist):
 
  +
|id=0
  +
|previous=0
  +
|next=0
  +
|created=April 28, 2008
  +
|complexity=basic
  +
|author=Seanhodges
  +
|version=7.0
  +
|subpage=/200804
  +
|category1=
  +
|category2=
  +
}}
 
Add the following to your <tt>~/.bash_completion</tt> file (create it if it does not exist):
   
<pre>_vim_ctags() {
+
<pre>
  +
_vim_ctags() {
 
local cur prev
 
local cur prev
   
Line 16: Line 29:
 
fi
 
fi
   
# Escape slashes to avoid confusing awk
+
# Escape slashes to avoid confusing awk
 
cur=${cur////\\/}
 
cur=${cur////\\/}
   
 
COMPREPLY=( $(compgen -W "`awk -vORS=" " "/^${cur}/ { print \\$1 }" tags`" ) )
 
COMPREPLY=( $(compgen -W "`awk -vORS=" " "/^${cur}/ { print \\$1 }" tags`" ) )
 
;;
 
;;
*)
+
*)
 
_filedir_xspec
 
_filedir_xspec
 
;;
 
;;
esac
+
esac
 
}
 
}
   
Line 30: Line 43:
 
excludelist='*.@(o|O|so|SO|so.!(conf)|SO.!(CONF)|a|A|rpm|RPM|deb|DEB|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MP?(E)G|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)'
 
excludelist='*.@(o|O|so|SO|so.!(conf)|SO.!(CONF)|a|A|rpm|RPM|deb|DEB|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MP?(E)G|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)'
   
complete -F _vim_ctags -f -X "${excludelist}" vi vim gvim rvim view rview rgvim rgview gview</pre>
+
complete -F _vim_ctags -f -X "${excludelist}" vi vim gvim rvim view rview rgvim rgview gview
  +
</pre>
 
   
 
Once you restart your bash session (or create a new one) you can type:
 
Once you restart your bash session (or create a new one) you can type:
   
  +
<pre>
~$ vim -t MyC<tab key>
+
~$ vim -t MyC<tab key>
 
  +
</pre>
   
 
and it will auto-complete the tag the same way it does for files and directories:
 
and it will auto-complete the tag the same way it does for files and directories:
   
  +
<pre>
MyClass MyClassFactory
+
MyClass MyClassFactory
~$ vim -t MyC
+
~$ vim -t MyC
  +
</pre>
   
 
I find this really useful when I'm jumping into a quick bug fix.
   
  +
==Comments==
I find this really useful when I'm jumping into a quick bug fix...
 

Revision as of 12:27, 29 April 2008

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created April 28, 2008 · complexity basic · author Seanhodges · version 7.0

Add the following to your ~/.bash_completion file (create it if it does not exist):

_vim_ctags() {
    local cur prev

    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    case "${prev}" in
        -t)
            # Avoid the complaint message when no tags file exists
            if [ ! -r ./tags ]
            then
                return
            fi

            # Escape slashes to avoid confusing awk
            cur=${cur////\\/}

            COMPREPLY=( $(compgen -W "`awk -vORS=" "  "/^${cur}/ { print \\$1 }" tags`" ) )
            ;;
        *)
            _filedir_xspec
            ;;
    esac
}

# Files matching this pattern are excluded
excludelist='*.@(o|O|so|SO|so.!(conf)|SO.!(CONF)|a|A|rpm|RPM|deb|DEB|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MP?(E)G|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)'

complete -F _vim_ctags -f -X "${excludelist}" vi vim gvim rvim view rview rgvim rgview gview

Once you restart your bash session (or create a new one) you can type:

~$ vim -t MyC<tab key>

and it will auto-complete the tag the same way it does for files and directories:

MyClass MyClassFactory
~$ vim -t MyC

I find this really useful when I'm jumping into a quick bug fix.

Comments