<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nitin Chaudhary</title>
    <description>The latest articles on Forem by Nitin Chaudhary (@ntncahay).</description>
    <link>https://forem.com/ntncahay</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F443926%2Ffa0a11d9-b424-4a84-a671-7ca2fec7976e.jpeg</url>
      <title>Forem: Nitin Chaudhary</title>
      <link>https://forem.com/ntncahay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ntncahay"/>
    <language>en</language>
    <item>
      <title>Neovim LSP Setup + Code Completion Engine</title>
      <dc:creator>Nitin Chaudhary</dc:creator>
      <pubDate>Fri, 22 Oct 2021 20:48:49 +0000</pubDate>
      <link>https://forem.com/ntncahay/neovim-lsp-setup-code-completion-engine-3ckm</link>
      <guid>https://forem.com/ntncahay/neovim-lsp-setup-code-completion-engine-3ckm</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;One of the cool feature that came with &lt;strong&gt;Neovim 0.5&lt;/strong&gt; is &lt;strong&gt;Language Server Protocol (LSP) support&lt;/strong&gt; which allows to code more effectively as well as easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Language Server Protocol
&lt;/h2&gt;

&lt;p&gt;LSP is a protocol which is used by a language server (eg: &lt;code&gt;clangd&lt;/code&gt;, &lt;code&gt;typescript-language-server&lt;/code&gt;) to communicate with client.&lt;br&gt;
Now, the question raises is what is a &lt;code&gt;language server&lt;/code&gt; too.&lt;br&gt;
So a &lt;code&gt;language server&lt;/code&gt; is a local server which provides suggestions to your client(in our case neovim) while you are writing the code.&lt;br&gt;
As we go forward, i think the definition will become more clearer.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up LSP
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I have been using &lt;a href="https://github.com/neovim/nvim-lspconfig" rel="noopener noreferrer"&gt;nvim-lspconfig&lt;/a&gt; from beginning as it provides the &lt;a href="https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md" rel="noopener noreferrer"&gt;list of all available LSPs for different languages&lt;/a&gt; and how exactly to install and configure them.
But first let's install the &lt;code&gt;nvim-lspconfig&lt;/code&gt; plugin itself:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Packer.nvim&lt;/span&gt;
&lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="s1"&gt;'neovim/nvim-lspconfig'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="c"&gt;" vim-plug&lt;/span&gt;
Plug 'neovim/nvim&lt;span class="p"&gt;-&lt;/span&gt;lspconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now let's see an example of how to install a &lt;code&gt;language server&lt;/code&gt;.&lt;br&gt;
   &lt;br&gt;As of now, let's see for &lt;code&gt;typescript language&lt;/code&gt;. For &lt;code&gt;.ts&lt;/code&gt; you can install &lt;code&gt;tsserver&lt;/code&gt; using the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; typescript-language-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Let's start configuring the server . So if you have gone through &lt;a href="https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md" rel="noopener noreferrer"&gt;nvim-lspconfig LSP List&lt;/a&gt; and found &lt;strong&gt;tsserver&lt;/strong&gt;, then we already know its quite easy to setup. Below is the snippet you can use to configure.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="s1"&gt;'lspconfig'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tsserver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We just need to put this line in either &lt;code&gt;init.lua&lt;/code&gt; or any &lt;code&gt;.lua&lt;/code&gt; file which is sourced when neovim starts up.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finally, we have our LSP installed and configured, but we don't see any suggestion or any code completions when we open a &lt;code&gt;.ts&lt;/code&gt; file in a project.
