- About CiscoCodeSnippets
- How to Download
- Dependencies
- Want to make changes and customize your snippets?
- How to use the snippets
CiscoCodeSnippets is a tool designed to streamline and accelerate Cisco IOS configuration using Visual Studio Code. By providing a collection of predefined code snippets, it simplifies the process of writing and managing network configurations.
How It Works Rapid Configuration Development:
- The snippets include common Cisco IOS commands, allowing for quick insertion of code blocks.
- Utilize the ? command for helpful details and options related to specific configurations.
Auto-Fill Code Sections:
- The snippets are designed with short-hand abbreviations for easy auto-completion.
- Users can customize these abbreviations to fit their preferences, ensuring a personalized and efficient workflow.
Integration with vsCode:
- The snippets are stored in JSON files within the vsCode User Snippets directory.
- Users can easily download and integrate these snippets into their vsCode setup, enhancing their coding environment with Cisco-specific tools.
- These abbreviations are configurable to your liking. Click Here to see how.
Here you will find various methods of downloading.
- The CLI method is best to be able to stay up to date with any improvements using
git pull
. Using the ZIP method you will have to follow the steps found here each time you wish to update the Code Snippet Files.
- Copy and paste the code below to navigate to the location where vsCode stores User Code Snippets. don't forget to change the area that reads <CHANGE THIS TO YOUR USER NAME> to your user name.
cd C:\Users\<CHANGE THIS TO YOUR USER NAME>\AppData\Roaming\Code\User\snippets
-
If you can't find this file location go to Can't find the directory?
-
NOTE: If you already have configurations inside this directory you may want to run the following command inside another directory and
mv
orcp
only the files you wish to add to your existing configuration to not cause duplicate name collisions or linking errors. -
Inside
/your/path/to/Code/User/snippets
run the following command to add the twoThreeFiveEight/vsCodeSnippets repo files to this directory.
git clone https://github.com/PIesPnuema/CiscoCodeSnippets.git
- Once the repo exists inside your directory you will be able to use the snippets found inside the JSON files.
- Click on <>Code drop down box on the main repo page
- open File Explorer
- Go to your Downloads directory
- Download the ZIP file.
- unzip this file inside your Download directory.
- Click the unzipped directory and copy all the files inside the directory.
- Navigate to the location
C:\Users\<CHANGE THIS TO YOUR USER NAME>\AppData\Roaming\Code\User\snippets
making sure to change the area that reads <CHANGE THIS TO YOUR USER NAME> to your user name. - NOTE: If you already have configurations inside this directory you may want to run the following command inside another directory and
mv
orcp
only the files you wish to add to your existing configuration to not cause duplicate name collisions or linking errors. - Paste all the files into this directory.
- You will now be able to use the snippets.
- Open vsCode
- Navigate to File then Preferences
- Click on Configure User Snippets
- When the Snippets File search bar opens click on the cisco.json file
- If cisco.json is not an option go to
- When the file opens find the file path at the top of the editor. Figure 0-3 and figure 0-4 show where you can find the path.
-
Open CLI and Navigate to the file path you found in the previous steps.
-
Inside
/your/path/to/Code/User/snippets
run the following command to add the vsCodeSnippets repo files to this directory.- NOTE: If you already have configurations inside this directory you may want to run the following command inside another directory and
mv
orcp
only the files you wish to add to your existing configuration.
- NOTE: If you already have configurations inside this directory you may want to run the following command inside another directory and
git clone https://github.com/PIesPnuema/CiscoCodeSnippets.git
- Once the repo exists inside your directory you will be able to use the snippets found inside the JSON files.
- You will need the Cisco IOS Syntax extension in vsCode to be able to add a JSON file containing the Cisco configurations found inside this repo.
- I am using the Cisco IOS Syntax extension by Jamiewoodio
- In vsCode navigate to Extensions found inside the left option bar.
- Search for the extensions mentioned above. Click install.
- You will need to already have the repo installed for this example and have an understanding of how to use it before making changes.
- Open vsCode
- Navigate to File then Preferences
- Click on Configure User Snippets
- When the Snippets File search bar opens click on the language you wish to add the configurations to.
- in our example, we will use the cisco.json file
-
We will only go over how to change the snippet code and not talk about what the JSON is doing.
-
The
"prefix": "cInitial",
field below sets our abbreviation name. We can change this to any name we would rather use to have this snippet paste itself into our configurations (program).
"Cisco Initial Configuration": {
"prefix": "cInitial",
"scope": "cisco",
"body": [
"hostname <name you want>",
"enable secret <PASSWORD>",
"username <USERNAME> secret <PASSWORD>",
"line con 0",
"logging synchronous",
"login local",
"line vty 0 4",
"logging synchronous",
"login local"
],
"description": "Cisco Initial Configuration"
},
- As it stands currently we will need to start typing
cInitial
to allow us to select this snippet. example in figure
- We will change this to
cMyCustomPreFix
to make this the new snippet command
"Cisco Initial Configuration": {
"prefix": "cMyCustomPreFix", <----- WE CHANGED THIS HERE
"scope": "cisco",
"body": [
"hostname <name you want>",
"enable secret <PASSWORD>",
"username <USERNAME> secret <PASSWORD>",
"line con 0",
"logging synchronous",
"login local",
"line vty 0 4",
"logging synchronous",
"login local"
],
"description": "Cisco Initial Configuration"
},
- Here is an example of what changes.
- Very simple we just change, add, or delete the code inside the quotes found inside the body section of the JSON configuration
"Cisco Initial Configuration": {
"prefix": "cMyCustomPreFix",
"scope": "cisco",
"body": [
"hostname <name you want>", <----- CHANGE THE CODE INSIDE THE QUOTES HERE
"enable secret <PASSWORD>", <----- OR HERE
"username <USERNAME> secret <PASSWORD>", <----- OR HERE
"line con 0", <----- OR HERE
"logging synchronous", <----- OR HERE
"login local", <----- OR HERE
"line vty 0 4", <----- MAYBE YOU WISH TO DELETE THIS
"logging synchronous", <----- OR THIS
"login local"
],
"description": "Cisco Initial Configuration"
},
- Just be sure to verify your code prints correctly afterward
The file extension must be the correct language for the snippets you wish to use unless you created a Global User Snippet File. In Figure (3-1) the name of the File is R1.ios the .ios has to be set to use the cisco.json snippets from the repo.
-
Here we are using the cisco.ios snippets.
- Every snippet prefix was prefixed with the character "c" to allow every snippet to populate inside the snippet menu box.
- After the character "c" the snippets will be under the category for which the snippet's purpose falls under. So far there are 3 main categories
- p == protocol (bgp, ospf, eigrp, ipsec, acl, rpvst+)
- l2 == Layer 2 snippets (switchport, Access/trunk)
- l3 == Layer 3 snippets (Layer 3 port-channel, layer 3 SVIs)
- After the character "c" the snippets will be under the category for which the snippet's purpose falls under. So far there are 3 main categories
- Every snippet prefix was prefixed with the character "c" to allow every snippet to populate inside the snippet menu box.
-
If you do not know the snippet prefix simply type "c" and then use DOWN ARROW to search for the snippet.
First Character | Second Character | following |
---|---|---|
c | l2, l3, p, or name | Name of snippet |
- That is basically how to use it. Play around and if you find a better solution to the structure feel free to submit a pull request to the repo explaining what you improved and why.