thewooster
thewooster

Reputation: 847

Vim alias for changing directory

I’m looking for a way to add a custom command or alias to my vimrc to quickly change to different directories within Vim. I had something set up once, but lost that config. This is for a Linux setup.

Basically, I want to set an alias (all-lowercase, if possible; Vim seems to want custom commands to start with an uppercase letter) such as:

:cdscripts

and have the result be the same as typing:

:cd /home/username/.../Scripts

I have used NERDTree, but am looking for something a little bit faster. I have also tried these:

Aliasing a command in vim

CommandAlias : Make aliases to vim command

but can’t quite get the results I’m looking for. Is this possible?

Upvotes: 2

Views: 1977

Answers (2)

Jintin
Jintin

Reputation: 1478

I wrote an alias manager doing these thing easily. - aliasme

you can add, remove or jump to declare path you want.

Three step to install

  1. mkdir ~/.aliasme

  2. curl https://raw.githubusercontent.com/Jintin/aliasme/master/aliasme.sh > ~/.aliasme/aliasme.sh

  3. echo "source ~/.aliasme/aliasme.sh" >> [~/.bash_profile (or any login script: bash_rc)]

After install, you can use all these function

  1. al add [name] [value] # add alias with name and value
  2. al rm [name] # remove alias by name
  3. al ls # alias list
  4. al [name] # execute alias associate with [name]

See https://github.com/Jintin/aliasme for more information

Upvotes: -1

Ingo Karkat
Ingo Karkat

Reputation: 172540

A custom command is very easy:

:command Cdscripts cd /home/username/.../Scripts

To avoid clashes with built-in commands, these must start with an uppercase letter. You can use the plugin linked in your question or cmdalias.vim - Create aliases for Vim commands to create a lowercase alias:

:Alias cdscripts Cdscripts

Upvotes: 4

Related Questions