Besides the very useful tab feature, Cursor also has a built-in
chat feature. It has a main chat, the AI agent to which we'll get back
later, but it also has the inline chat, which you can open with
command or control K, depending on your operating
system. And the cool thing about this inline chat
just highlight the code you want to change and then
press either quick edit to open it or
this shortcut I mentioned, command or control K.
You can choose the AI model you want to use here.
Either let Cursor choose one or choose one manually.
You can control which models are available here by clicking add models,
takes you to the settings, and there you can enable
that are available in Cursor. Of course, the model names will
be different when you're viewing this because they change all the time.
But then once you made your decision, and of course Cursor will memorize it and
use that model for the future too until you change it again, you can tell
Cursor what you want to change. For example, what if we don't want to
have a function that takes a file name and content as input?
Instead, we want a function that asks the user for that.
So we could simply tell Cursor function should ask
user for filename and content, something like this.
If we hit enter, it will analyze the highlighted code
suggest changes. And as always, if it does something like
this, it gives us a preview. Highlighted in red is the code that will
disappear. And highlighted in green is the code it wants to
add. In this case, it wants to change the function definition
to no longer accept parameters, and instead it wants to get these
values by using Python's built-in input function, which allows the user to
enter these values in the command line.
So I can then press keep or use the shortcut that's shown here or
click undo or click accept or reject here
or use the appropriate shortcuts.
The difference is that it could be suggesting different
affect some but not all lines. Then you could accept them on a
per line basis with these buttons, or just accept or
reject all suggested changes in one go with these
buttons. In this case for this example, it's the same, so I'll just
accept by using the accept shortcut, and that gives me an updated
function. Now, of course, with this function changed,
longer valid, which is why when I highlight it
for me, I'm getting the tab suggestion to remove
code, these two strings. It's highlighted in red.
So if I hit tab, that's accepted, and now it even wants to continue
and it assumes that for reading the file I want to do the same.
So I could hit tab again to also get rid of the
parameter here and read from file, hit tab to jump here, and
then accept this change and do that for the entire
file. So that's what I was referring to.
You can really quickly make changes in your
file. But initially, we started by using this inline chat to
tell Cursor which code to change in which way, which is another
very powerful way of adjusting your code with help of
AI.