In this paper, we present an efficient SLAM (Simultaneous Localization and Mapping) algorithm named VecSLAM, which localizes and builds a vector map for mobile robots in indoor environments. Compared to grid-mapping approaches, vector-based mapping algorithms require a relatively small amount of memory. Two essential operations for successful vector mapping are vector merging and loop closing. Merging methods used by traditional line segment-based mapping algorithms do not consider the sensor characteristics, which causes additional mapping error and makes it harder to close loops after navigation over a long distance. In addition, few line segment-based SLAM approaches contain loop closing methodology. We present a novel vector merging scheme based on a recursive least square estimation for robust mapping. An efficient loop closing method is also proposed, which effectively distributes the resultant mapping error throughout the loop to guarantee global map consistency. Simulation studies and experimental results show that VecSLAM is an efficient and robust online localization and mapping algorithm.