Now for the code completions, i am currently using &lt;a href="https://github.com/hrsh7th/nvim-cmp" rel="noopener noreferrer"&gt;nvim-cmp&lt;/a&gt; which is quite extensible and customizable plugin.
So, let's first install this plugin:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Packer.nvim&lt;/span&gt;
&lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="s1"&gt;'hrsh7th/cmp-nvim-lsp'&lt;/span&gt;
&lt;span class="n"&gt;Plug&lt;/span&gt; &lt;span class="s1"&gt;'hrsh7th/cmp-buffer'&lt;/span&gt;
&lt;span class="n"&gt;Plug&lt;/span&gt; &lt;span class="s1"&gt;'hrsh7th/nvim-cmp'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="p"&gt;--&lt;/span&gt; &lt;span class="k"&gt;vim&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;plug
Plug &lt;span class="s1"&gt;'hrsh7th/cmp-nvim-lsp'&lt;/span&gt;
Plug &lt;span class="s1"&gt;'hrsh7th/cmp-buffer'&lt;/span&gt;
Plug &lt;span class="s1"&gt;'hrsh7th/nvim-cmp'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For configuring up &lt;strong&gt;code completion engine (nvim-cmp)&lt;/strong&gt;, you can either refer to the documentation from above link (which is quite extensive) or you can just use the below code snippet to make it work
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="n"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setup&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;-- As currently, i am not using any snippet manager, thus disabled it.&lt;/span&gt;
      &lt;span class="c1"&gt;-- snippet = {&lt;/span&gt;
         &lt;span class="c1"&gt;--   expand = function(args)&lt;/span&gt;
            &lt;span class="c1"&gt;--     require("luasnip").lsp_expand(args.body)&lt;/span&gt;
            &lt;span class="c1"&gt;--   end,&lt;/span&gt;
         &lt;span class="c1"&gt;-- },&lt;/span&gt;

      &lt;span class="n"&gt;mapping&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;C-d&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scroll_docs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
         &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;C-f&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scroll_docs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
         &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;C-e&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
         &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;c-y&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;confirm&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;behavior&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ConfirmBehavior&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Insert&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nb"&gt;select&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="n"&gt;formatting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="n"&gt;format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lspkind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cmp_format&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;with_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;menu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
               &lt;span class="n"&gt;buffer&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"[buf]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;nvim_lsp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"[LSP]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;path&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"[path]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;

      &lt;span class="n"&gt;sources&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"nvim_lsp"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"path"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
         &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"buffer"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keyword_length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="n"&gt;experimental&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="n"&gt;ghost_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the snippets, mapping, formatting and sources part in the above code snippet is expalained nicely in the plugin's documentation.&lt;br&gt;
   &lt;br&gt;For above code to work, you also have to install &lt;a href="https://github.com/onsails/lspkind-nvim" rel="noopener noreferrer"&gt;lspkind&lt;/a&gt; which provides awesome icons in the code completions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After setting up this much, you would start getting this kind of awesome popups which you can use to make the cool auto completions and much more.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6uqq9ukxs0532g0q3ifw.JPG" alt="Code completion popup"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For LSP setup, you can checkout &lt;a href="https://www.youtube.com/watch?v=tOjVHXaUrzo&amp;amp;ab_channel=ThePrimeagen" rel="noopener noreferrer"&gt;primeagen's lsp video&lt;/a&gt;.  It's an year old, but its quite good for first time.&lt;/li&gt;
&lt;li&gt;For code completion engine &lt;code&gt;nvim-cmp&lt;/code&gt;, tj has just released a &lt;a href="https://www.youtube.com/watch?v=_DnmphIwnjo" rel="noopener noreferrer"&gt;TakeTuesday video: nvim-cmp&lt;/a&gt; which is super informative and it goes quite deep into the customizations too.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thank you for reading :)&lt;/p&gt;

</description>
      <category>neovim</category>
      <category>lsp</category>
    </item>
    <item>
      <title>My Vim Journey :)</title>
      <dc:creator>Nitin Chaudhary</dc:creator>
      <pubDate>Sat, 08 Aug 2020 01:42:44 +0000</pubDate>
      <link>https://forem.com/ntncahay/my-vim-journey-521e</link>
      <guid>https://forem.com/ntncahay/my-vim-journey-521e</guid>
      <description>&lt;p&gt;This all started when the pandemic began and we started working from home. At that time, I thought of learning something cool which would allow me to upskill my editing ability as well as becoming a good developer.&lt;/p&gt;

&lt;p&gt;So one of my teammates told me about &lt;code&gt;Vim&lt;/code&gt; and all of the good stuff about it!! I knew about &lt;code&gt;Vim&lt;/code&gt; but the only thing I knew was opening it by mistake and then trying to quit it (which I think is most of the new guys 🤣). &lt;/p&gt;

&lt;p&gt;I started seeing some screencasts and videos on youtube videos to see what all the fuss is about. After seeing all features of vim, I thought of giving it a try!! (Thank God I did this! 😆). &lt;br&gt;
After setting up &lt;code&gt;Vim&lt;/code&gt; and using it felt a bit different and difficult at the same time. But as I started using it in most of my development work like in &lt;code&gt;Xcode using XVim2&lt;/code&gt;, &lt;code&gt;Chrome using Vimium&lt;/code&gt;, and &lt;code&gt;Vim&lt;/code&gt; with its awesome plugins, I got a hang of it. Then as I was progressing, my teammate told me about this great book &lt;a href="https://www.amazon.in/Practical-Vim-Edit-Speed-Thought-ebook/dp/B018T6ZVPK"&gt;Practical Vim&lt;/a&gt;. So I started going through all the exercises and code in it, and as I was trying everything  I got excited to see how I can do my previous work in no time using this modal editing which is like a whole new realm for me.&lt;/p&gt;

&lt;p&gt;After learning all this (after 1.5 months), I started using vim for my office work too, and I saw a huge time gap between the work that previously used to take hours but now took mere minutes. 😄&lt;/p&gt;

&lt;p&gt;While I was seeing all the screencast and talks from youtube, I got to know about this &lt;a href="https://www.youtube.com/playlist?list=PLwJS-G75vM7kFO-yUkyNphxSIdbi_1NKX"&gt;Vim Screencast pl by Greg Hurrell&lt;/a&gt;. As I went through this playlist, I got to know about how cool the vim is and how I can even optimize my workflow even more.&lt;/p&gt;

&lt;p&gt;For me, the journey has just started as I am still trying to learn out vim every week for making my work fun, easy, and efficient! &lt;/p&gt;

&lt;p&gt;Thank you all reading!! 😄 🙃 😊&lt;br&gt;
(PS: This is my first ever post on any kind of technical thing)&lt;/p&gt;

</description>
      <category>vim</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
